Skip to content

Commit

Permalink
Don't use double quotes in MySQL queries
Browse files Browse the repository at this point in the history
MySQL databases with the ANSI_QUOTES mode enabled treat " as an identifier
quote (see https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_ansi_quotes).
So for such databases the 'occ upgrade' fails with an error message like this:
... unknown column 'oc_*' in where clause.

This fix replaces the doulbe quotes with single quotes that should be always
used in MySQL queries to quote literal strings.

Signed-off-by: Robin Müller <robin.mueller@1und1.de>
  • Loading branch information
coder-hugo committed Feb 16, 2018
1 parent b7ee624 commit 5c4aa17
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/private/Repair/Collation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin Appelman <robin@icewind.nl>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Robin Müller <robin.mueller@1und1.de>
*
* @license AGPL-3.0
*
Expand Down Expand Up @@ -124,7 +125,7 @@ protected function getAllNonUTF8BinTables(IDBConnection $connection) {
" FROM INFORMATION_SCHEMA . COLUMNS" .
" WHERE TABLE_SCHEMA = ?" .
" AND (COLLATION_NAME <> '" . $characterSet . "_bin' OR CHARACTER_SET_NAME <> '" . $characterSet . "')" .
" AND TABLE_NAME LIKE \"*PREFIX*%\"",
" AND TABLE_NAME LIKE '*PREFIX*%'",
array($dbName)
);
$rows = $statement->fetchAll();
Expand All @@ -139,7 +140,7 @@ protected function getAllNonUTF8BinTables(IDBConnection $connection) {
" FROM INFORMATION_SCHEMA . TABLES" .
" WHERE TABLE_SCHEMA = ?" .
" AND TABLE_COLLATION <> '" . $characterSet . "_bin'" .
" AND TABLE_NAME LIKE \"*PREFIX*%\"",
" AND TABLE_NAME LIKE '*PREFIX*%'",
[$dbName]
);
$rows = $statement->fetchAll();
Expand Down
1 change: 1 addition & 0 deletions tests/lib/Repair/RepairCollationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ protected function setUp() {

$dbPrefix = $this->config->getSystemValue("dbtableprefix");
$this->tableName = $this->getUniqueID($dbPrefix . "_collation_test");
$this->connection->exec("SET SESSION sql_mode = CONCAT(@@SESSION.sql_mode, ',ANSI_QUOTES')");
$this->connection->exec("CREATE TABLE $this->tableName(text VARCHAR(16)) COLLATE utf8_unicode_ci");

$this->repair = new TestCollationRepair($this->config, $this->logger, $this->connection, false);
Expand Down

0 comments on commit 5c4aa17

Please sign in to comment.