[Sqlalchemy-commits] sqlalchemy: Fix innodb autoinc constraint (double)quoting
Brought to you by:
zzzeek
From: <co...@sq...> - 2012-04-08 15:19:05
|
details: http://hg.sqlalchemy.org/sqlalchemy/sqlalchemy/rev/8bdd1a8d9618 changeset: 8183:8bdd1a8d9618 user: Jeff Dairiki <da...@da...> date: Fri Apr 06 21:55:39 2012 -0700 description: Fix innodb autoinc constraint (double)quoting Subject: sqlalchemy: - adjust mysql patch a bit so that we use details: http://hg.sqlalchemy.org/sqlalchemy/sqlalchemy/rev/64e57ff24c70 changeset: 8184:64e57ff24c70 user: Mike Bayer <mi...@zz...> date: Sun Apr 08 11:18:39 2012 -0400 description: - 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] diffstat: CHANGES | 7 +++++++ lib/sqlalchemy/dialects/mysql/base.py | 8 ++++++-- test/dialect/test_mysql.py | 18 +++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diffs (70 lines): diff -r a98001d03a2f -r 64e57ff24c70 CHANGES --- a/CHANGES Thu Apr 05 14:31:28 2012 -0400 +++ b/CHANGES Sun Apr 08 11:18:39 2012 -0400 @@ -61,6 +61,13 @@ 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 -r a98001d03a2f -r 64e57ff24c70 lib/sqlalchemy/dialects/mysql/base.py --- a/lib/sqlalchemy/dialects/mysql/base.py Thu Apr 05 14:31:28 2012 -0400 +++ b/lib/sqlalchemy/dialects/mysql/base.py Sun Apr 08 11:18:39 2012 -0400 @@ -1395,8 +1395,12 @@ 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 -r a98001d03a2f -r 64e57ff24c70 test/dialect/test_mysql.py --- a/test/dialect/test_mysql.py Thu Apr 05 14:31:28 2012 -0400 +++ b/test/dialect/test_mysql.py Sun Apr 08 11:18:39 2012 -0400 @@ -1411,7 +1411,7 @@ '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', @@ -1424,6 +1424,22 @@ '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' |