]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug in SQLite dialect where reflection of UNIQUE constraints
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 21 Jul 2015 16:33:35 +0000 (12:33 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 21 Jul 2015 16:36:37 +0000 (12:36 -0400)
that included non-alphabetic characters in the names, like dots or
spaces, would not be reflected with their name.
fixes #3495

(cherry picked from commit f39e692d1249aeffb4de85987f6a74303fc5dcc5)

Conflicts:
lib/sqlalchemy/dialects/sqlite/base.py

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/dialects/sqlite/base.py
lib/sqlalchemy/testing/suite/test_reflection.py

index 1a653af96fc64d922c5594d676d64b07f68c57ba..cd2e073757cd73aad0f1bc0af3d2c920863e2c01 100644 (file)
 .. changelog::
     :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
index 8653d7bb82de2c7d7915f899810cc7d21a4571f7..fc36491000a6b3f61763365da30686a41295d7fd 100644 (file)
@@ -1307,7 +1307,7 @@ class SQLiteDialect(default.DefaultDialect):
         c = connection.execute(UNIQUE_SQL, table_name=table_name)
         table_data = c.fetchone()[0]
 
-        UNIQUE_PATTERN = 'CONSTRAINT (\w+) UNIQUE \(([^\)]+)\)'
+        UNIQUE_PATTERN = 'CONSTRAINT "?(.+?)"? UNIQUE \(([^\)]+)\)'
         return [
             {'name': name,
              'column_names': [col.strip(' "') for col in cols.split(',')]}
index 7cc5fd1605ffe21b7322fc337c31727e72178bab..e1e612c4d866d3c9747176e83175a02800beaeb2 100644 (file)
@@ -431,12 +431,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')
         )