From 7ec63b27d005317d27a24e9ceac8ede520b7cd72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20S=CC=8Ckoda?= Date: Wed, 11 Jul 2012 15:54:03 +0200 Subject: [PATCH] MDL-34271 cleanup mysql engine hack before adding similar collation hack --- lib/ddl/mysql_sql_generator.php | 19 ++++-------- lib/dml/mysqli_native_moodle_database.php | 36 ++++++++++++++--------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/lib/ddl/mysql_sql_generator.php b/lib/ddl/mysql_sql_generator.php index 6ae310f6411..99d118d9349 100644 --- a/lib/ddl/mysql_sql_generator.php +++ b/lib/ddl/mysql_sql_generator.php @@ -117,23 +117,16 @@ class mysql_sql_generator extends sql_generator { * by any of its comments, indexes and sequence creation SQL statements. */ public function getCreateTableSQL($xmldb_table) { - // first find out if want some special db engine - $engine = null; - if (method_exists($this->mdb, 'get_dbengine')) { - $engine = $this->mdb->get_dbengine(); - } - + // First find out if want some special db engine. + $engine = $this->mdb->get_dbengine(); $sqlarr = parent::getCreateTableSQL($xmldb_table); - if (!$engine) { - // we rely on database defaults - return $sqlarr; - } - - // let's inject the engine into SQL + // Let's inject the extra MySQL tweaks. foreach ($sqlarr as $i=>$sql) { if (strpos($sql, 'CREATE TABLE ') === 0) { - $sqlarr[$i] .= " ENGINE = $engine"; + if ($engine) { + $sqlarr[$i] .= " ENGINE = $engine"; + } } } diff --git a/lib/dml/mysqli_native_moodle_database.php b/lib/dml/mysqli_native_moodle_database.php index 93311bd5fd4..5134ac98624 100644 --- a/lib/dml/mysqli_native_moodle_database.php +++ b/lib/dml/mysqli_native_moodle_database.php @@ -146,22 +146,28 @@ class mysqli_native_moodle_database extends moodle_database { return $this->dboptions['dbengine']; } - $engine = null; - - if (!$this->external) { - // look for current engine of our config table (the first table that gets created), - // so that we create all tables with the same engine - $sql = "SELECT engine FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}config'"; - $this->query_start($sql, NULL, SQL_QUERY_AUX); - $result = $this->mysqli->query($sql); - $this->query_end($result); - if ($rec = $result->fetch_assoc()) { - $engine = $rec['engine']; - } - $result->close(); + if ($this->external) { + return null; } + $engine = null; + + // Look for current engine of our config table (the first table that gets created), + // so that we create all tables with the same engine. + $sql = "SELECT engine + FROM INFORMATION_SCHEMA.TABLES + WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}config'"; + $this->query_start($sql, NULL, SQL_QUERY_AUX); + $result = $this->mysqli->query($sql); + $this->query_end($result); + if ($rec = $result->fetch_assoc()) { + $engine = $rec['engine']; + } + $result->close(); + if ($engine) { + // Cache the result to improve performance. + $this->dboptions['dbengine'] = $engine; return $engine; } @@ -175,7 +181,7 @@ class mysqli_native_moodle_database extends moodle_database { } $result->close(); - if (!$this->external and $engine === 'MyISAM') { + if ($engine === 'MyISAM') { // we really do not want MyISAM for Moodle, InnoDB or XtraDB is a reasonable defaults if supported $sql = "SHOW STORAGE ENGINES"; $this->query_start($sql, NULL, SQL_QUERY_AUX); @@ -196,6 +202,8 @@ class mysqli_native_moodle_database extends moodle_database { } } + // Cache the result to improve performance. + $this->dboptions['dbengine'] = $engine; return $engine; }