]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- standardized the behavior for table reflection where types can't be located;
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 2 Jul 2007 18:53:35 +0000 (18:53 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 2 Jul 2007 18:53:35 +0000 (18:53 +0000)
NullType is substituted instead, warning is raised.
- consolidation of imports in some db modules

CHANGES
lib/sqlalchemy/databases/firebird.py
lib/sqlalchemy/databases/informix.py
lib/sqlalchemy/databases/mssql.py
lib/sqlalchemy/databases/mysql.py
lib/sqlalchemy/databases/oracle.py
lib/sqlalchemy/databases/sqlite.py
lib/sqlalchemy/types.py

diff --git a/CHANGES b/CHANGES
index 135f35bd43a3664b41d927d4e98876eb8bc06da9..f1f95230dfdef06bb47fe4f83e10ed1ef1faa95a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -96,6 +96,8 @@
   - added "explcit" create/drop/execute support for sequences 
     (i.e. you can pass a "connectable" to each of those methods
     on Sequence)
+  - standardized the behavior for table reflection where types can't be located;
+    NullType is substituted instead, warning is raised.
 - extensions
   - proxyengine is temporarily removed, pending an actually working
     replacement.
index 64f5842384191c5516a77f330ce2a3a20ca1abba..ab6b8584992ad77cd872f381efb78a3ae7257e29 100644 (file)
@@ -5,15 +5,11 @@
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 
-import sys, StringIO, string, types
+import sys, StringIO, string, types, warnings
 
-from sqlalchemy import util
+from sqlalchemy import util, sql, schema, ansisql, exceptions
 import sqlalchemy.engine.default as default
-import sqlalchemy.sql as sql
-import sqlalchemy.schema as schema
-import sqlalchemy.ansisql as ansisql
 import sqlalchemy.types as sqltypes
-import sqlalchemy.exceptions as exceptions
 
 
 _initialized_kb = False
@@ -258,7 +254,13 @@ class FBDialect(ansisql.ANSIDialect):
 
             kw = {}
             # get the data types and lengths
-            args.append(column_func[row['FTYPE']](row))
+            coltype = column_func.get(row['FTYPE'], None)
+            if coltype is None:
+                warnings.warn(RuntimeWarning("Did not recognize type '%s' of column '%s'" % (str(row['FTYPE']), name)))
+                coltype = sqltypes.NULLTYPE
+            else:
+                coltype = coltype(row)
+            args.append(coltype)
 
             # is it a primary key?
             kw['primary_key'] = name in pkfields
index 99bc3896c9898e4b79af4c479c61a18e3824337c..5382ce2a42424f2a4932f24b0d6b41967a0fbd58 100644 (file)
@@ -6,19 +6,13 @@
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
 
-import sys, StringIO, string , random
+import sys, StringIO, string , random, warnings
 import datetime
 from decimal import Decimal
 
-import sqlalchemy.util as util
-import sqlalchemy.sql as sql
-import sqlalchemy.engine as engine
+from sqlalchemy import util, sql, engine, schema, ansisql, exceptions, pool
 import sqlalchemy.engine.default as default
-import sqlalchemy.schema as schema
-import sqlalchemy.ansisql as ansisql
 import sqlalchemy.types as sqltypes
-import sqlalchemy.exceptions as exceptions
-import sqlalchemy.pool as pool
 
 
 # for offset
@@ -306,7 +300,11 @@ class InfoDialect(ansisql.ANSIDialect):
                     scale = 0
                 coltype = InfoNumeric(precision, scale)
             else:
-                coltype = ischema_names.get(coltype)
+                try:
+                    coltype = ischema_names[coltype]
+                except KeyError:
+                    warnings.warn(RuntimeWarning("Did not recognize type '%s' of column '%s'" % (coltype, name)))
+                    coltype = sqltypes.NULLTYPE
             
             colargs = []
             if default is not None:
index 8b81884bb9a8ca7890c0ba8739beee35b52991c9..78bf52dc5062a68e9ad9f9709241d099cb832cca 100644 (file)
@@ -42,16 +42,11 @@ Known issues / TODO:
   
 """
 
-import sys, StringIO, string, types, re, datetime, random
+import sys, StringIO, string, types, re, datetime, random, warnings
 
-import sqlalchemy.sql as sql
-import sqlalchemy.engine as engine
-import sqlalchemy.engine.default as default
-import sqlalchemy.schema as schema
-import sqlalchemy.ansisql as ansisql
+from sqlalchemy import sql, engine, schema, ansisql, exceptions
 import sqlalchemy.types as sqltypes
-import sqlalchemy.exceptions as exceptions
-
+from sqlalchemy.engine import default
     
 class MSNumeric(sqltypes.Numeric):
     def convert_result_value(self, value, dialect):
@@ -507,11 +502,15 @@ class MSSQLDialect(ansisql.ANSIDialect):
             for a in (charlen, numericprec, numericscale):
                 if a is not None:
                     args.append(a)
-            coltype = self.ischema_names[type]
+            coltype = self.ischema_names.get(type, None)
             if coltype == MSString and charlen == -1:
                 coltype = MSText()                
             else:
-                if coltype == MSNVarchar and charlen == -1:
+                if coltype is None:
+                    warnings.warn(RuntimeWarning("Did not recognize type '%s' of column '%s'" % (type, name)))
+                    coltype = sqltypes.NULLTYPE
+                    
+                elif coltype == MSNVarchar and charlen == -1:
                     charlen = None
                 coltype = coltype(*args)
             colargs= []
index dfdebc5df4f573b55cef0cdea86684da00ef36c8..341550e114d8893d4cf3227b761883375cf2311d 100644 (file)
@@ -4,7 +4,7 @@
 # This module is part of SQLAlchemy and is released under
 # the MIT License: http://www.opensource.org/licenses/mit-license.php
 
-import sys, StringIO, string, types, re, datetime, inspect
+import sys, StringIO, string, types, re, datetime, inspect, warnings
 
 from sqlalchemy import sql,engine,schema,ansisql
 from sqlalchemy.engine import default
@@ -1117,7 +1117,11 @@ class MySQLDialect(ansisql.ANSIDialect):
             extra_2 = match.group(4)
 
             #print "coltype: " + repr(col_type) + " args: " + repr(args) + "extras:" + repr(extra_1) + ' ' + repr(extra_2)
-            coltype = ischema_names.get(col_type, MSString)
+            try:
+                coltype = ischema_names[col_type]
+            except KeyError:
+                warnings.warn(RuntimeWarning("Did not recognize type '%s' of column '%s'" % (col_type, name)))
+                coltype = sqltypes.NULLTYPE
 
             kw = {}
             if extra_1 is not None:
index 4add288ee451030bdcad1d1ce92d0b0badf1c43b..c0264ca84682b9aa04fd2ea8f9f199ddfb689138 100644 (file)
@@ -359,7 +359,8 @@ class OracleDialect(ansisql.ANSIDialect):
                 try:
                     coltype = ischema_names[coltype]
                 except KeyError:
-                    raise exceptions.AssertionError("Can't get coltype for type '%s' on colname '%s'" % (coltype, colname))
+                    warnings.warn(RuntimeWarning("Did not recognize type '%s' of column '%s'" % (coltype, colname)))
+                    coltype = sqltypes.NULLTYPE
 
             colargs = []
             if default is not None:
index e3282e028ae43fd845bb43ce112584fe2eb9aac0..a5328cfcf20170333d99e68b0a08addd87e3ed1a 100644 (file)
@@ -253,7 +253,12 @@ class SQLiteDialect(ansisql.ANSIDialect):
                 args = ''
 
             #print "coltype: " + repr(coltype) + " args: " + repr(args)
-            coltype = pragma_names.get(coltype, SLString)
+            try:
+                coltype = pragma_names[coltype]
+            except KeyError:
+                warnings.warn(RuntimeWarning("Did not recognize type '%s' of column '%s'" % (coltype, name)))
+                coltype = sqltypes.NULLTYPE
+                
             if args is not None:
                 args = re.findall(r'(\d+)', args)
                 #print "args! " +repr(args)
index b7f9e6e9926b81c109a076adb7753d744da41afb..7dcc44eccbce0e7cb7651891bf639eea7802533b 100644 (file)
@@ -181,7 +181,7 @@ def adapt_type(typeobj, colspecs):
         return typeobj
     return typeobj.adapt(impltype)
 
-class NullTypeEngine(TypeEngine):
+class NullType(TypeEngine):
     def get_col_spec(self):
         raise NotImplementedError()
 
@@ -190,6 +190,7 @@ class NullTypeEngine(TypeEngine):
 
     def convert_result_value(self, value, dialect):
         return value
+NullTypeEngine = NullType
 
 class String(TypeEngine):
     def __init__(self, length=None, convert_unicode=False):
@@ -418,4 +419,4 @@ class NCHAR(Unicode):pass
 class BLOB(Binary): pass
 class BOOLEAN(Boolean): pass
 
-NULLTYPE = NullTypeEngine()
+NULLTYPE = NullType()