Skip to content

Commit

Permalink
Merge branch 'm34_MDL-59583_Fix_MariaDB_10d2d7_Breaking_Change' of ht…
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jul 31, 2017
2 parents 722f67d + 0510d5c commit 2653e0c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/dml/mariadb_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public function get_server_info() {
return array('description'=>$this->mysqli->server_info, 'version'=>$version);
}

protected function has_breaking_change_quoted_defaults() {
$version = $this->get_server_info()['version'];
// Breaking change since 10.2.7: MDEV-13132.
return version_compare($version, '10.2.7', '>=');
}

/**
* It is time to require transactions everywhere.
*
Expand Down
16 changes: 14 additions & 2 deletions lib/dml/mysqli_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ public function get_columns($table, $usecache=true) {
$rawcolumn->numeric_scale = null;
$rawcolumn->is_nullable = $rawcolumn->null; unset($rawcolumn->null);
$rawcolumn->column_default = $rawcolumn->default; unset($rawcolumn->default);
$rawcolumn->column_key = $rawcolumn->key; unset($rawcolumn->default);
$rawcolumn->column_key = $rawcolumn->key; unset($rawcolumn->key);

if (preg_match('/(enum|varchar)\((\d+)\)/i', $rawcolumn->column_type, $matches)) {
$rawcolumn->data_type = $matches[1];
Expand Down Expand Up @@ -783,6 +783,14 @@ public function get_columns($table, $usecache=true) {
return $structure;
}

/**
* Indicates whether column information retrieved from `information_schema.columns` has default values quoted or not.
* @return boolean True when default values are quoted (breaking change); otherwise, false.
*/
protected function has_breaking_change_quoted_defaults() {
return false;
}

/**
* Returns moodle column info for raw column from information schema.
* @param stdClass $rawcolumn
Expand All @@ -794,7 +802,11 @@ private function get_column_info(stdClass $rawcolumn) {
$info->name = $rawcolumn->column_name;
$info->type = $rawcolumn->data_type;
$info->meta_type = $this->mysqltype2moodletype($rawcolumn->data_type);
$info->default_value = $rawcolumn->column_default;
if ($this->has_breaking_change_quoted_defaults()) {
$info->default_value = trim($rawcolumn->column_default, "'");
} else {
$info->default_value = $rawcolumn->column_default;
}
$info->has_default = !is_null($rawcolumn->column_default);
$info->not_null = ($rawcolumn->is_nullable === 'NO');
$info->primary_key = ($rawcolumn->column_key === 'PRI');
Expand Down

0 comments on commit 2653e0c

Please sign in to comment.