]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- sqlite housekeeping- added dialect test & moved tests there, pruned the dialect...
authorJason Kirtland <jek@discorporate.us>
Thu, 11 Oct 2007 17:35:13 +0000 (17:35 +0000)
committerJason Kirtland <jek@discorporate.us>
Thu, 11 Oct 2007 17:35:13 +0000 (17:35 +0000)
lib/sqlalchemy/databases/sqlite.py
test/dialect/alltests.py
test/dialect/sqlite.py [new file with mode: 0644]
test/engine/reflection.py
test/sql/testtypes.py

index 8651608b215ea4b728ee45075f0cc1a3c3b7f19c..ea15381db52cadf99618f20930d7b4b7d256839c 100644 (file)
@@ -389,15 +389,26 @@ class SQLiteSchemaDropper(compiler.SchemaDropper):
     pass
 
 class SQLiteIdentifierPreparer(compiler.IdentifierPreparer):
-    reserved_words = compiler.IdentifierPreparer.reserved_words.union([
-        'abort', 'add', 'after', 'alter', 'attach', 'autoincrement', 'before',
-        'begin','by', 'cascade', 'commit', 'conflict', 'database', 'deferred',
-        'delete', 'detach', 'drop', 'each', 'escape', 'exclusive', 'explain',
-        'fail', 'glob', 'if', 'ignore', 'immediate', 'index', 'insert',
-        'instead', 'key', 'match', 'of', 'plan', 'pragma', 'query', 'raise',
-        'reindex', 'rename', 'replace', 'restrict', 'rollback', 'row', 'temp',
-        'temporary', 'transaction', 'trigger', 'update', 'vacuum', 'values',
-        'view', 'virtual'])
+    reserved_words = util.Set([
+        'add', 'after', 'all', 'alter', 'analyze', 'and', 'as', 'asc',
+        'attach', 'autoincrement', 'before', 'begin', 'between', 'by',
+        'cascade', 'case', 'cast', 'check', 'collate', 'column', 'commit',
+        'conflict', 'constraint', 'create', 'cross', 'current_date',
+        'current_time', 'current_timestamp', 'database', 'default',
+        'deferrable', 'deferred', 'delete', 'desc', 'detach', 'distinct',
+        'drop', 'each', 'else', 'end', 'escape', 'except', 'exclusive',
+        'explain', 'false', 'fail', 'for', 'foreign', 'from', 'full', 'glob',
+        'group', 'having', 'if', 'ignore', 'immediate', 'in', 'index',
+        'initially', 'inner', 'insert', 'instead', 'intersect', 'into', 'is',
+        'isnull', 'join', 'key', 'left', 'like', 'limit', 'match', 'natural',
+        'not', 'notnull', 'null', 'of', 'offset', 'on', 'or', 'order', 'outer',
+        'plan', 'pragma', 'primary', 'query', 'raise', 'references',
+        'reindex', 'rename', 'replace', 'restrict', 'right', 'rollback',
+        'row', 'select', 'set', 'table', 'temp', 'temporary', 'then', 'to',
+        'transaction', 'trigger', 'true', 'union', 'unique', 'update', 'using',
+        'vacuum', 'values', 'view', 'virtual', 'when', 'where',
+        ])
+
     def __init__(self, dialect):
         super(SQLiteIdentifierPreparer, self).__init__(dialect, omit_schema=True)
 
index 9058fb04c1447826c3b4ddf48a18a86f977bcbbe..3e34f737ef4e6f952daf47dd2774cf31d5c49954 100644 (file)
@@ -3,13 +3,14 @@ import unittest
 
 def suite():
     modules_to_test = (
-        'dialect.mysql',
-        'dialect.postgres',
-        'dialect.oracle',
-        'dialect.mssql',
         'dialect.access',
-        'dialect.informix',
         'dialect.firebird',
+        'dialect.informix',
+        'dialect.mssql',
+        'dialect.mysql',
+        'dialect.oracle',
+        'dialect.postgres',
+        'dialect.sqlite',
         )
     alltests = unittest.TestSuite()
     for name in modules_to_test:
diff --git a/test/dialect/sqlite.py b/test/dialect/sqlite.py
new file mode 100644 (file)
index 0000000..43ee9e6
--- /dev/null
@@ -0,0 +1,89 @@
+"""SQLite-specific tests."""
+
+import testbase
+import datetime
+from sqlalchemy import *
+from sqlalchemy.databases import sqlite
+from testlib import *
+
+
+class TestTypes(AssertMixin):
+    @testing.supported('sqlite')
+    def test_date(self):
+        meta = MetaData(testbase.db)
+        t = Table('testdate', meta,
+                  Column('id', Integer, primary_key=True),
+                  Column('adate', Date), 
+                  Column('adatetime', DateTime))
+        meta.create_all()
+        try:
+            d1 = datetime.date(2007, 10, 30)
+            d2 = datetime.datetime(2007, 10, 30)
+
+            t.insert().execute(adate=str(d1), adatetime=str(d2))
+            
+            self.assert_(t.select().execute().fetchall()[0] ==
+                         (1, datetime.date(2007, 10, 30),
+                          datetime.datetime(2007, 10, 30)))
+            
+        finally:
+            meta.drop_all()
+
+
+class DialectTest(AssertMixin):
+    @testing.supported('sqlite')
+    def test_extra_reserved_words(self):
+        """Tests reserved words in identifiers.
+
+        'true', 'false', and 'column' are undocumented reserved words
+        when used as column identifiers (as of 3.5.1).  Covering them here
+        to ensure they remain in place if the dialect's reserved_words set
+        is updated in the future.
+        """
+
+        meta = MetaData(testbase.db)
+        t = Table('reserved', meta,
+                  Column('safe', Integer),
+                  Column('true', Integer), 
+                  Column('false', Integer),
+                  Column('column', Integer))
+
+        try:
+            meta.create_all()
+            t.insert().execute(safe=1)
+            list(t.select().execute())
+        finally:
+            meta.drop_all()
+
+    @testing.supported('sqlite')
+    def test_quoted_identifiers(self):
+        """Tests autoload of tables created with quoted column names."""
+
+        # This is quirky in sqlite.
+        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 = MetaData(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")
+
+
+if __name__ == "__main__":
+    testbase.main()
index d4ada94e4c9f456f7587656a30cd128feb4e5980..82a04874afcd2748043fee8d11136e5bfcb9329a 100644 (file)
@@ -317,33 +317,6 @@ class ReflectionTest(PersistTest):
         finally:
             testbase.db.execute("drop table book")
 
-    @testing.supported('sqlite')
-    def test_goofy_sqlite(self):
-        """test autoload of table where quotes were used with all the colnames.  quirky in sqlite."""
-        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 = MetaData(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")
-
     @testing.exclude('mysql', '<', (4, 1, 1))
     def test_composite_fk(self):
         """test reflection of composite foreign keys"""
index 1a6fa7563dd1687e6622d82dfe47fbc38903723a..c11fa0bdf1c6a19d67edab0bf0557a9077a1e741 100644 (file)
@@ -424,27 +424,6 @@ class DateTest(AssertMixin):
         l = map(list, users_with_date.select().execute().fetchall())
         self.assert_(l == insert_data,
                      'DateTest mismatch: got:%s expected:%s' % (l, insert_data))
-
-    @testing.supported('sqlite')
-    def test_sqlite_date(self):
-        meta = MetaData(testbase.db)
-        t = Table('testdate', meta,
-                  Column('id', Integer, primary_key=True),
-                  Column('adate', Date), 
-                  Column('adatetime', DateTime))
-        t.create(checkfirst=True)
-        try:
-            d1 = datetime.date(2007, 10, 30)
-            d2 = datetime.datetime(2007, 10, 30)
-
-            t.insert().execute(adate=str(d1), adatetime=str(d2))
-            
-            self.assert_(t.select().execute().fetchall()[0] ==
-                         (1, datetime.date(2007, 10, 30),
-                          datetime.datetime(2007, 10, 30)))
-            
-        finally:
-            t.drop(checkfirst=True)
         
     def testtextdate(self):
         x = testbase.db.text(