dairiki avatar dairiki committed 8bdd1a8

Fix innodb autoinc constraint (double)quoting

Comments (0)

Files changed (2)


                 auto_inc_column is not list(table.primary_key)[0]:
             if constraint_string:
                 constraint_string += ", \n\t"
-            constraint_string += "KEY `idx_autoinc_%s`(`%s`)" % (auto_inc_column.name, \
+            constraint_string += "KEY `idx_autoinc_%s`(%s)" % (auto_inc_column.name, \
         return constraint_string


                             'CREATE TABLE sometable (assigned_id '
                             'INTEGER NOT NULL, id INTEGER NOT NULL '
                             'AUTO_INCREMENT, PRIMARY KEY (assigned_id, '
-                            'id), KEY `idx_autoinc_id`(`id`))ENGINE=Inn'
+                            'id), KEY `idx_autoinc_id`(id))ENGINE=Inn'
         t1 = Table('sometable', MetaData(), Column('assigned_id',
                             'INTEGER NOT NULL, PRIMARY KEY '
                             '(assigned_id, id))ENGINE=InnoDB')
+    def test_innodb_autoincrement_reserved_word_column_name(self):
+        t1 = Table(
+            'sometable', MetaData(),
+            Column('id', Integer(), primary_key=True, autoincrement=False),
+            Column('order', Integer(), primary_key=True, autoincrement=True),
+            mysql_engine='InnoDB')
+        self.assert_compile(
+            schema.CreateTable(t1),
+            'CREATE TABLE sometable ('
+            'id INTEGER NOT NULL, '
+            '`order` INTEGER NOT NULL AUTO_INCREMENT, '
+            'PRIMARY KEY (id, `order`), '
+            'KEY `idx_autoinc_order`(`order`)'
+            ')ENGINE=InnoDB')
 class SQLModeDetectionTest(fixtures.TestBase):
     __only_on__ = 'mysql'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.