From 3269b73ff7a12303aadcaed0246d401ec649fa94 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 8 Apr 2012 11:18:39 -0400 Subject: [PATCH] - adjust mysql patch a bit so that we use built in quoting for the "idx_" name as well - [bug] Fixed bug whereby column name inside of "KEY" clause for autoincrement composite column with InnoDB would double quote a name that's a reserved word. Courtesy Jeff Dairiki. [ticket:2460] --- CHANGES | 7 +++++++ lib/sqlalchemy/dialects/mysql/base.py | 8 ++++++-- test/dialect/test_mysql.py | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index c53822455c..a1c5dd4b9b 100644 --- a/CHANGES +++ b/CHANGES @@ -61,6 +61,13 @@ CHANGES respectively. Courtesy Diana Clarke [ticket:2445] +- mysql + - [bug] Fixed bug whereby column name inside + of "KEY" clause for autoincrement composite + column with InnoDB would double quote a + name that's a reserved word. Courtesy Jeff + Dairiki. [ticket:2460] + 0.7.6 ===== - orm diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 5636271362..65c2c59b9f 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -1395,8 +1395,12 @@ class MySQLDDLCompiler(compiler.DDLCompiler): 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, \ - self.preparer.format_column(auto_inc_column)) + constraint_string += "KEY %s (%s)" % ( + self.preparer.quote( + "idx_autoinc_%s" % auto_inc_column.name, None + ), + self.preparer.format_column(auto_inc_column) + ) return constraint_string diff --git a/test/dialect/test_mysql.py b/test/dialect/test_mysql.py index 613fac7c32..9a2e17ecc1 100644 --- a/test/dialect/test_mysql.py +++ b/test/dialect/test_mysql.py @@ -1411,7 +1411,7 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL): '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' 'oDB') t1 = Table('sometable', MetaData(), Column('assigned_id', @@ -1436,7 +1436,7 @@ class SQLTest(fixtures.TestBase, AssertsCompiledSQL): 'id INTEGER NOT NULL, ' '`order` INTEGER NOT NULL AUTO_INCREMENT, ' 'PRIMARY KEY (id, `order`), ' - 'KEY `idx_autoinc_order`(`order`)' + 'KEY idx_autoinc_order (`order`)' ')ENGINE=InnoDB') -- 2.47.2