Unverified Commit c98c5482 authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #3668 from staudenmeir/mysql-collation

Quote collation on MySQL
parents d9b377cd 733b64bc
......@@ -503,7 +503,7 @@ SQL
$options['collate'] = $options['charset'] . '_unicode_ci';
}
$tableOptions[] = sprintf('COLLATE %s', $options['collate']);
$tableOptions[] = $this->getColumnCollationDeclarationSQL($options['collate']);
// Engine
if (! isset($options['engine'])) {
......@@ -965,6 +965,14 @@ SQL
return 'CHARACTER SET ' . $charset;
}
/**
* {@inheritDoc}
*/
public function getColumnCollationDeclarationSQL($collation)
{
return 'COLLATE ' . $this->quoteSingleIdentifier($collation);
}
/**
* {@inheritDoc}
*/
......
......@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\BlobType;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\Tests\Types\MySqlPointType;
......@@ -275,6 +276,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
$table->addColumn('text', 'text');
$table->addColumn('foo', 'text')->setPlatformOption('collation', 'latin1_swedish_ci');
$table->addColumn('bar', 'text')->setPlatformOption('collation', 'utf8_general_ci');
$table->addColumn('baz', 'text')->setPlatformOption('collation', 'binary');
$this->schemaManager->dropAndCreateTable($table);
$columns = $this->schemaManager->listTableColumns('test_collation');
......@@ -283,6 +285,7 @@ class MySqlSchemaManagerTest extends SchemaManagerFunctionalTestCase
self::assertEquals('latin1_swedish_ci', $columns['text']->getPlatformOption('collation'));
self::assertEquals('latin1_swedish_ci', $columns['foo']->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
$table = new Table('foobar', [new Column('aa', Type::getType('integer'))]);
self::assertSame(
$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
......@@ -53,7 +53,7 @@ class MySqlInheritCharsetTest extends TestCase
$table->addOption('charset', 'utf8');
self::assertSame(
$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
......@@ -61,7 +61,7 @@ class MySqlInheritCharsetTest extends TestCase
$table->addOption('charset', 'utf8mb4');
self::assertSame(
$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