*
* This function creates a table AND adds the details to the developer tab & $this->>temporary tables.
*
- * @todo improve presentation on the developer tab since CREATE TEMPORARY is removed.
- *
* @param string $identifier
* @param $sql
- * @param bool $isTrueTemporary
- * Is this a mysql temporary table or temporary in a less technical sense.
*
* @return string
*/
- public function createTemporaryTable($identifier, $sql, $isTrueTemporary = TRUE) {
+ public function createTemporaryTable($identifier, $sql) {
+ $tempTable = CRM_Utils_SQL_TempTable::build()->setUtf8(TRUE)->createWithQuery($sql);
+ $name = $tempTable->getName();
+ // Developers may force tables to be durable to assist in debugging so lets check.
+ $isNotTrueTemporary = $tempTable->isDurable();
+ // The TempTable build routine adds the next line - we output it to help developers see what has happened.
+ $sql = 'CREATE ' . ($isNotTrueTemporary ? '' : 'TEMPORARY ') . "TABLE $name DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci " . $sql;
$this->addToDeveloperTab($sql);
- $name = CRM_Utils_SQL_TempTable::build()->setUtf8(TRUE)->setDurable($isTrueTemporary)->createWithQuery($sql)->getName();
- $this->temporaryTables[$identifier] = ['temporary' => $isTrueTemporary, 'name' => $name];
+ $this->temporaryTables[$identifier] = ['temporary' => !$isNotTrueTemporary, 'name' => $name];
return $name;
}
WHERE smartgroup_contact.group_id IN ({$smartGroups}) ";
}
- $this->groupTempTable = CRM_Utils_SQL_TempTable::build()->setCategory('rptgrp')->setId(date('Ymd_') . uniqid())->getName();
- $this->executeReportQuery("
- CREATE TEMPORARY TABLE $this->groupTempTable $this->_databaseAttributes
- $query
- ");
+ $this->groupTempTable = $this->createTemporaryTable('rptgrp', $query);
CRM_Core_DAO::executeQuery("ALTER TABLE $this->groupTempTable ADD INDEX i_id(id)");
}
// @todo this acl has no test coverage and is very hard to test manually so could be fragile.
$this->resetFormSqlAndWhereHavingClauses();
- $this->contactTempTable = CRM_Utils_SQL_TempTable::build()->setCategory('rptlybunt')->setId(date('Ymd_') . uniqid())->getName();
+ $this->contactTempTable = $this->createTemporaryTable('rptlybunt', "
+ SELECT SQL_CALC_FOUND_ROWS {$this->_aliases['civicrm_contact']}.id as cid {$this->_from}
+ {$this->_where}
+ GROUP BY {$this->_aliases['civicrm_contact']}.id"
+ );
$this->limit();
- $getContacts = "
- CREATE TEMPORARY TABLE $this->contactTempTable {$this->_databaseAttributes}
- SELECT SQL_CALC_FOUND_ROWS {$this->_aliases['civicrm_contact']}.id as cid {$this->_from} {$this->_where}
- GROUP BY {$this->_aliases['civicrm_contact']}.id";
- $this->executeReportQuery($getContacts);
if (empty($this->_params['charts'])) {
$this->setPager();
}
/**
* @param string|NULL $category
+ *
* @return CRM_Utils_SQL_TempTable
*/
public function setCategory($category) {
}
/**
- * @parma bool $value
+ * Set whether the table should be durable.
+ *
+ * Durable tables are not TEMPORARY in the mysql sense.
+ *
+ * @param bool $durable
+ *
* @return CRM_Utils_SQL_TempTable
*/
public function setDurable($durable = TRUE) {
}
/**
+ * Setter for id
+ *
* @param mixed $id
+ *
* @return CRM_Utils_SQL_TempTable
*/
public function setId($id) {
return $this;
}
+ /**
+ * Set table collation to UTF8.
+ *
+ * This would make sense as a default but cautiousness during phasing in has made it opt-in.
+ *
+ * @param bool $value
+ *
+ * @return $this
+ */
public function setUtf8($value = TRUE) {
$this->utf8 = $value;
return $this;