diff options
-rw-r--r-- | lib/sqlalchemy/databases/sqlite.py | 56 | ||||
-rw-r--r-- | test/dialect/sqlite.py | 68 |
2 files changed, 97 insertions, 27 deletions
diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index a5a5a2ed9..939a19228 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -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) diff --git a/test/dialect/sqlite.py b/test/dialect/sqlite.py index f04093b89..5041cca89 100644 --- a/test/dialect/sqlite.py +++ b/test/dialect/sqlite.py @@ -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' |