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

This commit is contained in:
Petr Škoda 2012-07-11 15:54:03 +02:00
parent 904673dd20
commit ed047dabc9
2 changed files with 28 additions and 27 deletions

View File

@ -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";
}
}
}

View File

@ -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;
}