diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-08-03 00:28:57 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2006-08-03 00:28:57 +0000 |
commit | aaefbb7e04c0b673d052c225e51749549f354f12 (patch) | |
tree | 9ca5ae39ddc83f94567b84384bfc50672f1304f5 /lib/sqlalchemy/databases | |
parent | d6a6d67b8cded2280c216c6d224852f6b8a8d79e (diff) | |
download | sqlalchemy-aaefbb7e04c0b673d052c225e51749549f354f12.tar.gz |
- better check for ambiguous join conditions in sql.Join; propigates to a
better error message in PropertyLoader (i.e. relation()/backref()) for when
the join condition can't be reasonably determined.
- sqlite creates ForeignKeyConstraint objects properly upon table
reflection.
Diffstat (limited to 'lib/sqlalchemy/databases')
-rw-r--r-- | lib/sqlalchemy/databases/sqlite.py | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index b68bf99a7..529486f46 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -200,16 +200,30 @@ class SQLiteDialect(ansisql.ANSIDialect): raise exceptions.NoSuchTableError(table.name) c = connection.execute("PRAGMA foreign_key_list(" + table.name + ")", {}) + fks = {} while True: row = c.fetchone() if row is None: break - (tablename, localcol, remotecol) = (row[2], row[3], row[4]) - #print "row! " + repr(row) + (constraint_name, tablename, localcol, remotecol) = (row[0], row[2], row[3], row[4]) + try: + fk = fks[constraint_name] + except KeyError: + fk = ([],[]) + fks[constraint_name] = fk + + print "row! " + repr([key for key in row.keys()]), repr(row) # look up the table based on the given table's engine, not 'self', # since it could be a ProxyEngine remotetable = schema.Table(tablename, table.metadata, autoload=True, autoload_with=connection) - table.c[localcol].append_item(schema.ForeignKey(remotetable.c[remotecol])) + constrained_column = table.c[localcol].name + refspec = ".".join([tablename, remotecol]) + if constrained_column not in fk[0]: + fk[0].append(constrained_column) + if refspec not in fk[1]: + fk[1].append(refspec) + for name, value in fks.iteritems(): + table.append_item(schema.ForeignKeyConstraint(value[0], value[1])) # check for UNIQUE indexes c = connection.execute("PRAGMA index_list(" + table.name + ")", {}) unique_indexes = [] |