Skip to content
Browse files

MDL-34271 cleanup mysql engine hack before adding similar collation hack

  • Loading branch information...
1 parent 9a7c3d5 commit 61c4fa28c1bf4c2b13ac894dd63b0eac557827a4 @skodak skodak committed Jul 11, 2012
Showing with 26 additions and 25 deletions.
  1. +6 −13 lib/ddl/mysql_sql_generator.php
  2. +20 −12 lib/dml/mysqli_native_moodle_database.php
View
19 lib/ddl/mysql_sql_generator.php
@@ -101,23 +101,16 @@ public function getResetSequenceSQL($table) {
* to create it (inside one array)
*/
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";
+ }
}
}
View
32 lib/dml/mysqli_native_moodle_database.php
@@ -145,22 +145,28 @@ public function get_dbengine() {
return $this->dboptions['dbengine'];
}
+ if ($this->external) {
+ return null;
+ }
+
$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();
+ // 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;
}
@@ -174,7 +180,7 @@ public function get_dbengine() {
}
$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);
@@ -195,6 +201,8 @@ public function get_dbengine() {
}
}
+ // Cache the result to improve performance.
+ $this->dboptions['dbengine'] = $engine;
return $engine;
}

0 comments on commit 61c4fa2

Please sign in to comment.
Something went wrong with that request. Please try again.