]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix mysql CREATE TABLE / COLLATE issue
authorGord Thompson <gord@gordthompson.com>
Thu, 6 Aug 2020 23:19:52 +0000 (17:19 -0600)
committerGord Thompson <gord@gordthompson.com>
Sun, 9 Aug 2020 23:21:42 +0000 (17:21 -0600)
Fixes: #5411
Change-Id: Ib0c53f5ed3f9d3ff0586580c9a9cce73b4b870f4

doc/build/changelog/unreleased_13/5411.rst [new file with mode: 0644]
lib/sqlalchemy/dialects/mysql/base.py
test/dialect/mysql/test_compiler.py

diff --git a/doc/build/changelog/unreleased_13/5411.rst b/doc/build/changelog/unreleased_13/5411.rst
new file mode 100644 (file)
index 0000000..8389278
--- /dev/null
@@ -0,0 +1,6 @@
+.. change::
+    :tags: bug, mysql
+    :tickets: 5411
+
+    Fixed an issue where CREATE TABLE statements were not specifying the
+    COLLATE keyword correctly.
\ No newline at end of file
index 90945ebadd14970d74f28ee10593d8578ddf4982..eea86bf758ac401bed6f30c97bc5ac941be555c3 100644 (file)
@@ -1796,6 +1796,8 @@ class MySQLDDLCompiler(compiler.DDLCompiler):
             [
                 ("DEFAULT_CHARSET", "COLLATE"),
                 ("DEFAULT_CHARACTER_SET", "COLLATE"),
+                ("CHARSET", "COLLATE"),
+                ("CHARACTER_SET", "COLLATE"),
             ],
             nonpart_options,
         ):
index 89af0ed4ec2fd196adfb086563557c2c4098eaa8..09bdd80be2382284e3c827e5e3dc33674b25f11a 100644 (file)
@@ -871,6 +871,34 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL):
             ")STATS_SAMPLE_PAGES=2 PARTITION BY HASH(other_id) PARTITIONS 2",
         )
 
+    def test_create_table_with_collate(self):
+        # issue #5411
+        t1 = Table(
+            "testtable",
+            MetaData(),
+            Column("id", Integer(), primary_key=True, autoincrement=True),
+            mysql_engine="InnoDB",
+            mysql_collate="utf8_icelandic_ci",
+            mysql_charset="utf8",
+        )
+        first_part = (
+            "CREATE TABLE testtable ("
+            "id INTEGER NOT NULL AUTO_INCREMENT, "
+            "PRIMARY KEY (id))"
+        )
+        try:
+            self.assert_compile(
+                schema.CreateTable(t1),
+                first_part
+                + "ENGINE=InnoDB CHARSET=utf8 COLLATE utf8_icelandic_ci",
+            )
+        except AssertionError:
+            self.assert_compile(
+                schema.CreateTable(t1),
+                first_part
+                + "CHARSET=utf8 ENGINE=InnoDB COLLATE utf8_icelandic_ci",
+            )
+
     def test_inner_join(self):
         t1 = table("t1", column("x"))
         t2 = table("t2", column("y"))