summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2011-04-10 10:47:34 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2011-04-10 10:47:34 -0400
commitfb97a666bb6e352ae908d763d2d8ac3c087cd529 (patch)
treea9202a09caf517369279f24ac716698f7498ee90
parent3b22a2ac97bdb59b8b4afd7c9b0c525e03a8230a (diff)
downloadsqlalchemy-fb97a666bb6e352ae908d763d2d8ac3c087cd529.tar.gz
- Fixed bug where reflection of foreign key
created as "REFERENCES <tablename>" without col name would fail. [ticket:2115] (also in 0.6.7)
-rw-r--r--CHANGES6
-rw-r--r--lib/sqlalchemy/dialects/sqlite/base.py4
-rw-r--r--test/dialect/test_sqlite.py19
3 files changed, 29 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 3b29f8bb6..88347f066 100644
--- 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.
diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py
index 43d8d708b..95f699f54 100644
--- a/lib/sqlalchemy/dialects/sqlite/base.py
+++ b/lib/sqlalchemy/dialects/sqlite/base.py
@@ -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)
diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py
index c50bc69c6..20e3419c4 100644
--- a/test/dialect/test_sqlite.py
+++ b/test/dialect/test_sqlite.py
@@ -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)
+
+