Contact: fumanchu@aminus.org

Log in as guest/geniusql to create tickets

Changeset 18

Show
Ignore:
Timestamp:
02/18/07 23:36:15
Author:
fumanchu
Message:

Moved Database.isrelatedtype to TypeAdapter?.related. Also moved Database.python_type to TypeAdapter?.python_type, which now uses TypeAdapter?._reverse_types (a dict). Also removed Typeless mode for SQLite; it's just too dangerous.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/geniusql/__init__.py

    r17 r18  
    7171        that's not How Python Works. Quack. 
    7272        ''' 
     73        type.__init__(name, bases, dct) 
    7374         
    7475        newdoc = [cls.__doc__ or ""] 
  • trunk/geniusql/adapters.py

    r17 r18  
    342342    """Determine the best database type for a given column + Python type. 
    343343     
    344     When Dejavu is asked to create database tables, it must choose an 
     344    When Geniusql is asked to create database tables, it must choose an 
    345345    appropriate column data type for each UnitProperty based on the 
    346346    type (and hints) of that property. This class recommends such 
     
    368368    # TEXT is not an SQL standard, but it's common. 
    369369    numeric_text_type = "TEXT" 
     370     
     371    _reverse_types = { 
     372        "DATE": datetime.date, 
     373        "DATETIME": datetime.datetime, 
     374        "TIMESTAMP": datetime.datetime, 
     375        "TIME": datetime.time, 
     376         
     377        "INT": int, 
     378        "INTEGER": int, 
     379        "SMALLINT": int, 
     380         
     381        "BOOL": bool, 
     382        "BOOLEAN": bool, 
     383         
     384        "BIGINT": long, 
     385        "LONG": long, 
     386         
     387        "DOUBLE": float, 
     388        "DOUBLE PRECISION": float, 
     389        "FLOAT": float, 
     390        "REAL": float, 
     391        "SINGLE": float, 
     392         
     393        "CHAR": str, 
     394        "BLOB": str, 
     395        "TEXT": str, 
     396        "VARCHAR": str, 
     397        } 
     398     
     399    if decimal: 
     400        _reverse_types["DECIMAL"] = decimal.Decimal 
     401        _reverse_types["NUMERIC"] = decimal.Decimal 
     402    elif fixedpoint: 
     403        _reverse_types["DECIMAL"] = fixedpoint.FixedPoint 
     404        _reverse_types["NUMERIC"] = fixedpoint.FixedPoint 
     405     
     406    def __init__(self): 
     407        # Make a copy of the class-level 'dict 
     408        self._reverse_types = self._reverse_types.copy() 
     409     
     410    def python_type(self, dbtype): 
     411        """Return a Python type which can store values of the given dbtype.""" 
     412        # Strip any size argument (e.g. "VARCHAR(255)"). 
     413        key = dbtype.upper().split("(", 1)[0] 
     414        try: 
     415            return self._reverse_types[key] 
     416        except KeyError: 
     417            raise TypeError("Database type %r could not be converted " 
     418                            "to a Python type." % dbtype) 
     419     
     420    def related(self, pytype1, pytype2): 
     421        """If values of both types are expressed with the same SQL, return True.""" 
     422        if issubclass(pytype1, pytype2) or issubclass(pytype2, pytype1): 
     423            return True 
     424        if issubclass(pytype1, basestring) and issubclass(pytype2, basestring): 
     425            return True 
     426        if ((issubclass(pytype1, int) or issubclass(pytype1, long)) and 
     427            (issubclass(pytype2, int) or issubclass(pytype2, long))): 
     428            return True 
     429        if fixedpoint: 
     430            if decimal: 
     431                if ((issubclass(pytype1, fixedpoint.FixedPoint) 
     432                     or issubclass(pytype1, decimal.Decimal)) and 
     433                    (issubclass(pytype2, fixedpoint.FixedPoint) 
     434                     or issubclass(pytype2, decimal.Decimal))): 
     435                    return True 
     436            else: 
     437                if (issubclass(pytype1, fixedpoint.FixedPoint) and 
     438                    issubclass(pytype2, fixedpoint.FixedPoint)): 
     439                    return True 
     440        else: 
     441            if decimal: 
     442                if (issubclass(pytype1, decimal.Decimal) and 
     443                    issubclass(pytype2, decimal.Decimal)): 
     444                    return True 
     445        return False 
    370446     
    371447    def coerce(self, col, pytype): 
  • trunk/geniusql/objects.py

    r17 r18  
    606606        if dbtype is None: 
    607607            col.dbtype = self.db.typeadapter.coerce(col, pytype) 
    608         pytype2 = self.db.python_type(col.dbtype) 
    609         col.imperfect_type = not self.db.isrelatedtype(pytype, pytype2) 
     608        pytype2 = self.db.typeadapter.python_type(col.dbtype) 
     609        col.imperfect_type = not self.db.typeadapter.related(pytype, pytype2) 
    610610         
    611611        return col 
     
    773773    def log(self, msg): 
    774774        pass 
    775      
    776     def python_type(self, dbtype): 
    777         """Return a Python type which can store values of the given dbtype.""" 
    778         raise TypeError("Database type %r could not be converted " 
    779                         "to a Python type." % dbtype) 
    780      
    781     def isrelatedtype(self, pytype1, pytype2): 
    782         """If values of both types are expressed with the same SQL, return True.""" 
    783         if issubclass(pytype1, pytype2) or issubclass(pytype2, pytype1): 
    784             return True 
    785         if issubclass(pytype1, basestring) and issubclass(pytype2, basestring): 
    786             return True 
    787         if ((issubclass(pytype1, int) or issubclass(pytype1, long)) and 
    788             (issubclass(pytype2, int) or issubclass(pytype2, long))): 
    789             return True 
    790         if typerefs.fixedpoint: 
    791             if typerefs.decimal: 
    792                 if ((issubclass(pytype1, typerefs.fixedpoint.FixedPoint) 
    793                      or issubclass(pytype1, typerefs.decimal.Decimal)) and 
    794                     (issubclass(pytype2, typerefs.fixedpoint.FixedPoint) 
    795                      or issubclass(pytype2, typerefs.decimal.Decimal))): 
    796                     return True 
    797             else: 
    798                 if (issubclass(pytype1, typerefs.fixedpoint.FixedPoint) and 
    799                     issubclass(pytype2, typerefs.fixedpoint.FixedPoint)): 
    800                     return True 
    801         else: 
    802             if typerefs.decimal: 
    803                 if (issubclass(pytype1, typerefs.decimal.Decimal) and 
    804                     issubclass(pytype2, typerefs.decimal.Decimal)): 
    805                     return True 
    806         return False 
    807775     
    808776    #                               Naming                               # 
  • trunk/geniusql/providers/ado.py

    r17 r18  
    511511         
    512512        cols = [] 
     513        pytype = self.db.typeadapter.python_type 
    513514        for row in data: 
    514515            # I tried passing criteria to OpenSchema, but passing None is 
     
    520521            default = row[8] 
    521522            if default is not None: 
    522                 deftype = self.db.python_type(dbtype) 
     523                deftype = pytype(dbtype) 
    523524                if issubclass(deftype, (int, long)): 
    524525                    # We may have stuck extraneous quotes in the default 
     
    529530             
    530531            name = str(row[3]) 
    531             c = geniusql.Column(self.db.python_type(dbtype), dbtype, 
     532            c = geniusql.Column(pytype(dbtype), dbtype, 
    532533                                default, hints={}, key=(name in pknames), 
    533534                                name=name, qname=self.db.quote(name)) 
     
    613614 
    614615 
     616class ADOTypeAdapter(adapters.TypeAdapter): 
     617     
     618    _reverse_types = adapters.TypeAdapter._reverse_types.copy() 
     619    _reverse_types.update({ 
     620        "DBDATE": datetime.date, 
     621        "DBTIME": datetime.time, 
     622        "DBTIMESTAMP": datetime.datetime, 
     623         
     624        "UNSIGNEDTINYINT": int, 
     625        "UNSIGNEDSMALLINT": int, 
     626        "UNSIGNEDINT": int, 
     627        "BIT": bool, 
     628         
     629        "UNSIGNEDBIGINT": long, 
     630         
     631        "BSTR": str, 
     632        "VARIANT": str, 
     633        "BINARY": str, 
     634        "LONGVARCHAR": str, 
     635        "VARBINARY": str, 
     636        "LONGVARBINARY": str, 
     637         
     638        "WCHAR": unicode, 
     639        "VARWCHAR": unicode, 
     640        "LONGVARWCHAR": unicode, 
     641        }) 
     642     
     643    if typerefs.decimal: 
     644        _reverse_types["CURRENCY"] = typerefs.decimal.Decimal 
     645    elif typerefs.fixedpoint: 
     646        _reverse_types["CURRENCY"] = typerefs.fixedpoint.FixedPoint 
     647 
     648 
    615649class ADODatabase(geniusql.Database): 
    616650     
    617651    decompiler = ADOSQLDecompiler 
    618652    adapterfromdb = AdapterFromADO() 
    619      
    620     def python_type(self, dbtype): 
    621         """Return a Python type which can store values of the given dbtype.""" 
    622         if dbtype in ("DATE", "DBDATE"): 
    623             return datetime.date 
    624         elif dbtype == "DBTIME": 
    625             return datetime.time 
    626         elif dbtype in ("DATETIME", "DBTIMESTAMP"): 
    627             return datetime.datetime 
    628         elif dbtype in ("SMALLINT", "INTEGER", "TINYINT", 
    629                         "UNSIGNEDTINYINT", "UNSIGNEDSMALLINT", 
    630                         "UNSIGNEDINT"): 
    631             return int 
    632         elif dbtype in ("BIT", "BOOLEAN"): 
    633             return bool 
    634         elif dbtype in ("BIGINT", "UNSIGNEDBIGINT", "LONG"): 
    635             return long 
    636         elif dbtype in ("SINGLE", "DOUBLE", "DOUBLE PRECISION", "REAL"): 
    637             return float 
    638          
    639         for t in ("DECIMAL", "NUMERIC", "CURRENCY"): 
    640             if dbtype.startswith(t): 
    641                 if typerefs.decimal: 
    642                     return typerefs.decimal.Decimal 
    643                 elif typerefs.fixedpoint: 
    644                     return typerefs.fixedpoint.FixedPoint 
    645          
    646         for t in ("BSTR", "VARIANT", "BINARY", "CHAR", "MEMO", "TEXT", 
    647                   "VARCHAR", "LONGVARCHAR", "VARBINARY", "LONGVARBINARY"): 
    648             if dbtype.startswith(t): 
    649                 return str 
    650          
    651         for t in ("WCHAR", "VARWCHAR", "LONGVARWCHAR"): 
    652             if dbtype.startswith(t): 
    653                 return unicode 
    654          
    655         raise TypeError("Database type %r could not be converted " 
    656                         "to a Python type." % dbtype) 
    657      
     653    typeadapter = ADOTypeAdapter() 
    658654     
    659655    #                               Naming                                # 
     
    806802 
    807803 
    808 class TypeAdapter_SQLServer(adapters.TypeAdapter): 
     804class TypeAdapter_SQLServer(ADOTypeAdapter): 
    809805     
    810806    # Hm. Docs say 38, but I can't seem to get more than 12 working. 
     
    999995 
    1000996 
    1001 class TypeAdapter_MSAccess(adapters.TypeAdapter): 
     997class TypeAdapter_MSAccess(ADOTypeAdapter): 
    1002998    # http://msdn2.microsoft.com/en-us/library/ms714540.aspx 
    1003999    # http://office.microsoft.com/en-us/access/HP010322481033.aspx 
     
    10061002    numeric_max_precision = 12 
    10071003    numeric_max_bytes = 6 
     1004     
     1005    _reverse_types = ADOTypeAdapter._reverse_types.copy() 
     1006    _reverse_types.update({ 
     1007        "LONG": int, 
     1008        "MEMO": str, 
     1009        }) 
    10081010     
    10091011    def coerce_bool(self, col): return "BIT" 
     
    12291231        del conn 
    12301232        return "ADO Version: %s" % v 
    1231      
    1232     def python_type(self, dbtype): 
    1233         if dbtype == "LONG": 
    1234             return int 
    1235         return ADODatabase.python_type(self, dbtype) 
    12361233 
    12371234 
  • trunk/geniusql/providers/firebird.py

    r17 r18  
    113113     
    114114    numeric_text_type = "BLOB" 
     115     
     116    _reverse_types = adapters.TypeAdapter._reverse_types.copy() 
     117    _reverse_types.update({ 
     118        'LONG': int, 
     119        'SHORT': int, 
     120        'INT64': long, 
     121        'VARYING': str, 
     122        'NCHAR': unicode, 
     123        'NATIONAL': unicode, 
     124        }) 
    115125     
    116126    def coerce_str(self, col): 
     
    435445            "T.RDB$FIELD_NAME='RDB$FIELD_TYPE';" % tablename, conn=conn) 
    436446        cols = [] 
     447        pytype = self.db.typeadapter.python_type 
    437448        for name, dbtype, fieldlen, default, prec, scale in data: 
    438449            hints = {} 
     
    463474             
    464475            # Column(pytype, dbtype, default=None, hints=None, key=False, name, qname) 
    465             col = geniusql.Column(self.db.python_type(dbtype), dbtype, default, 
     476            col = geniusql.Column(pytype(dbtype), dbtype, default, 
    466477                                  hints, key, name, self.db.quote(name)) 
    467478            cols.append(col) 
     
    563574    sql_name_max_length = 31 
    564575    encoding = 'utf8' 
    565      
    566     def python_type(self, dbtype): 
    567         """Return a Python type which can store values of the given dbtype.""" 
    568         dbtype = dbtype.upper() 
    569          
    570         if dbtype in ('INTEGER', 'SMALLINT', 'LONG', 'SHORT'): 
    571             return int 
    572         elif dbtype in ('BIGINT', 'INT64'): 
    573             return long 
    574         elif dbtype in ('FLOAT', 'DOUBLE', 'DOUBLE PRECISION', 'REAL'): 
    575             return float 
    576         elif dbtype.startswith('NUMERIC') or dbtype.startswith('DECIMAL'): 
    577             if typerefs.decimal: 
    578                 return typerefs.decimal.Decimal 
    579             elif typerefs.fixedpoint: 
    580                 return typerefs.fixedpoint.FixedPoint 
    581         elif dbtype == 'DATE': 
    582             return datetime.date 
    583         elif dbtype == 'TIMESTAMP': 
    584             return datetime.datetime 
    585         elif dbtype == 'TIME': 
    586             return datetime.time 
    587         for t in ('CHAR', 'VARCHAR', 'BLOB', 'TEXT', 'VARYING'): 
    588             if dbtype.startswith(t): 
    589                 return str 
    590         for t in ('NCHAR', 'NATIONAL'): 
    591             if dbtype.startswith(t): 
    592                 return unicode 
    593          
    594         raise TypeError("Database type %r could not be converted " 
    595                         "to a Python type." % dbtype) 
    596576     
    597577    #                               Naming                               # 
  • trunk/geniusql/providers/mysql.py

    r17 r18  
    8888    numeric_max_precision = 16 
    8989    numeric_max_bytes = 8 
     90     
     91    _reverse_types = adapters.TypeAdapter._reverse_types.copy() 
     92    _reverse_types.update({ 
     93        'TINYINT': int, 
     94        'MEDIUMINT': int, 
     95         
     96        'BINARY': str, 
     97        'VARBINARY': str, 
     98        'TINYBLOB': str, 
     99        'TINYTEXT': str, 
     100        'MEDIUMBLOB': str, 
     101        'MEDIUMTEXT': str, 
     102        'LONGBLOB': str, 
     103        'LONGTEXT': str, 
     104        }) 
    90105     
    91106    def float_type(self, precision): 
     
    126141            return "MEDIUMINT" 
    127142        return "INTEGER" 
     143     
     144    def related(self, pytype1, pytype2): 
     145        if pytype1 is float and pytype2 is float: 
     146            # MySQL provides no reliable method to compare floats in SQL. 
     147            # Setting this to False will set col.imperfect_type to True, 
     148            # which will tell the SQL decompiler to mark float comparisons 
     149            # as imperfect. 
     150            return False 
     151        return adapters.TypeAdapter.related(self, pytype1, pytype2) 
    128152 
    129153 
     
    325349             
    326350            key = (row[3] == "PRI") 
    327             pytype = self.db.python_type(dbtype) 
     351            pytype = self.db.typeadapter.python_type(dbtype) 
    328352             
    329353            col = geniusql.Column(pytype, dbtype, None, hints, key, 
     
    419443        return "MySQL Version: %s" % self._version 
    420444     
    421     def python_type(self, dbtype): 
    422         """Return a Python type which can store values of the given dbtype.""" 
    423         dbtype = dbtype.upper() 
    424         parenpos = dbtype.find("(") 
    425         if parenpos > -1: 
    426             dbtype = dbtype[:parenpos] 
    427          
    428         if dbtype in ('TINYINT', 'SMALLINT', 'MEDIUMINT', 'INT', 'INTEGER'): 
    429             return int 
    430         elif dbtype == 'BIGINT': 
    431             return long 
    432         elif dbtype in ('BOOL', 'BOOLEAN'): 
    433             return bool 
    434         elif dbtype in ('FLOAT', 'DOUBLE', 'DOUBLE PRECISION', 'REAL'): 
    435             return float 
    436         elif dbtype in ('DECIMAL', 'NUMERIC'): 
    437             if typerefs.decimal: 
    438                 return typerefs.decimal.Decimal 
    439             elif typerefs.fixedpoint: 
    440                 return typerefs.fixedpoint.Fixedpoint 
    441         elif dbtype == 'DATE': 
    442             return datetime.date 
    443         elif dbtype in ('DATETIME', 'TIMESTAMP'): 
    444             return datetime.datetime 
    445         elif dbtype == 'TIME': 
    446             return datetime.time 
    447         elif dbtype in ('CHAR', 'VARCHAR', 'BINARY', 'VARBINARY', 
    448                         'TINYBLOB', 'TINYTEXT', 'BLOB', 'TEXT', 
    449                         'MEDIUMBLOB', 'MEDIUMTEXT', 'LONGBLOB', 'LONGTEXT'): 
    450             return str 
    451          
    452         raise TypeError("Database type %r could not be converted " 
    453                         "to a Python type." % dbtype) 
    454      
    455     def isrelatedtype(self, pytype1, pytype2): 
    456         if pytype1 is float and pytype2 is float: 
    457             # MySQL provides no reliable method to compare floats in SQL. 
    458             # Setting this to False will set col.imperfect_type to True, 
    459             # which will tell the SQL decompiler to mark float comparisons 
    460             # as imperfect. 
    461             return False 
    462         return geniusql.Database.isrelatedtype(self, pytype1, pytype2) 
    463      
    464445    def quote(self, name): 
    465446        """Return name, quoted for use in an SQL statement.""" 
  • trunk/geniusql/providers/postgres.py

    r17 r18  
    178178        data, _ = self.db.fetch(sql, conn=conn) 
    179179        cols = [] 
     180        pytype = self.db.typeadapter.python_type 
    180181        for row in data: 
    181182            name = row[0] 
     
    192193            else: 
    193194                dbtype = None 
    194             c = geniusql.Column(self.db.python_type(dbtype), dbtype, 
     195            c = geniusql.Column(pytype(dbtype), dbtype, 
    195196                                None, {}, row[2] in indices, 
    196197                                row[0], self.db.quote(row[0])) 
     
    219220                    # our guessed type. Be sure to strip any ::typename 
    220221                    default = default.split("::", 1)[0] 
    221                     c.default = self.db.python_type(dbtype)(default) 
     222                    c.default = pytype(dbtype)(default) 
    222223            else: 
    223224                c.default = None 
     
    315316 
    316317 
     318class PgTypeAdapter(adapters.TypeAdapter): 
     319     
     320    _reverse_types = adapters.TypeAdapter._reverse_types.copy() 
     321    _reverse_types.update({ 
     322        "TIMESTAMPTZ": datetime.datetime, 
     323        "TIMETZ": datetime.time, 
     324        "INT2": int, 
     325        "INT4": int, 
     326        "INT8": long, 
     327        "FLOAT4": float, 
     328        "FLOAT8": float, 
     329        "MONEY": float, 
     330        "BYTEA": str, 
     331        "BPCHAR": str, 
     332        }) 
     333 
    317334class PgDatabase(geniusql.Database): 
    318335     
     
    324341    adaptertosql = AdapterToPgSQL() 
    325342    adapterfromdb = AdapterFromPg() 
     343    typeadapter = PgTypeAdapter() 
    326344     
    327345    decompiler = PgDecompiler 
    328346    schemaclass = PgSchema 
    329      
    330     def __init__(self, **kwargs): 
    331         geniusql.Database.__init__(self, **kwargs) 
    332      
    333     def python_type(self, dbtype): 
    334         """Return a Python type which can store values of the given dbtype.""" 
    335         dbtype = dbtype.upper() 
    336         if dbtype in ('INT2', 'INT4', 'INTEGER', 'SMALLINT'): 
    337             return int 
    338         elif dbtype in ('BOOL', 'BOOLEAN'): 
    339             return bool 
    340         elif dbtype in ('INT8', 'BIGINT'): 
    341             return long 
    342         elif dbtype in ('FLOAT4', 'FLOAT8', 'MONEY', 'DOUBLE PRECISION', 'REAL'): 
    343             return float 
    344         elif dbtype.startswith('NUMERIC'): 
    345             if typerefs.decimal: 
    346                 return typerefs.decimal.Decimal 
    347             elif typerefs.fixedpoint: 
    348                 return typerefs.fixedpoint.FixedPoint 
    349         elif dbtype == 'DATE': 
    350             return datetime.date 
    351         elif dbtype in ('TIMESTAMP', 'TIMESTAMPTZ'): 
    352             return datetime.datetime 
    353         elif dbtype in ('TIME', 'TIMETZ'): 
    354             return datetime.time 
    355         elif dbtype in ('BYTEA'): 
    356             return str 
    357         for t in ('CHAR', 'VARCHAR', 'BPCHAR', 'TEXT'): 
    358             if dbtype.startswith(t): 
    359                 return str 
    360          
    361         raise TypeError("Database type %r could not be converted " 
    362                         "to a Python type." % dbtype) 
    363347     
    364348    def quote(self, name): 
  • trunk/geniusql/providers/sqlite.py

    r17 r18  
    5757            return '1' 
    5858        return '0' 
    59  
    60  
    61 class AdapterToSQLiteTypeless(AdapterToSQLite): 
    62      
    63     def cast_any_to_object(self, colref): 
    64         return colref 
    6559 
    6660 
     
    238232    numeric_max_bytes = 0 
    239233     
     234    _reverse_types = adapters.TypeAdapter._reverse_types.copy() 
     235    _reverse_types.update({ 
     236        "NONE": unicode, 
     237        }) 
     238     
     239    def python_type(self, dbtype): 
     240        """Return a Python type which can store values of the given dbtype.""" 
     241        # Strip any size argument (e.g. "VARCHAR(255)"). 
     242        key = dbtype.upper().split("(", 1)[0] 
     243        try: 
     244            return self._reverse_types[key] 
     245        except KeyError: 
     246            return str 
     247     
    240248    def coerce_decimal_Decimal(self, col): 
    241249        return "TEXT" 
     
    265273        """Return a datatype which can handle the given number of bytes.""" 
    266274        return "INTEGER" 
    267  
    268  
    269 class TypeAdapterSQLiteTypeless(adapters.TypeAdapter): 
    270      
    271     def coerce(self, col, pytype): 
    272         # SQLite can be 'typeless' (but we lose the type introspection) 
    273         # This will be returned inside _get_columns as NUMERIC. 
    274         return "" 
     275     
     276    perfect_dates = False 
     277     
     278    def related(self, pytype1, pytype2): 
     279        if (self.perfect_dates and 
     280            issubclass(pytype1, (datetime.date, datetime.time, datetime.datetime)) and 
     281            issubclass(pytype2, self.python_type(self.coerce(None, pytype1)))): 
     282            return True 
     283        return adapters.TypeAdapter.related(self, pytype1, pytype2) 
    275284 
    276285 
     
    763772        kwargs['mode'] = int(kwargs.pop('mode', '0755'), 8) 
    764773        geniusql.Database.__init__(self, **kwargs) 
    765      
    766     def isrelatedtype(self, pytype1, pytype2): 
    767         if (self.adaptertosql.perfect_dates and 
    768             issubclass(pytype1, (datetime.date, datetime.time, datetime.datetime)) and 
    769             issubclass(pytype2, self.python_type(self.typeadapter.coerce(None, pytype1)))): 
    770             return True 
    771         return geniusql.Database.isrelatedtype(self, pytype1, pytype2) 
    772      
    773     def python_type(self, dbtype): 
    774         """Return a Python type which can store values of the given dbtype.""" 
    775         if isinstance(self.typeadapter, TypeAdapterSQLiteTypeless): 
    776             return str 
    777          
    778         if dbtype == "REAL": 
    779             return float 
    780         elif dbtype == "NUMERIC": 
    781             if typerefs.decimal: 
    782                 return typerefs.decimal.Decimal 
    783             elif typerefs.fixedpoint: 
    784                 return typerefs.fixedpoint.FixedPoint 
    785         elif dbtype.startswith("INTEGER"): 
    786             return int 
    787         elif dbtype == "NONE": 
    788             return unicode 
    789          
    790         return str 
    791774     
    792775    def quote(self, name): 
  • trunk/geniusql/test/test_sqlite.py

    r17 r18  
    3333        print "Testing SQLite with 'Perfect Dates'" 
    3434        opts['adaptertosql.perfect_dates'] = True 
     35        opts['typeadapter.perfect_dates'] = True 
    3536        reload(zoo_fixture) 
    3637        zoo_fixture.run(DB_class, dbpath, opts) 
    3738        opts['adaptertosql.perfect_dates'] = False 
     39        opts['typeadapter.perfect_dates'] = False 
    3840         
    3941        print 
     
    4143        reload(zoo_fixture) 
    4244        zoo_fixture.run(DB_class, ':memory:', opts) 
    43          
    44         print 
    45         print "Testing SQLite 'typeless'..." 
    46         from geniusql.providers import sqlite 
    47         opts['typeadapter'] = sqlite.TypeAdapterSQLiteTypeless() 
    48         reload(zoo_fixture) 
    49         zoo_fixture.run(DB_class, dbpath, opts) 
    5045 
    5146if __name__ == "__main__":