]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- added test coverage for unknown type reflection, fixed
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 18 Oct 2007 17:56:18 +0000 (17:56 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 18 Oct 2007 17:56:18 +0000 (17:56 +0000)
  sqlite/mysql handling of type reflection for unknown types

CHANGES
lib/sqlalchemy/databases/mysql.py
lib/sqlalchemy/databases/sqlite.py
test/engine/reflection.py

diff --git a/CHANGES b/CHANGES
index 6e2777d5d9483547f14058a48adf7d8c2ce53924..f86adc4c6cc320263d7158166440288bfa8f84a8 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -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, 
index 66b62c215e50e15bce265b6c78770f05bd815bbd..de417f3a516daf6f35a40bc288f785d1a7fac987 100644 (file)
@@ -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 == '':
index ea15381db52cadf99618f20930d7b4b7d256839c..99a1d56503eeb68e3355a454402ef195879245ee 100644 (file)
@@ -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)
index 4f1d18d5d2bbfa436146775db44d856289e8b99a..af190649ccba7ae23db036fbfeacd4c873cbe8d2 100644 (file)
@@ -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"""