From: Mike Bayer Date: Mon, 2 Jul 2007 18:53:35 +0000 (+0000) Subject: - standardized the behavior for table reflection where types can't be located; X-Git-Tag: rel_0_4_6~138 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=336b069b4d60c6a6626aa8ccda7685b6bf52c669;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - standardized the behavior for table reflection where types can't be located; NullType is substituted instead, warning is raised. - consolidation of imports in some db modules --- diff --git a/CHANGES b/CHANGES index 135f35bd43..f1f95230df 100644 --- 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. diff --git a/lib/sqlalchemy/databases/firebird.py b/lib/sqlalchemy/databases/firebird.py index 64f5842384..ab6b858499 100644 --- a/lib/sqlalchemy/databases/firebird.py +++ b/lib/sqlalchemy/databases/firebird.py @@ -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 diff --git a/lib/sqlalchemy/databases/informix.py b/lib/sqlalchemy/databases/informix.py index 99bc3896c9..5382ce2a42 100644 --- a/lib/sqlalchemy/databases/informix.py +++ b/lib/sqlalchemy/databases/informix.py @@ -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: diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 8b81884bb9..78bf52dc50 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -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= [] diff --git a/lib/sqlalchemy/databases/mysql.py b/lib/sqlalchemy/databases/mysql.py index dfdebc5df4..341550e114 100644 --- a/lib/sqlalchemy/databases/mysql.py +++ b/lib/sqlalchemy/databases/mysql.py @@ -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: diff --git a/lib/sqlalchemy/databases/oracle.py b/lib/sqlalchemy/databases/oracle.py index 4add288ee4..c0264ca846 100644 --- a/lib/sqlalchemy/databases/oracle.py +++ b/lib/sqlalchemy/databases/oracle.py @@ -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: diff --git a/lib/sqlalchemy/databases/sqlite.py b/lib/sqlalchemy/databases/sqlite.py index e3282e028a..a5328cfcf2 100644 --- a/lib/sqlalchemy/databases/sqlite.py +++ b/lib/sqlalchemy/databases/sqlite.py @@ -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) diff --git a/lib/sqlalchemy/types.py b/lib/sqlalchemy/types.py index b7f9e6e992..7dcc44eccb 100644 --- a/lib/sqlalchemy/types.py +++ b/lib/sqlalchemy/types.py @@ -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()