Merge branch 'MDL-66110-master' of https://github.com/ryanwyllie/moodle

This commit is contained in:
Jun Pataleta
2019-08-21 09:57:49 +08:00
2 changed files with 30 additions and 1 deletions
+17 -1
View File
@@ -834,7 +834,23 @@ abstract class moodle_database {
* @return string The sql with tablenames being prefixed with $CFG->prefix
*/
protected function fix_table_names($sql) {
return preg_replace('/\{([a-z][a-z0-9_]*)\}/', $this->prefix.'$1', $sql);
return preg_replace_callback(
'/\{([a-z][a-z0-9_]*)\}/',
function($matches) {
return $this->fix_table_name($matches[1]);
},
$sql
);
}
/**
* Adds the prefix to the table name.
*
* @param string $tablename The table name
* @return string The prefixed table name
*/
protected function fix_table_name($tablename) {
return $this->prefix . $tablename;
}
/**
+13
View File
@@ -2032,4 +2032,17 @@ class mysqli_native_moodle_database extends moodle_database {
}
return false;
}
/**
* Fixes any table names that clash with reserved words.
*
* @param string $tablename The table name
* @return string The fixed table name
*/
protected function fix_table_name($tablename) {
$prefixedtablename = parent::fix_table_name($tablename);
// This function quotes the table name if it matches one of the MySQL reserved
// words, e.g. groups.
return $this->get_manager()->generator->getEncQuoted($prefixedtablename);
}
}