From: mark burdett Date: Wed, 20 Feb 2019 00:46:46 +0000 (-0800) Subject: Provide API for creating TEMPORARY MEMORY tables. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=8ccee4bf13394f5a8ba88d5fc146596ba58ec4c9;p=civicrm-core.git Provide API for creating TEMPORARY MEMORY tables. --- diff --git a/CRM/Utils/SQL/TempTable.php b/CRM/Utils/SQL/TempTable.php index cfcdbac514..cde12a0f67 100644 --- a/CRM/Utils/SQL/TempTable.php +++ b/CRM/Utils/SQL/TempTable.php @@ -72,6 +72,8 @@ class CRM_Utils_SQL_TempTable { const CATEGORY_REGEXP = ';^[a-zA-Z0-9]+$;'; const ID_LENGTH = 37; // MAX{64} - CATEGORY_LENGTH{12} - CONST_LENGHTH{15} = 37 const ID_REGEXP = ';^[a-zA-Z0-9_]+$;'; + const INNODB = 'ENGINE=InnoDB'; + const MEMORY = 'ENGINE=MEMORY'; /** * @var bool @@ -84,6 +86,8 @@ class CRM_Utils_SQL_TempTable { protected $autodrop; + protected $memory; + /** * @return CRM_Utils_SQL_TempTable */ @@ -96,6 +100,7 @@ class CRM_Utils_SQL_TempTable { // I suspect it would be better to just say utf8=true, but a lot of existing queries don't do the utf8 bit. $t->utf8 = CRM_Utils_Constant::value('CIVICRM_TEMP_FORCE_UTF8', FALSE); $t->autodrop = FALSE; + $t->memory = FALSE; return $t; } @@ -126,8 +131,9 @@ class CRM_Utils_SQL_TempTable { * @return CRM_Utils_SQL_TempTable */ public function createWithQuery($selectQuery) { - $sql = sprintf('%s %s AS %s', + $sql = sprintf('%s %s %s AS %s', $this->toSQL('CREATE'), + $this->memory ? self::MEMORY : self::INNODB, $this->utf8 ? self::UTF8 : '', ($selectQuery instanceof CRM_Utils_SQL_Select ? $selectQuery->toSQL() : $selectQuery) ); @@ -144,9 +150,10 @@ class CRM_Utils_SQL_TempTable { * @return CRM_Utils_SQL_TempTable */ public function createWithColumns($columns) { - $sql = sprintf('%s (%s) %s', + $sql = sprintf('%s (%s) %s %s', $this->toSQL('CREATE'), $columns, + $this->memory ? self::MEMORY : self::INNODB, $this->utf8 ? self::UTF8 : '' ); CRM_Core_DAO::executeQuery($sql, array(), TRUE, NULL, TRUE, FALSE); @@ -215,6 +222,13 @@ class CRM_Utils_SQL_TempTable { return $this->durable; } + /** + * @return bool + */ + public function isMemory() { + return $this->memory; + } + /** * @return bool */ @@ -273,6 +287,18 @@ class CRM_Utils_SQL_TempTable { return $this; } + /** + * Set table engine to MEMORY. + * + * @param bool $value + * + * @return $this + */ + public function setMemory($value = TRUE) { + $this->memory = $value; + return $this; + } + /** * Set table collation to UTF8. *