Skip to content

Commit 1495526

Browse files
author
David Monllao
committed
Merge branch 'm33_MDL-59596_DDL_Issues_With_MariaDB_10p2_SQLMode' of https://github.com/scara/moodle into MOODLE_33_STABLE
2 parents 33ef4d9 + 23c1612 commit 1495526

3 files changed

+35
-0
lines changed

lib/ddl/mysql_sql_generator.php

+21
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,27 @@ public function getAddFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = N
321321
return $sqls;
322322
}
323323

324+
public function getAlterFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = NULL, $skip_default_clause = NULL, $skip_notnull_clause = NULL)
325+
{
326+
$tablename = $xmldb_table->getName();
327+
$dbcolumnsinfo = $this->mdb->get_columns($tablename);
328+
329+
if (($this->mdb->has_breaking_change_sqlmode()) &&
330+
($dbcolumnsinfo[$xmldb_field->getName()]->meta_type == 'X') &&
331+
($xmldb_field->getType() == XMLDB_TYPE_INTEGER)) {
332+
// Ignore 1292 ER_TRUNCATED_WRONG_VALUE Truncated incorrect INTEGER value: '%s'.
333+
$altercolumnsqlorig = $this->alter_column_sql;
334+
$this->alter_column_sql = str_replace('ALTER TABLE', 'ALTER IGNORE TABLE', $this->alter_column_sql);
335+
$result = parent::getAlterFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause, $skip_default_clause, $skip_notnull_clause);
336+
// Restore the original ALTER SQL statement pattern.
337+
$this->alter_column_sql = $altercolumnsqlorig;
338+
339+
return $result;
340+
}
341+
342+
return parent::getAlterFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause, $skip_default_clause, $skip_notnull_clause);
343+
}
344+
324345
/**
325346
* Given one correct xmldb_table, returns the SQL statements
326347
* to create temporary table (inside one array).

lib/dml/mariadb_native_moodle_database.php

+6
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ protected function has_breaking_change_quoted_defaults() {
9494
return version_compare($version, '10.2.7', '>=');
9595
}
9696

97+
public function has_breaking_change_sqlmode() {
98+
$version = $this->get_server_info()['version'];
99+
// Breaking change since 10.2.4: https://mariadb.com/kb/en/the-mariadb-library/sql-mode/#setting-sql_mode.
100+
return version_compare($version, '10.2.4', '>=');
101+
}
102+
97103
/**
98104
* It is time to require transactions everywhere.
99105
*

lib/dml/mysqli_native_moodle_database.php

+8
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,14 @@ protected function has_breaking_change_quoted_defaults() {
817817
return false;
818818
}
819819

820+
/**
821+
* Indicates whether SQL_MODE default value has changed in a not backward compatible way.
822+
* @return boolean True when SQL_MODE breaks BC; otherwise, false.
823+
*/
824+
public function has_breaking_change_sqlmode() {
825+
return false;
826+
}
827+
820828
/**
821829
* Returns moodle column info for raw column from information schema.
822830
* @param stdClass $rawcolumn

0 commit comments

Comments
 (0)