]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix for sqlite refection of names with weird quotes around them in the DDL which...
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 19 Oct 2006 23:01:14 +0000 (23:01 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 19 Oct 2006 23:01:14 +0000 (23:01 +0000)
lib/sqlalchemy/databases/sqlite.py
test/engine/reflection.py

index a4445b1a83100c8d43d60810d481377d98644d2d..557441254a1147c4f6851d36bed5fa855690704e 100644 (file)
@@ -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:
index 469aab20ebe3a09758d1bce7f26ebbe9470ad333..fa0cb4245aec4abb65594844c009106ebb78ee0a 100644 (file)
@@ -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)