Skip to content

Commit

Permalink
Merge branch 'm34_MDL-59596_DDL_Issues_With_MariaDB_10p2_SQLMode' of h…
Browse files Browse the repository at this point in the history
…ttps://github.com/scara/moodle into MOODLE_34_STABLE
  • Loading branch information
David Monllao committed May 28, 2018
2 parents cb6b89a + 1edb0f1 commit 8359822
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
21 changes: 21 additions & 0 deletions lib/ddl/mysql_sql_generator.php
Expand Up @@ -321,6 +321,27 @@ public function getAddFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = N
return $sqls;
}

public function getAlterFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause = NULL, $skip_default_clause = NULL, $skip_notnull_clause = NULL)
{
$tablename = $xmldb_table->getName();
$dbcolumnsinfo = $this->mdb->get_columns($tablename);

if (($this->mdb->has_breaking_change_sqlmode()) &&
($dbcolumnsinfo[$xmldb_field->getName()]->meta_type == 'X') &&
($xmldb_field->getType() == XMLDB_TYPE_INTEGER)) {
// Ignore 1292 ER_TRUNCATED_WRONG_VALUE Truncated incorrect INTEGER value: '%s'.
$altercolumnsqlorig = $this->alter_column_sql;
$this->alter_column_sql = str_replace('ALTER TABLE', 'ALTER IGNORE TABLE', $this->alter_column_sql);
$result = parent::getAlterFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause, $skip_default_clause, $skip_notnull_clause);
// Restore the original ALTER SQL statement pattern.
$this->alter_column_sql = $altercolumnsqlorig;

return $result;
}

return parent::getAlterFieldSQL($xmldb_table, $xmldb_field, $skip_type_clause, $skip_default_clause, $skip_notnull_clause);
}

/**
* Given one correct xmldb_table, returns the SQL statements
* to create temporary table (inside one array).
Expand Down
6 changes: 6 additions & 0 deletions lib/dml/mariadb_native_moodle_database.php
Expand Up @@ -94,6 +94,12 @@ protected function has_breaking_change_quoted_defaults() {
return version_compare($version, '10.2.7', '>=');
}

public function has_breaking_change_sqlmode() {
$version = $this->get_server_info()['version'];
// Breaking change since 10.2.4: https://mariadb.com/kb/en/the-mariadb-library/sql-mode/#setting-sql_mode.
return version_compare($version, '10.2.4', '>=');
}

/**
* It is time to require transactions everywhere.
*
Expand Down
8 changes: 8 additions & 0 deletions lib/dml/mysqli_native_moodle_database.php
Expand Up @@ -817,6 +817,14 @@ protected function has_breaking_change_quoted_defaults() {
return false;
}

/**
* Indicates whether SQL_MODE default value has changed in a not backward compatible way.
* @return boolean True when SQL_MODE breaks BC; otherwise, false.
*/
public function has_breaking_change_sqlmode() {
return false;
}

/**
* Returns moodle column info for raw column from information schema.
* @param stdClass $rawcolumn
Expand Down

0 comments on commit 8359822

Please sign in to comment.