From c6053b283046c7db7201d60d341e279032394002 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 6 May 2014 14:46:59 +0200 Subject: [PATCH] Quote identifiers on mysql --- lib/private/db/mdb2schemamanager.php | 4 +++- lib/private/db/mysqlmigrator.php | 32 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 lib/private/db/mysqlmigrator.php diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php index 1a19e737da8..d6e0e77b54e 100644 --- a/lib/private/db/mdb2schemamanager.php +++ b/lib/private/db/mdb2schemamanager.php @@ -64,7 +64,9 @@ class MDB2SchemaManager { return new SQLiteMigrator($this->conn); } else if ($platform instanceof OraclePlatform) { return new OracleMigrator($this->conn); - } else if ($platform instanceof MySqlPlatform or $platform instanceof PostgreSqlPlatform) { + } else if ($platform instanceof MySqlPlatform) { + return new MySQLMigrator($this->conn); + } else if ($platform instanceof PostgreSqlPlatform) { return new Migrator($this->conn); } else { return new NoCheckMigrator($this->conn); diff --git a/lib/private/db/mysqlmigrator.php b/lib/private/db/mysqlmigrator.php new file mode 100644 index 00000000000..97495f52032 --- /dev/null +++ b/lib/private/db/mysqlmigrator.php @@ -0,0 +1,32 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +namespace OC\DB; + +use Doctrine\DBAL\Schema\Schema; + +class MySQLMigrator extends Migrator { + /** + * @param Schema $targetSchema + * @param \Doctrine\DBAL\Connection $connection + * @return \Doctrine\DBAL\Schema\SchemaDiff + */ + protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) { + $schemaDiff = parent::getDiff($targetSchema, $connection); + + // identifiers need to be quoted for mysql + foreach ($schemaDiff->changedTables as $tableDiff) { + $tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name); + foreach ($tableDiff->changedColumns as $column) { + $column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName); + } + } + + return $schemaDiff; + } +} -- 2.39.5