Commit 733b64bc authored by Jonas Staudenmeir's avatar Jonas Staudenmeir

Quote collation on MySQL

parent d9b377cd
...@@ -503,7 +503,7 @@ SQL ...@@ -503,7 +503,7 @@ SQL
$options['collate'] = $options['charset'] . '_unicode_ci'; $options['collate'] = $options['charset'] . '_unicode_ci';
} }
$tableOptions[] = sprintf('COLLATE %s', $options['collate']); $tableOptions[] = $this->getColumnCollationDeclarationSQL($options['collate']);
// Engine // Engine
if (! isset($options['engine'])) { if (! isset($options['engine'])) {
...@@ -965,6 +965,14 @@ SQL ...@@ -965,6 +965,14 @@ SQL
return 'CHARACTER SET ' . $charset; return 'CHARACTER SET ' . $charset;
} }
/**
* {@inheritDoc}
*/
public function getColumnCollationDeclarationSQL($collation)
{
return 'COLLATE ' . $this->quoteSingleIdentifier($collation);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
......
...@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\MySqlPlatform; ...@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types; use Doctrine\DBAL\Types\Types;
use Doctrine\Tests\Types\MySqlPointType; use Doctrine\Tests\Types\MySqlPointType;
...@@ -275,6 +276,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -275,6 +276,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$table->addColumn('text', 'text'); $table->addColumn('text', 'text');
$table->addColumn('foo', 'text')->setPlatformOption('collation', 'latin1_swedish_ci'); $table->addColumn('foo', 'text')->setPlatformOption('collation', 'latin1_swedish_ci');
$table->addColumn('bar', 'text')->setPlatformOption('collation', 'utf8_general_ci'); $table->addColumn('bar', 'text')->setPlatformOption('collation', 'utf8_general_ci');
$table->addColumn('baz', 'text')->setPlatformOption('collation', 'binary');
$this->schemaManager->dropAndCreateTable($table); $this->schemaManager->dropAndCreateTable($table);
$columns = $this->schemaManager->listTableColumns('test_collation'); $columns = $this->schemaManager->listTableColumns('test_collation');
...@@ -283,6 +285,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -283,6 +285,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertEquals('latin1_swedish_ci', $columns['text']->getPlatformOption('collation')); self::assertEquals('latin1_swedish_ci', $columns['text']->getPlatformOption('collation'));
self::assertEquals('latin1_swedish_ci', $columns['foo']->getPlatformOption('collation')); self::assertEquals('latin1_swedish_ci', $columns['foo']->getPlatformOption('collation'));
self::assertEquals('utf8_general_ci', $columns['bar']->getPlatformOption('collation')); self::assertEquals('utf8_general_ci', $columns['bar']->getPlatformOption('collation'));
self::assertInstanceOf(BlobType::class, $columns['baz']->getType());
} }
/** /**
......
...@@ -45,7 +45,7 @@ class MySqlInheritCharsetTest extends TestCase ...@@ -45,7 +45,7 @@ class MySqlInheritCharsetTest extends TestCase
$table = new Table('foobar', [new Column('aa', Type::getType('integer'))]); $table = new Table('foobar', [new Column('aa', Type::getType('integer'))]);
self::assertSame( self::assertSame(
$platform->getCreateTableSQL($table), $platform->getCreateTableSQL($table),
['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'] ['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB']
); );
// explicit utf8 // explicit utf8
...@@ -53,7 +53,7 @@ class MySqlInheritCharsetTest extends TestCase ...@@ -53,7 +53,7 @@ class MySqlInheritCharsetTest extends TestCase
$table->addOption('charset', 'utf8'); $table->addOption('charset', 'utf8');
self::assertSame( self::assertSame(
$platform->getCreateTableSQL($table), $platform->getCreateTableSQL($table),
['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'] ['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB']
); );
// explicit utf8mb4 // explicit utf8mb4
...@@ -61,7 +61,7 @@ class MySqlInheritCharsetTest extends TestCase ...@@ -61,7 +61,7 @@ class MySqlInheritCharsetTest extends TestCase
$table->addOption('charset', 'utf8mb4'); $table->addOption('charset', 'utf8mb4');
self::assertSame( self::assertSame(
$platform->getCreateTableSQL($table), $platform->getCreateTableSQL($table),
['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci ENGINE = InnoDB'] ['CREATE TABLE foobar (aa INT NOT NULL) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB']
); );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment