]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
that's not a "name=0", that's a counter. so name is None unconditonally.
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 8 Jan 2012 00:49:25 +0000 (19:49 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 8 Jan 2012 00:49:25 +0000 (19:49 -0500)
[ticket:2348]

CHANGES
lib/sqlalchemy/dialects/sqlite/base.py
test/dialect/test_sqlite.py

diff --git a/CHANGES b/CHANGES
index a1cb54d3d1efe8dae14600fec694725e913022f9..a55d5953f650898d5472bbfd25947b76980cd052 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -25,9 +25,10 @@ CHANGES
 
 - sqlite
   - [bug] the "name" of an FK constraint in SQLite
-    is reflected as "None", not "0" [ticket:2364].
+    is reflected as "None", not "0" or other 
+    integer value [ticket:2364].
     SQLite does not appear to support constraint
-    naming in any case (the names are ignored).
+    naming in any case.
 
 - Py3K
   - [bug] Fixed inappropriate usage of util.py3k
index 004798956aa486c5b5269547abda0e9b121cfbe2..aea14485235f1793a1ef81cb10bc8a5ee58666cf 100644 (file)
@@ -696,9 +696,7 @@ class SQLiteDialect(default.DefaultDialect):
             row = c.fetchone()
             if row is None:
                 break
-            (constraint_name, rtbl, lcol, rcol) = (row[0], row[2], row[3], row[4])
-            if not constraint_name:
-                constraint_name = None
+            (numerical_id, rtbl, lcol, rcol) = (row[0], row[2], row[3], row[4])
             # sqlite won't return rcol if the table
             # was created with REFERENCES <tablename>, no col
             if rcol is None:
@@ -707,17 +705,17 @@ class SQLiteDialect(default.DefaultDialect):
             lcol = re.sub(r'^\"|\"$', '', lcol)
             rcol = re.sub(r'^\"|\"$', '', rcol)
             try:
-                fk = fks[constraint_name]
+                fk = fks[numerical_id]
             except KeyError:
                 fk = {
-                    'name' : constraint_name,
+                    'name' : None,
                     'constrained_columns' : [],
                     'referred_schema' : None,
                     'referred_table' : rtbl,
                     'referred_columns' : []
                 }
                 fkeys.append(fk)
-                fks[constraint_name] = fk
+                fks[numerical_id] = fk
 
             # look up the table based on the given table's engine, not 'self',
             # since it could be a ProxyEngine
index ed9d7e4936da4eba52d9f2842411abf3762b709f..7a5953654da3e4c4f95bca613ea222adf178eccb 100644 (file)
@@ -732,17 +732,23 @@ class ReflectFKConstraintTest(fixtures.TestBase):
     __only_on__ = 'sqlite'
 
     def setup(self):
-        testing.db.execute("CREATE TABLE a (id INTEGER PRIMARY KEY)")
+        testing.db.execute("CREATE TABLE a1 (id INTEGER PRIMARY KEY)")
+        testing.db.execute("CREATE TABLE a2 (id INTEGER PRIMARY KEY)")
         testing.db.execute("CREATE TABLE b (id INTEGER PRIMARY KEY, "
-                            "FOREIGN KEY(id) REFERENCES a(id))")
+                            "FOREIGN KEY(id) REFERENCES a1(id),"
+                            "FOREIGN KEY(id) REFERENCES a2(id)"
+                            ")")
         testing.db.execute("CREATE TABLE c (id INTEGER, "
                             "CONSTRAINT bar PRIMARY KEY(id),"
-                            "CONSTRAINT foo FOREIGN KEY(id) REFERENCES a(id))")
+                            "CONSTRAINT foo1 FOREIGN KEY(id) REFERENCES a1(id),"
+                            "CONSTRAINT foo2 FOREIGN KEY(id) REFERENCES a2(id)"
+                            ")")
 
     def teardown(self):
         testing.db.execute("drop table c")
         testing.db.execute("drop table b")
-        testing.db.execute("drop table a")
+        testing.db.execute("drop table a1")
+        testing.db.execute("drop table a2")
 
     def test_name_is_none(self):
         # and not "0"
@@ -750,7 +756,7 @@ class ReflectFKConstraintTest(fixtures.TestBase):
         b = Table('b', meta, autoload=True, autoload_with=testing.db)
         eq_(
             [con.name for con in b.constraints],
-            [None, None]
+            [None, None, None]
         )
 
     def test_name_not_none(self):