From: Roman Podolyaka Date: Sat, 22 Jun 2013 10:31:51 +0000 (+0300) Subject: Fix unique constraints reflection in SQLite X-Git-Tag: rel_0_9_0b1~240^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=1ad06ea42c69c10f18c5d43d4d4a68223cbef52e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix unique constraints reflection in SQLite If SQLite keywords are used as column names, they are quoted. The code parsing the information about table unique constraints should be modified so that it properly removes double-quotes from column names. --- diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 3e2a158a06..787fdec175 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -933,7 +933,8 @@ class SQLiteDialect(default.DefaultDialect): UNIQUE_PATTERN = 'CONSTRAINT (\w+) UNIQUE \(([^\)]+)\)' return [ - {'name': name, 'column_names': [c.strip() for c in cols.split(',')]} + {'name': name, + 'column_names': [col.strip(' "') for col in cols.split(',')]} for name, cols in re.findall(UNIQUE_PATTERN, table_data) ] diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index 16061780e0..7ab4097a11 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -373,6 +373,7 @@ class ComponentReflectionTest(fixtures.TablesTest): {'name': 'unique_a_b_c', 'column_names': ['a', 'b', 'c']}, {'name': 'unique_a_c', 'column_names': ['a', 'c']}, {'name': 'unique_b_c', 'column_names': ['b', 'c']}, + {'name': 'unique_asc_key', 'column_names': ['asc', 'key']}, ], key=operator.itemgetter('name') ) @@ -382,6 +383,9 @@ class ComponentReflectionTest(fixtures.TablesTest): Column('a', sa.String(20)), Column('b', sa.String(30)), Column('c', sa.Integer), + # reserved identifiers + Column('asc', sa.String(30)), + Column('key', sa.String(30)), schema=schema ) for uc in uniques: