diff options
-rw-r--r-- | CHANGES | 6 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/mysql.py | 2 | ||||
-rw-r--r-- | lib/sqlalchemy/databases/sqlite.py | 6 | ||||
-rw-r--r-- | test/engine/reflection.py | 30 |
4 files changed, 38 insertions, 6 deletions
@@ -1,7 +1,11 @@ ======= CHANGES ======= - +0.4.1 +----- +- added test coverage for unknown type reflection, fixed + sqlite/mysql handling of type reflection for unknown types + 0.4.0 ----- - (see 0.4.0beta1 for the start of major changes against 0.3, diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index 66b62c215..de417f3a5 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -2046,7 +2046,7 @@ class MySQLSchemaReflector(object): warnings.warn(RuntimeWarning( "Did not recognize type '%s' of column '%s'" % (type_, name))) - col_type = sqltypes.NULLTYPE + col_type = sqltypes.NullType # Column type positional arguments eg. varchar(32) if args is None or args == '': diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index ea15381db..99a1d5650 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -153,7 +153,7 @@ colspecs = { sqltypes.CHAR: SLChar, } -pragma_names = { +ischema_names = { 'INTEGER' : SLInteger, 'INT' : SLInteger, 'SMALLINT' : SLSmallInteger, @@ -271,10 +271,10 @@ class SQLiteDialect(default.DefaultDialect): args = '' try: - coltype = pragma_names[coltype] + coltype = ischema_names[coltype] except KeyError: warnings.warn(RuntimeWarning("Did not recognize type '%s' of column '%s'" % (coltype, name))) - coltype = sqltypes.NULLTYPE + coltype = sqltypes.NullType if args is not None: args = re.findall(r'(\d+)', args) diff --git a/test/engine/reflection.py b/test/engine/reflection.py index 4f1d18d5d..af190649c 100644 --- a/test/engine/reflection.py +++ b/test/engine/reflection.py @@ -3,6 +3,7 @@ import pickle, StringIO, unicodedata from sqlalchemy import * from sqlalchemy import exceptions +from sqlalchemy import types as sqltypes from testlib import * from testlib import engines @@ -181,7 +182,34 @@ class ReflectionTest(PersistTest): assert len(a4.constraints) == 2 finally: meta.drop_all() - + + def test_unknown_types(self): + meta = MetaData(testbase.db) + t = Table("test", meta, + Column('foo', String(30))) + + import sys + dialect_module = sys.modules[testbase.db.dialect.__module__] + + # we're relying on the presence of "ischema_names" in the + # dialect module, else we can't test this. we need to be able + # to get the dialect to not be aware of some type so we temporarily + # monkeypatch. not sure what a better way for this could be, + # except for an established dialect hook or dialect-specific tests + if not hasattr(dialect_module, 'ischema_names'): + return + + ischema_names = dialect_module.ischema_names + t.create() + dialect_module.ischema_names = {} + try: + m2 = MetaData(testbase.db) + t2 = Table("test", m2, autoload=True) + assert t2.c.foo.type.__class__ == sqltypes.NullType + finally: + dialect_module.ischema_names = ischema_names + t.drop() + def test_override_fkandpkcol(self): """test that you can override columns which contain foreign keys to other reflected tables, where the foreign key column is also a primary key column""" |