From: Mike Bayer Date: Sun, 8 Jan 2012 00:49:25 +0000 (-0500) Subject: that's not a "name=0", that's a counter. so name is None unconditonally. X-Git-Tag: rel_0_7_5~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fd136760391712fc277d2cca73f6400f630d9e58;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git that's not a "name=0", that's a counter. so name is None unconditonally. [ticket:2348] --- diff --git a/CHANGES b/CHANGES index a1cb54d3d1..a55d5953f6 100644 --- 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 diff --git a/lib/sqlalchemy/dialects/sqlite/base.py b/lib/sqlalchemy/dialects/sqlite/base.py index 004798956a..aea1448523 100644 --- a/lib/sqlalchemy/dialects/sqlite/base.py +++ b/lib/sqlalchemy/dialects/sqlite/base.py @@ -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 , 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 diff --git a/test/dialect/test_sqlite.py b/test/dialect/test_sqlite.py index ed9d7e4936..7a5953654d 100644 --- a/test/dialect/test_sqlite.py +++ b/test/dialect/test_sqlite.py @@ -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):