From 0510d5c757fbbf5b54ecd0aefe81338e4be9f40e Mon Sep 17 00:00:00 2001 From: Matteo Scaramuccia Date: Tue, 25 Jul 2017 09:07:20 +0200 Subject: [PATCH] MDL-59583 dml: fixed breaking change added w/ MariaDB 10.2.7+ --- lib/dml/mariadb_native_moodle_database.php | 6 ++++++ lib/dml/mysqli_native_moodle_database.php | 14 +++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/dml/mariadb_native_moodle_database.php b/lib/dml/mariadb_native_moodle_database.php index ffc77965932..48debee57ce 100644 --- a/lib/dml/mariadb_native_moodle_database.php +++ b/lib/dml/mariadb_native_moodle_database.php @@ -88,6 +88,12 @@ class mariadb_native_moodle_database extends mysqli_native_moodle_database { 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. * diff --git a/lib/dml/mysqli_native_moodle_database.php b/lib/dml/mysqli_native_moodle_database.php index bb6c519f3b1..1f70e7b4c8e 100644 --- a/lib/dml/mysqli_native_moodle_database.php +++ b/lib/dml/mysqli_native_moodle_database.php @@ -783,6 +783,14 @@ class mysqli_native_moodle_database extends moodle_database { 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 @@ -794,7 +802,11 @@ class mysqli_native_moodle_database extends moodle_database { $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');