summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2015-07-21 12:33:35 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2015-07-21 12:33:35 -0400
commitf39e692d1249aeffb4de85987f6a74303fc5dcc5 (patch)
treefa8c050e42af2a4e06b5e0adcad2f24c7f2b7df7
parent575f080850a0a061ccb7ac40e3ea1fbf6b0fedf4 (diff)
downloadsqlalchemy-f39e692d1249aeffb4de85987f6a74303fc5dcc5.tar.gz
- Fixed bug in SQLite dialect where reflection of UNIQUE constraints
that included non-alphabetic characters in the names, like dots or spaces, would not be reflected with their name. fixes #3495
-rw-r--r--doc/build/changelog/changelog_09.rst9
-rw-r--r--lib/sqlalchemy/dialects/sqlite/base.py2
-rw-r--r--lib/sqlalchemy/testing/suite/test_reflection.py8
3 files changed, 18 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst
index 2d2964ba4..4f1e6093e 100644
--- a/doc/build/changelog/changelog_09.rst
+++ b/doc/build/changelog/changelog_09.rst
@@ -15,6 +15,15 @@
:version: 0.9.10
.. change::
+ :tags: bug, sqlite
+ :tickets: 3495
+ :versions: 1.0.8
+
+ Fixed bug in SQLite dialect where reflection of UNIQUE constraints
+ that included non-alphabetic characters in the names, like dots or
+ spaces, would not be reflected with their name.
+
+ .. change::
:tags: feature, sql
:tickets: 3418
:versions: 1.0.5
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py
index d9da46f4c..e19047b76 100644
--- a/lib/sqlalchemy/dialects/sqlite/base.py
+++ b/lib/sqlalchemy/dialects/sqlite/base.py
@@ -1387,7 +1387,7 @@ class SQLiteDialect(default.DefaultDialect):
unique_constraints = []
def parse_uqs():
- UNIQUE_PATTERN = '(?:CONSTRAINT (\w+) +)?UNIQUE *\((.+?)\)'
+ UNIQUE_PATTERN = '(?:CONSTRAINT "?(.+?)"? +)?UNIQUE *\((.+?)\)'
INLINE_UNIQUE_PATTERN = (
'(?:(".+?")|([a-z0-9]+)) '
'+[a-z0-9_ ]+? +UNIQUE')
diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py
index 3edbdeb8c..288a85973 100644
--- a/lib/sqlalchemy/testing/suite/test_reflection.py
+++ b/lib/sqlalchemy/testing/suite/test_reflection.py
@@ -531,12 +531,20 @@ class ComponentReflectionTest(fixtures.TablesTest):
@testing.provide_metadata
def _test_get_unique_constraints(self, schema=None):
+ # SQLite dialect needs to parse the names of the constraints
+ # separately from what it gets from PRAGMA index_list(), and
+ # then matches them up. so same set of column_names in two
+ # constraints will confuse it. Perhaps we should no longer
+ # bother with index_list() here since we have the whole
+ # CREATE TABLE?
uniques = sorted(
[
{'name': 'unique_a', 'column_names': ['a']},
{'name': 'unique_a_b_c', 'column_names': ['a', 'b', 'c']},
{'name': 'unique_c_a_b', 'column_names': ['c', 'a', 'b']},
{'name': 'unique_asc_key', 'column_names': ['asc', 'key']},
+ {'name': 'i.have.dots', 'column_names': ['b']},
+ {'name': 'i have spaces', 'column_names': ['c']},
],
key=operator.itemgetter('name')
)