Skip to content

Commit

Permalink
MDL-34271 cleanup mysql engine hack before adding similar collation hack
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Jul 12, 2012
1 parent 3b52187 commit 7ec63b2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
19 changes: 6 additions & 13 deletions lib/ddl/mysql_sql_generator.php
Expand Up @@ -117,23 +117,16 @@ public function getResetSequenceSQL($table) {
* 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";
}
}
}

Expand Down
32 changes: 20 additions & 12 deletions lib/dml/mysqli_native_moodle_database.php
Expand Up @@ -146,22 +146,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;
}

Expand All @@ -175,7 +181,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);
Expand All @@ -196,6 +202,8 @@ public function get_dbengine() {
}
}

// Cache the result to improve performance.
$this->dboptions['dbengine'] = $engine;
return $engine;
}

Expand Down

0 comments on commit 7ec63b2

Please sign in to comment.