]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- fixed reflection of Time columns on sqlite
authorJason Kirtland <jek@discorporate.us>
Fri, 1 Feb 2008 08:11:12 +0000 (08:11 +0000)
committerJason Kirtland <jek@discorporate.us>
Fri, 1 Feb 2008 08:11:12 +0000 (08:11 +0000)
lib/sqlalchemy/databases/sqlite.py
test/dialect/sqlite.py

index a5a5a2ed902a876bbb084ce9095ccacd15c51d75..939a192289d965aa8c7f5944e79699bc8087422c 100644 (file)
@@ -141,37 +141,39 @@ class SLBoolean(sqltypes.Boolean):
         return process
 
 colspecs = {
-    sqltypes.Integer : SLInteger,
-    sqltypes.Smallinteger : SLSmallInteger,
-    sqltypes.Numeric : SLNumeric,
-    sqltypes.Float : SLNumeric,
-    sqltypes.DateTime : SLDateTime,
-    sqltypes.Date : SLDate,
-    sqltypes.Time : SLTime,
-    sqltypes.String : SLString,
-    sqltypes.Binary : SLBinary,
-    sqltypes.Boolean : SLBoolean,
-    sqltypes.Text : SLText,
+    sqltypes.Binary: SLBinary,
+    sqltypes.Boolean: SLBoolean,
     sqltypes.CHAR: SLChar,
+    sqltypes.Date: SLDate,
+    sqltypes.DateTime: SLDateTime,
+    sqltypes.Float: SLNumeric,
+    sqltypes.Integer: SLInteger,
+    sqltypes.NCHAR: SLChar,
+    sqltypes.Numeric: SLNumeric,
+    sqltypes.Smallinteger: SLSmallInteger,
+    sqltypes.String: SLString,
+    sqltypes.Text: SLText,
+    sqltypes.Time: SLTime,
 }
 
 ischema_names = {
-    'INTEGER' : SLInteger,
-    'INT' : SLInteger,
-    'SMALLINT' : SLSmallInteger,
-    'VARCHAR' : SLString,
-    'CHAR' : SLChar,
-    'TEXT' : SLText,
-    'NUMERIC' : SLNumeric,
-    'DECIMAL' : SLNumeric,
-    'FLOAT' : SLNumeric,
-    'REAL': SLNumeric,
-    'TIMESTAMP' : SLDateTime,
-    'DATETIME' : SLDateTime,
-    'DATE' : SLDate,
-    'BLOB' : SLBinary,
+    'BLOB': SLBinary,
     'BOOL': SLBoolean,
     'BOOLEAN': SLBoolean,
+    'CHAR': SLChar,
+    'DATE': SLDate,
+    'DATETIME': SLDateTime,
+    'DECIMAL': SLNumeric,
+    'FLOAT': SLNumeric,
+    'INT': SLInteger,
+    'INTEGER': SLInteger,
+    'NUMERIC': SLNumeric,
+    'REAL': SLNumeric,
+    'SMALLINT': SLSmallInteger,
+    'TEXT': SLText,
+    'TIME': SLTime,
+    'TIMESTAMP': SLDateTime,
+    'VARCHAR': SLString,
 }
 
 def descriptor():
@@ -352,10 +354,10 @@ class SQLiteCompiler(compiler.DefaultCompiler):
     functions = compiler.DefaultCompiler.functions.copy()
     functions.update (
         {
-            sql_functions.now : 'CURRENT_TIMESTAMP'
+            sql_functions.now: 'CURRENT_TIMESTAMP'
         }
     )
-    
+
     def visit_cast(self, cast, **kwargs):
         if self.dialect.supports_cast:
             return super(SQLiteCompiler, self).visit_cast(cast)
index f04093b89c0ad316e3d0de8670cc985612b75653..5041cca89e3eab315170db4511ecdb36b9bbf7ad 100644 (file)
@@ -31,6 +31,74 @@ class TestTypes(AssertMixin):
         finally:
             meta.drop_all()
 
+    @testing.uses_deprecated('Using String type with no length')
+    def test_type_reflection(self):
+        # (ask_for, roundtripped_as_if_different)
+        specs = [( String(), sqlite.SLText(), ),
+                 ( String(1), sqlite.SLString(1), ),
+                 ( String(3), sqlite.SLString(3), ),
+                 ( Text(), sqlite.SLText(), ),
+                 ( Unicode(), sqlite.SLText(), ),
+                 ( Unicode(1), sqlite.SLString(1), ),
+                 ( Unicode(3), sqlite.SLString(3), ),
+                 ( UnicodeText(), sqlite.SLText(), ),
+                 ( CLOB, sqlite.SLText(), ),
+                 ( sqlite.SLChar(1), ),
+                 ( CHAR(3), sqlite.SLChar(3), ),
+                 ( NCHAR(2), sqlite.SLChar(2), ),
+                 ( SmallInteger(), sqlite.SLSmallInteger(), ),
+                 ( sqlite.SLSmallInteger(), ),
+                 ( Binary(3), sqlite.SLBinary(), ),
+                 ( Binary(), sqlite.SLBinary() ),
+                 ( sqlite.SLBinary(3), sqlite.SLBinary(), ),
+                 ( NUMERIC, sqlite.SLNumeric(), ),
+                 ( NUMERIC(10,2), sqlite.SLNumeric(10,2), ),
+                 ( Numeric, sqlite.SLNumeric(), ),
+                 ( Numeric(10, 2), sqlite.SLNumeric(10, 2), ),
+                 ( DECIMAL, sqlite.SLNumeric(), ),
+                 ( DECIMAL(10, 2), sqlite.SLNumeric(10, 2), ),
+                 ( Float, sqlite.SLNumeric(), ),
+                 ( sqlite.SLNumeric(), ),
+                 ( INT, sqlite.SLInteger(), ),
+                 ( Integer, sqlite.SLInteger(), ),
+                 ( sqlite.SLInteger(), ),
+                 ( TIMESTAMP, sqlite.SLDateTime(), ),
+                 ( DATETIME, sqlite.SLDateTime(), ),
+                 ( DateTime, sqlite.SLDateTime(), ),
+                 ( sqlite.SLDateTime(), ),
+                 ( DATE, sqlite.SLDate(), ),
+                 ( Date, sqlite.SLDate(), ),
+                 ( sqlite.SLDate(), ),
+                 ( TIME, sqlite.SLTime(), ),
+                 ( Time, sqlite.SLTime(), ),
+                 ( sqlite.SLTime(), ),
+                 ( BOOLEAN, sqlite.SLBoolean(), ),
+                 ( Boolean, sqlite.SLBoolean(), ),
+                 ( sqlite.SLBoolean(), ),
+                 ]
+        columns = [Column('c%i' % (i + 1), t[0]) for i, t in enumerate(specs)]
+
+        db = testing.db
+        m = MetaData(db)
+        t_table = Table('types', m, *columns)
+        try:
+            m.create_all()
+
+            m2 = MetaData(db)
+            rt = Table('types', m2, autoload=True)
+            try:
+                db.execute('CREATE VIEW types_v AS SELECT * from types')
+                rv = Table('types_v', m2, autoload=True)
+
+                expected = [len(c) > 1 and c[1] or c[0] for c in specs]
+                for table in rt, rv:
+                    for i, reflected in enumerate(table.c):
+                        print reflected.type, type(expected[i])
+                        assert isinstance(reflected.type, type(expected[i]))
+            finally:
+                db.execute('DROP VIEW types_v')
+        finally:
+            m.drop_all()
 
 class DialectTest(AssertMixin):
     __only_on__ = 'sqlite'