summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorRoman Podolyaka <roman.podolyaka@gmail.com>2013-06-22 13:31:51 +0300
committerRoman Podolyaka <roman.podolyaka@gmail.com>2013-06-23 10:42:03 +0300
commit1ad06ea42c69c10f18c5d43d4d4a68223cbef52e (patch)
tree9d8d42bae2aa5a55d393fd6e6ca9eb9031e12d22 /lib/sqlalchemy
parent90296229209104e3903358844c2fbcd565d71bf3 (diff)
downloadsqlalchemy-1ad06ea42c69c10f18c5d43d4d4a68223cbef52e.tar.gz
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.
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/dialects/sqlite/base.py3
-rw-r--r--lib/sqlalchemy/testing/suite/test_reflection.py4
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py
index 3e2a158a0..787fdec17 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 16061780e..7ab4097a1 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: