From: Mike Bayer Date: Thu, 19 Oct 2006 23:01:14 +0000 (+0000) Subject: fix for sqlite refection of names with weird quotes around them in the DDL which... X-Git-Tag: rel_0_3_0~25 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a941dff48f04b9dc0a81ce2673c67b2ba24971ac;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix for sqlite refection of names with weird quotes around them in the DDL which seem to hang around --- diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index a4445b1a83..557441254a 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -186,7 +186,7 @@ class SQLiteDialect(ansisql.ANSIDialect): #print "row! " + repr(row) found_table = True (name, type, nullable, has_default, primary_key) = (row[1], row[2].upper(), not row[3], row[4] is not None, row[5]) - + name = re.sub(r'^\"|\"$', '', name) match = re.match(r'(\w+)(\(.*?\))?', type) coltype = match.group(1) args = match.group(2) @@ -213,6 +213,9 @@ class SQLiteDialect(ansisql.ANSIDialect): if row is None: break (constraint_name, tablename, localcol, remotecol) = (row[0], row[2], row[3], row[4]) + tablename = re.sub(r'^\"|\"$', '', tablename) + localcol = re.sub(r'^\"|\"$', '', localcol) + remotecol = re.sub(r'^\"|\"$', '', remotecol) try: fk = fks[constraint_name] except KeyError: diff --git a/test/engine/reflection.py b/test/engine/reflection.py index 469aab20eb..fa0cb4245a 100644 --- a/test/engine/reflection.py +++ b/test/engine/reflection.py @@ -223,6 +223,32 @@ class ReflectionTest(PersistTest): finally: t.drop() + @testbase.supported('sqlite') + def test_goofy_sqlite(self): + testbase.db.execute("""CREATE TABLE "django_content_type" ( + "id" integer NOT NULL PRIMARY KEY, + "django_stuff" text NULL + ) + """) + testbase.db.execute(""" + CREATE TABLE "django_admin_log" ( + "id" integer NOT NULL PRIMARY KEY, + "action_time" datetime NOT NULL, + "content_type_id" integer NULL REFERENCES "django_content_type" ("id"), + "object_id" text NULL, + "change_message" text NOT NULL + ) + """) + try: + meta = BoundMetaData(testbase.db) + table1 = Table("django_admin_log", meta, autoload=True) + table2 = Table("django_content_type", meta, autoload=True) + j = table1.join(table2) + assert j.onclause == table1.c.content_type_id==table2.c.id + finally: + testbase.db.execute("drop table django_admin_log") + testbase.db.execute("drop table django_content_type") + def testmultipk(self): """test that creating a table checks for a sequence before creating it""" meta = BoundMetaData(testbase.db)