From: Roman Podoliaka Date: Fri, 14 Feb 2014 11:04:57 +0000 (+0200) Subject: Fix unique constraints reflection in SQLite X-Git-Tag: rel_0_8_5~15^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a7e0d3e1e36076e20ead9447508d99b2e477ba46;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix unique constraints reflection in SQLite Reflection of unique constraints didn't work properly, if reserved identifiers had been used as column names. In this case column names would be put in double quotes (e.g. the name of column asc would be returned as "asc"). This issue is only present in 0.8.4 and not in 0.9.x. --- diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 19a35b4954..328fe1caa3 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -940,7 +940,7 @@ 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': [c.strip(' "') for c 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 418c080a2c..263a6ae3bd 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -385,6 +385,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') ) @@ -394,6 +395,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: