*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
- *
* Table naming rules:
* - MySQL imposes a 64 char limit.
* - All temp tables start with "civicrm_tmp".
$sql = sprintf('%s %s %s AS %s',
$this->toSQL('CREATE'),
$this->memory ? self::MEMORY : self::INNODB,
- $this->utf8 ? self::UTF8 : '',
+ $this->getUtf8String(),
($selectQuery instanceof CRM_Utils_SQL_Select ? $selectQuery->toSQL() : $selectQuery)
);
CRM_Core_DAO::executeQuery($sql, [], TRUE, NULL, TRUE, FALSE);
return $this;
}
+ /**
+ * Get the utf8 string for the table.
+ *
+ * If the db collation is already utf8 by default (either
+ * utf8 or utf84mb) then rely on that. Otherwise set to utf8.
+ *
+ * Respecting the DB collation supports utf8mb4 adopters, which is currently
+ * not the norm in civi installs.
+ *
+ * @return string
+ */
+ public function getUtf8String() {
+ if (!$this->utf8) {
+ return '';
+ }
+ $dbUTF = CRM_Core_BAO_SchemaHandler::getDBCollation();
+ if (strpos($dbUTF, 'utf8') !== FALSE) {
+ return '';
+ }
+ return self::UTF8;
+ }
+
/**
* Create the empty table.
*
$this->toSQL('CREATE'),
$columns,
$this->memory ? self::MEMORY : self::INNODB,
- $this->utf8 ? self::UTF8 : ''
+ $this->getUtf8String()
);
CRM_Core_DAO::executeQuery($sql, [], TRUE, NULL, TRUE, FALSE);
$this->createSql = $sql;