]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug where reflection of foreign key
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 10 Apr 2011 14:47:34 +0000 (10:47 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 10 Apr 2011 14:47:34 +0000 (10:47 -0400)
created as "REFERENCES <tablename>" without
col name would fail.  [ticket:2115]
(also in 0.6.7)

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

diff --git a/CHANGES b/CHANGES
index 3b29f8bb6915d3773bda54499f7a279f9d9693fd..88347f066ea567a515c4224a9324e1d8e442beb8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -105,6 +105,12 @@ CHANGES
   - The "pool.manage" feature doesn't use pickle
     anymore to hash the arguments for each pool.
 
+- sqlite
+  - Fixed bug where reflection of foreign key
+    created as "REFERENCES <tablename>" without
+    col name would fail.  [ticket:2115]
+    (also in 0.6.7)
+
 - postgresql
   - Psycopg2 for Python 3 is now supported.
 
index 43d8d708ba9dfdc1e73b2bca6dbe0d93ba1c4dd1..95f699f545231bb4646ff93c6a950025a5815a9b 100644 (file)
@@ -683,6 +683,10 @@ class SQLiteDialect(default.DefaultDialect):
             if row is None:
                 break
             (constraint_name, 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:
+                rcol = lcol
             rtbl = re.sub(r'^\"|\"$', '', rtbl)
             lcol = re.sub(r'^\"|\"$', '', lcol)
             rcol = re.sub(r'^\"|\"$', '', rcol)
index c50bc69c648c7246b21fe9c4dcdbbb5191029fac..20e3419c42a0f4e4d9489a3a7a0217bd64e05233 100644 (file)
@@ -667,3 +667,22 @@ class AutoIncrementTest(fixtures.TestBase, AssertsCompiledSQL):
                             'CREATE TABLE autoinctable (id INTEGER NOT '
                             'NULL PRIMARY KEY AUTOINCREMENT)',
                             dialect=sqlite.dialect())
+
+
+class ReflectHeadlessFKsTest(fixtures.TestBase):
+    def setup(self):
+        testing.db.execute("CREATE TABLE a (id INTEGER PRIMARY KEY)")
+        testing.db.execute("CREATE TABLE b (id INTEGER PRIMARY KEY REFERENCES a)")
+
+    def teardown(self):
+        testing.db.execute("drop table b")
+        testing.db.execute("drop table a")
+
+    def test_reflect_tables_fk_no_colref(self):
+        meta = MetaData()
+        a = Table('a', meta, autoload=True, autoload_with=testing.db)
+        b = Table('b', meta, autoload=True, autoload_with=testing.db)
+
+        assert b.c.id.references(a.c.id)
+
+