diff options
author | Roman Podoliaka <rpodolyaka@mirantis.com> | 2014-02-14 13:04:57 +0200 |
---|---|---|
committer | Roman Podoliaka <rpodolyaka@mirantis.com> | 2014-02-14 14:09:21 +0200 |
commit | a7e0d3e1e36076e20ead9447508d99b2e477ba46 (patch) | |
tree | 2dfecc81a90ac63764eeca3a56c332f0f44277c0 | |
parent | b87935ed4409cb57a88d5e84d4280d8f97be13ee (diff) | |
download | sqlalchemy-pr/72.tar.gz |
Fix unique constraints reflection in SQLitepr/72
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.
-rw-r--r-- | lib/sqlalchemy/dialects/sqlite/base.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/testing/suite/test_reflection.py | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 19a35b495..328fe1caa 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 418c080a2..263a6ae3b 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: |