Contact: fumanchu@aminus.org

Log in as guest/geniusql to create tickets

Changeset 65

Show
Ignore:
Timestamp:
04/09/07 18:06:49
Author:
fumanchu
Message:

Moved adapters.AdapterSet? to dbtypes.DatabaseTypeSet?.

Files:

Legend:

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

    r64 r65  
    3636    import pickle 
    3737 
    38 try: 
    39     set 
    40 except NameError: 
    41     from sets import Set as set 
     38from geniusql import typerefs 
     39 
    4240 
    4341import sys 
     
    5755del L, sys 
    5856 
    59 import warnings 
    60  
    61 from geniusql import errors, typerefs 
    62  
    63  
    64 # ----------------------------- Adapter Sets ----------------------------- # 
    65  
    66  
    67 def getCoerceName(pytype): 
    68     """Return the name of the coercion method for a given Python type.""" 
    69     mod = pytype.__module__ 
    70     if mod == "__builtin__": 
    71         xform = "%s" % pytype.__name__ 
    72     else: 
    73         xform = "%s_%s" % (mod, pytype.__name__) 
    74     xform = xform.replace(".", "_") 
    75     return xform 
    76  
    77  
    78 class AdapterSet(object): 
    79     """Determine the best database type for a given column + Python type. 
    80      
    81     When Geniusql is asked to create database tables, it must choose an 
    82     appropriate column data type for each UnitProperty based on the 
    83     type (and hints) of that property. This class recommends such 
    84     database types by returning a new instance of DatabaseType. 
    85     """ 
    86      
    87     known_types = None 
    88      
    89     # You should REALLY check into your DB's encoding and override this. 
    90     encoding = 'utf8' 
    91      
    92     def __copy__(self): 
    93         newset = self.__class__() 
    94         newset.update(self) 
    95         newset.known_types = self.known_types.copy() 
    96         return newset 
    97     copy = __copy__ 
    98      
    99     def canonicalize(self, dbtypename): 
    100         """Return the canonical DatabaseType for the given synonym. 
    101          
    102         In order to avoid large amounts of code (in each provider module!) 
    103         that merely looks up synonyms, database types MUST be 
    104         canonicalized for all Column and SQLExpression objects. 
    105         """ 
    106         for typeset in self.known_types.itervalues(): 
    107             for dbtype in typeset: 
    108                 if (dbtypename == dbtype.__name__ 
    109                     or dbtypename in dbtype.synonyms): 
    110                     return dbtype 
    111         raise KeyError("No canonical name found for %r." % dbtypename) 
    112      
    113     def default(self, pytype, dbtype=None): 
    114         """Return a default adapter instance for the given pytype, dbtype.""" 
    115         if dbtype is None: 
    116             dbtype = self.database_type(pytype) 
    117          
    118         ptypes = [pytype, None] 
    119         for base in pytype.__bases__: 
    120             ptypes.append(base) 
    121          
    122         for p in ptypes: 
    123             if p in dbtype.default_adapters: 
    124                 return dbtype.default_adapters[p] 
    125          
    126         raise TypeError("%s has no default adapter for %s. Looked for: %s" % 
    127                         (dbtype, pytype, "\n".join([repr(x) for x in ptypes]))) 
    128      
    129      
    130     # ------------------------- Database types ------------------------- # 
    131      
    132     def database_type(self, pytype, hints=None): 
    133         """Return a DatabaseType instance for the given Python type. 
    134          
    135         hints: if provided, this should be a dict of property attributes 
    136             which can be used to distinguish between similar database types. 
    137             Canonical keys include 'bytes', 'precision', and 'scale'. 
    138         """ 
    139         xform = "dbtype_for_" + getCoerceName(pytype) 
    140         try: 
    141             xform = getattr(self, xform) 
    142         except AttributeError: 
    143             raise TypeError("%r is not handled by %s. Tried %r" % 
    144                             (pytype, self.__class__, xform)) 
    145         if hints is None: 
    146             hints = {} 
    147         return xform(hints) 
    148      
    149     def dbtype_for_float(self, hints): 
    150         """Return a DatabaseType for floats of the given binary precision.""" 
    151         # Note that 'precision' is binary digits, not decimal. 
    152         precision = int(hints.get('precision', maxfloat_digits)) 
    153         if precision == 0: 
    154             # Use the maximum precision. 
    155             precision = max([0] + [dbtype.max_precision 
    156                                    for dbtype in self.known_types['float']]) 
    157         for dbtype in self.known_types['float']: 
    158             if precision <= dbtype.max_precision: 
    159                 return dbtype(precision=precision) 
    160         return self.decimal_type(precision=precision) 
    161      
    162     def dbtype_for_str(self, hints): 
    163         # The bytes hint shall not reflect the usual 4-byte base for varchar. 
    164         bytes = int(hints.get('bytes', 255)) 
    165         if bytes == 0: 
    166             # Use the maximum bytes. 
    167             bytes = max([0] + [dbtype.max_bytes 
    168                                for dbtype in self.known_types['varchar']]) 
    169         for dbtype in self.known_types['varchar']: 
    170             if bytes <= dbtype.max_bytes: 
    171                 return dbtype(bytes=bytes) 
    172         raise ValueError("%r is greater than the maximum bytes %r." 
    173                          % (bytes, dbtype.max_bytes)) 
    174      
    175     def dbtype_for_dict(self, hints): 
    176         return self.dbtype_for_str(hints) 
    177     def dbtype_for_list(self, hints): 
    178         return self.dbtype_for_str(hints) 
    179     def dbtype_for_tuple(self, hints): 
    180         return self.dbtype_for_str(hints) 
    181     def dbtype_for_unicode(self, hints): 
    182         return self.dbtype_for_str(hints) 
    183      
    184     def dbtype_for_geniusql_logic_Expression(self, hints): 
    185         return self.dbtype_for_str(hints) 
    186      
    187     def dbtype_for_bool(self, hints): 
    188         return self.known_types['bool'][0]() 
    189      
    190     def dbtype_for_datetime_datetime(self, hints): 
    191         return self.known_types['datetime'][0]() 
    192      
    193     def dbtype_for_datetime_date(self, hints): 
    194         return self.known_types['date'][0]() 
    195      
    196     def dbtype_for_datetime_time(self, hints): 
    197         return self.known_types['time'][0]() 
    198      
    199     def dbtype_for_datetime_timedelta(self, hints): 
    200         try: 
    201             # If your DB has an INTERVAL datatype, you should provide a 
    202             # native INTERVAL type. You'll also have to update the date 
    203             # arithmetic inside the decompiler and add a timedelta adapter. 
    204             return self.known_types['timedelta'][0]() 
    205         except (KeyError, IndexError): 
    206             # Fallback for DB's which do not have an INTERVAL data type. 
    207             # Use decimal instead of float to avoid rounding errors. 
    208             # Using precision of 12 should allow +/- 31688 years. 
    209             return self.decimal_type(12, 0) 
    210      
    211     def numeric_max_precision(self): 
    212         return max([0] + [t.max_precision for t in self.known_types['numeric']]) 
    213      
    214     def decimal_type(self, precision, scale): 
    215         if scale > precision: 
    216             scale = precision 
    217          
    218         for dbtype in self.known_types['numeric']: 
    219             if precision <= dbtype.max_precision: 
    220                 return dbtype(precision=precision, scale=scale) 
    221          
    222         # Use a VARCHAR type (add 1 char for the decimal point and 1 for sign). 
    223         bytes = precision + 1 
    224         if scale: 
    225             bytes += 1 
    226         dbtype = self.dbtype_for_str({'bytes': bytes}) 
    227          
    228         errors.warn("The given precision (%s) is greater than the " 
    229                     "maximum numeric precision (%s). Using %s instead." 
    230                     % (precision, self.numeric_max_precision(), dbtype)) 
    231         return dbtype 
    232      
    233     if typerefs.decimal: 
    234         if hasattr(typerefs.decimal, "Decimal"): 
    235             def dbtype_for_decimal_Decimal(self, hints): 
    236                 precision = int(hints.get('precision', 0)) 
    237                 if precision == 0: 
    238                     precision = self.numeric_max_precision() 
    239                 # Assume most people use decimal for money; default scale = 2. 
    240                 scale = int(hints.get('scale', 2)) 
    241                 return self.decimal_type(precision, scale) 
    242         else: 
    243             def dbtype_for_decimal(self, hints): 
    244                 precision = int(hints.get('precision', 0)) 
    245                 if precision == 0: 
    246                     precision = self.numeric_max_precision() 
    247                 # Assume most people use decimal for money; default scale = 2. 
    248                 scale = int(hints.get('scale', 2)) 
    249                 return self.decimal_type(precision, scale) 
    250      
    251     if typerefs.fixedpoint: 
    252         def dbtype_for_fixedpoint_FixedPoint(self, hints): 
    253             # Note that fixedpoint has no theoretical precision limit. 
    254             precision = int(hints.get('precision', 0)) 
    255             if precision == 0: 
    256                 precision = self.numeric_max_precision() 
    257             # Assume most people use fixedpoint for money; default scale = 2. 
    258             scale = int(hints.get('scale', 2)) 
    259             return self.decimal_type(precision, scale) 
    260      
    261     def dbtype_for_long(self, hints): 
    262         if 'bytes' in hints: 
    263             bytes = int(hints['bytes']) 
    264         else: 
    265             bytes = self.numeric_max_precision() / 2 
    266          
    267         for dbtype in self.known_types['int']: 
    268             if bytes <= dbtype.max_bytes: 
    269                 return dbtype(bytes=bytes) 
    270         return self.decimal_type(precision=bytes * 2, scale=0) 
    271      
    272     def dbtype_for_int(self, hints): 
    273         bytes = int(hints.get('bytes', maxint_bytes)) 
    274         for dbtype in self.known_types['int']: 
    275             if bytes <= dbtype.max_bytes: 
    276                 return dbtype(bytes=bytes) 
    277         return self.decimal_type(precision=bytes * 2, scale=0) 
    27857 
    27958 
  • trunk/geniusql/dbtypes.py

    r64 r65  
    44import datetime 
    55 
    6 from geniusql import adapters, typerefs 
     6from geniusql import adapters, errors, typerefs 
    77 
    88 
     
    2828    synonyms = [] 
    2929     
    30     # Given the wide variety of type systems in commercial databases, 
    31     # it seemed best to just overlay them all with a nominative system. 
    32     implicit_conversions = [] 
    33      
    3430    def __init__(self, **kwargs): 
    3531        for k, v in kwargs.iteritems(): 
     
    4945        """Return the type for use in CREATE or ALTER statements.""" 
    5046        return self.__class__.__name__ 
     47     
     48    def default_adapter(self, pytype): 
     49        """Return a default adapter instance for the given pytype, dbtype.""" 
     50        ptypes = [pytype, None] 
     51        for base in pytype.__bases__: 
     52            ptypes.append(base) 
     53         
     54        for p in ptypes: 
     55            if p in self.default_adapters: 
     56                return self.default_adapters[p] 
     57         
     58        raise TypeError("%s has no default adapter for %s. Looked for: %s" % 
     59                        (self, pytype, "\n".join([repr(x) for x in ptypes]))) 
    5160 
    5261 
     
    120129    _initargs = DatabaseType._initargs + ("precision", "max_precision") 
    121130     
    122     # Max binary precision for floating-point columns (= 53 for PostgreSQL 8). 
    123     # Python floats are implemented using C doubles; actual precision depends 
    124     # on platform (but is usually 53 binary digits, see adapters.maxfloat_digits). 
    125     # PostgreSQL DOUBLE is 53 binary-digit precision. 
     131    # Max binary precision for floating-point columns. Python floats are 
     132    # implemented using C doubles; actual precision depends on platform 
     133    # (but is usually 53 binary digits, see adapters.maxfloat_digits). 
     134    # Many commercial DB's DOUBLE is 53 binary-digit precision. 
    126135    max_precision = 53 
    127136     
     
    411420    default_adapters = {bool: adapters.bool_to_SQL99BOOLEAN()} 
    412421 
     422 
     423 
     424# ----------------------------- Type Sets ----------------------------- # 
     425 
     426 
     427def getCoerceName(pytype): 
     428    """Return the name of the coercion method for a given Python type.""" 
     429    mod = pytype.__module__ 
     430    if mod == "__builtin__": 
     431        xform = "%s" % pytype.__name__ 
     432    else: 
     433        xform = "%s_%s" % (mod, pytype.__name__) 
     434    xform = xform.replace(".", "_") 
     435    return xform 
     436 
     437 
     438class DatabaseTypeSet(object): 
     439    """Determine the best database type for a given column + Python type. 
     440     
     441    When Geniusql is asked to create database tables, it must choose an 
     442    appropriate column data type for each UnitProperty based on the 
     443    type (and hints) of that property. This class recommends such 
     444    database types by returning a new instance of DatabaseType. 
     445    """ 
     446     
     447    known_types = None 
     448     
     449    # You should REALLY check into your DB's encoding and override this. 
     450    encoding = 'utf8' 
     451     
     452    def __copy__(self): 
     453        newset = self.__class__() 
     454        newset.update(self) 
     455        newset.known_types = self.known_types.copy() 
     456        return newset 
     457    copy = __copy__ 
     458     
     459    def canonicalize(self, dbtypename): 
     460        """Return the canonical DatabaseType for the given synonym. 
     461         
     462        In order to avoid large amounts of code (in each provider module!) 
     463        that merely looks up synonyms, database types MUST be 
     464        canonicalized for all Column and SQLExpression objects. 
     465        """ 
     466        for typeset in self.known_types.itervalues(): 
     467            for dbtype in typeset: 
     468                if (dbtypename == dbtype.__name__ 
     469                    or dbtypename in dbtype.synonyms): 
     470                    return dbtype 
     471        raise KeyError("No canonical name found for %r." % dbtypename) 
     472     
     473    def database_type(self, pytype, hints=None): 
     474        """Return a DatabaseType instance for the given Python type. 
     475         
     476        hints: if provided, this should be a dict of property attributes 
     477            which can be used to distinguish between similar database types. 
     478            Canonical keys include 'bytes', 'precision', and 'scale'. 
     479        """ 
     480        xform = "dbtype_for_" + getCoerceName(pytype) 
     481        try: 
     482            xform = getattr(self, xform) 
     483        except AttributeError: 
     484            raise TypeError("%r is not handled by %s. Tried %r" % 
     485                            (pytype, self.__class__, xform)) 
     486        if hints is None: 
     487            hints = {} 
     488        return xform(hints) 
     489     
     490    def dbtype_for_float(self, hints): 
     491        """Return a DatabaseType for floats of the given binary precision.""" 
     492        # Note that 'precision' is binary digits, not decimal. 
     493        precision = int(hints.get('precision', adapters.maxfloat_digits)) 
     494        if precision == 0: 
     495            # Use the maximum precision. 
     496            precision = max([0] + [dbtype.max_precision 
     497                                   for dbtype in self.known_types['float']]) 
     498        for dbtype in self.known_types['float']: 
     499            if precision <= dbtype.max_precision: 
     500                return dbtype(precision=precision) 
     501        return self.decimal_type(precision=precision) 
     502     
     503    def dbtype_for_str(self, hints): 
     504        # The bytes hint shall not reflect the usual 4-byte base for varchar. 
     505        bytes = int(hints.get('bytes', 255)) 
     506        if bytes == 0: 
     507            # Use the maximum bytes. 
     508            bytes = max([0] + [dbtype.max_bytes 
     509                               for dbtype in self.known_types['varchar']]) 
     510        for dbtype in self.known_types['varchar']: 
     511            if bytes <= dbtype.max_bytes: 
     512                return dbtype(bytes=bytes) 
     513        raise ValueError("%r is greater than the maximum bytes %r." 
     514                         % (bytes, dbtype.max_bytes)) 
     515     
     516    def dbtype_for_dict(self, hints): 
     517        return self.dbtype_for_str(hints) 
     518    def dbtype_for_list(self, hints): 
     519        return self.dbtype_for_str(hints) 
     520    def dbtype_for_tuple(self, hints): 
     521        return self.dbtype_for_str(hints) 
     522    def dbtype_for_unicode(self, hints): 
     523        return self.dbtype_for_str(hints) 
     524     
     525    def dbtype_for_geniusql_logic_Expression(self, hints): 
     526        return self.dbtype_for_str(hints) 
     527     
     528    def dbtype_for_bool(self, hints): 
     529        return self.known_types['bool'][0]() 
     530     
     531    def dbtype_for_datetime_datetime(self, hints): 
     532        return self.known_types['datetime'][0]() 
     533     
     534    def dbtype_for_datetime_date(self, hints): 
     535        return self.known_types['date'][0]() 
     536     
     537    def dbtype_for_datetime_time(self, hints): 
     538        return self.known_types['time'][0]() 
     539     
     540    def dbtype_for_datetime_timedelta(self, hints): 
     541        try: 
     542            # If your DB has an INTERVAL datatype, you should provide a 
     543            # native INTERVAL type. You'll also have to update the date 
     544            # arithmetic inside the decompiler and add a timedelta adapter. 
     545            return self.known_types['timedelta'][0]() 
     546        except (KeyError, IndexError): 
     547            # Fallback for DB's which do not have an INTERVAL data type. 
     548            # Use decimal instead of float to avoid rounding errors. 
     549            # Using precision of 12 should allow +/- 31688 years. 
     550            return self.decimal_type(12, 0) 
     551     
     552    def numeric_max_precision(self): 
     553        return max([0] + [t.max_precision for t in self.known_types['numeric']]) 
     554     
     555    def decimal_type(self, precision, scale): 
     556        if scale > precision: 
     557            scale = precision 
     558         
     559        for dbtype in self.known_types['numeric']: 
     560            if precision <= dbtype.max_precision: 
     561                return dbtype(precision=precision, scale=scale) 
     562         
     563        # Use a VARCHAR type (add 1 char for the decimal point and 1 for sign). 
     564        bytes = precision + 1 
     565        if scale: 
     566            bytes += 1 
     567        dbtype = self.dbtype_for_str({'bytes': bytes}) 
     568         
     569        errors.warn("The given precision (%s) is greater than the " 
     570                    "maximum numeric precision (%s). Using %s instead." 
     571                    % (precision, self.numeric_max_precision(), dbtype)) 
     572        return dbtype 
     573     
     574    if typerefs.decimal: 
     575        if hasattr(typerefs.decimal, "Decimal"): 
     576            def dbtype_for_decimal_Decimal(self, hints): 
     577                precision = int(hints.get('precision', 0)) 
     578                if precision == 0: 
     579                    precision = self.numeric_max_precision() 
     580                # Assume most people use decimal for money; default scale = 2. 
     581                scale = int(hints.get('scale', 2)) 
     582                return self.decimal_type(precision, scale) 
     583        else: 
     584            def dbtype_for_decimal(self, hints): 
     585                precision = int(hints.get('precision', 0)) 
     586                if precision == 0: 
     587                    precision = self.numeric_max_precision() 
     588                # Assume most people use decimal for money; default scale = 2. 
     589                scale = int(hints.get('scale', 2)) 
     590                return self.decimal_type(precision, scale) 
     591     
     592    if typerefs.fixedpoint: 
     593        def dbtype_for_fixedpoint_FixedPoint(self, hints): 
     594            # Note that fixedpoint has no theoretical precision limit. 
     595            precision = int(hints.get('precision', 0)) 
     596            if precision == 0: 
     597                precision = self.numeric_max_precision() 
     598            # Assume most people use fixedpoint for money; default scale = 2. 
     599            scale = int(hints.get('scale', 2)) 
     600            return self.decimal_type(precision, scale) 
     601     
     602    def dbtype_for_long(self, hints): 
     603        if 'bytes' in hints: 
     604            bytes = int(hints['bytes']) 
     605        else: 
     606            bytes = self.numeric_max_precision() / 2 
     607         
     608        for dbtype in self.known_types['int']: 
     609            if bytes <= dbtype.max_bytes: 
     610                return dbtype(bytes=bytes) 
     611        return self.decimal_type(precision=bytes * 2, scale=0) 
     612     
     613    def dbtype_for_int(self, hints): 
     614        bytes = int(hints.get('bytes', adapters.maxint_bytes)) 
     615        for dbtype in self.known_types['int']: 
     616            if bytes <= dbtype.max_bytes: 
     617                return dbtype(bytes=bytes) 
     618        return self.decimal_type(precision=bytes * 2, scale=0) 
     619 
  • trunk/geniusql/decompile.py

    r64 r65  
    109109    bool_false = "FALSE" 
    110110     
    111     def __init__(self, tables, expr, adapterset): 
     111    def __init__(self, tables, expr, typeset): 
    112112        self.tables = tables 
    113113        self.expr = expr 
    114         self.adapterset = adapterset 
     114        self.typeset = typeset 
    115115         
    116116        self.groups = [] 
     
    120120        self.false_expr = self.const(False, self.bool_false) 
    121121         
    122         booldbtype = self.adapterset.database_type(bool) 
    123         booladapter = self.adapterset.default(bool, booldbtype
     122        booldbtype = self.typeset.database_type(bool) 
     123        booladapter = booldbtype.default_adapter(bool
    124124        self.T = self.const(True, booladapter.push(True, booldbtype)) 
    125125        self.F = self.const(False, booladapter.push(False, booldbtype)) 
     
    136136        name = "expr%s" % self.exprcount 
    137137         
    138         dbtype = self.adapterset.database_type(pytype) 
     138        dbtype = self.typeset.database_type(pytype) 
    139139        e = SQLExpression(sql, name, dbtype, pytype) 
    140         e.adapter = adapter or self.adapterset.default(pytype, dbtype) 
     140        e.adapter = adapter or dbtype.default_adapter(pytype) 
    141141         
    142142        return e 
     
    429429            atoms = [] 
    430430            for x in op2.value: 
    431                 adapter = self.adapterset.default(type(x), op1.dbtype
     431                adapter = op1.dbtype.default_adapter(type(x)
    432432                atoms.append(adapter.push(x, op1.dbtype)) 
    433433            if atoms: 
     
    448448            atoms = [] 
    449449            for x in op2.value: 
    450                 adapter = self.adapterset.default(type(x), op1.dbtype
     450                adapter = op1.dbtype.default_adapter(type(x)
    451451                atoms.append(adapter.push(x.lower(), op1.dbtype)) 
    452452            return self.get_expr("LOWER(%s) IN (%s)" % 
     
    531531        if newpytype != op1.pytype: 
    532532            op1.pytype = newpytype 
    533             op1.dbtype = self.adapterset.database_type(newpytype) 
    534             op1.adapter = self.adapterset.default(newpytype, op1.dbtype) 
     533            op1.dbtype = self.typeset.database_type(newpytype) 
     534            op1.adapter = op1.dbtype.default_adapter(newpytype) 
    535535        if not op1.name.startswith("expr_"): 
    536536            op1.name = "expr_%s" % op1.name 
  • trunk/geniusql/objects.py

    r64 r65  
    1919import geniusql 
    2020from geniusql import errors, typerefs 
    21 from geniusql import adapter
     21from geniusql import dbtype
    2222from geniusql import conns 
    2323from geniusql import decompile 
     
    331331        tpair = [(self.qname, self)] 
    332332        decom = self.schema.db.decompiler(tpair, logic.filter(**inputs), 
    333                                           self.schema.db.adapterset) 
     333                                          self.schema.db.typeset) 
    334334##        decom.verbose = True 
    335335        code = decom.code() 
     
    626626        col.autoincrement = autoincrement 
    627627         
    628         typer = self.db.adapterset 
     628        typer = self.db.typeset 
    629629        if col.dbtype is None: 
    630630            col.dbtype = typer.database_type(pytype, hints or {}) 
    631         col.adapter = typer.default(pytype, col.dbtype) 
     631        col.adapter = col.dbtype.default_adapter(pytype) 
    632632         
    633633        return col 
     
    754754    __metaclass__ = geniusql._AttributeDocstrings 
    755755     
    756     adapterset = adapters.AdapterSet() 
     756    typeset = dbtypes.DatabaseTypeSet() 
    757757    decompiler = decompile.SQLDecompiler 
    758758    joinwrapper = select.TableWrapper 
     
    842842            conn = self.connections.get() 
    843843        if isinstance(query, unicode): 
    844             query = query.encode(self.adapterset.encoding) 
     844            query = query.encode(self.typeset.encoding) 
    845845        self.log(query) 
    846846        return conn.query(query) 
  • trunk/geniusql/providers/ado.py

    r64 r65  
    256256            atoms = [] 
    257257            for x in op2.value: 
    258                 adapter = self.adapterset.default(type(x), op1.dbtype
     258                adapter = op1.dbtype.default_adapter(type(x)
    259259                atoms.append(adapter.push(x, op1.dbtype)) 
    260260            if atoms: 
     
    461461            conn = self.connections.get() 
    462462##        if isinstance(query, unicode): 
    463 ##            query = query.encode(self.adapterset.encoding) 
     463##            query = query.encode(self.typeset.encoding) 
    464464         
    465465        self.log(query) 
  • trunk/geniusql/providers/msaccess.py

    r64 r65  
    324324 
    325325 
    326 class MSAccessAdapterSet(adapters.AdapterSet): 
     326class MSAccessTypeSet(dbtypes.DatabaseTypeSet): 
    327327     
    328328    known_types = {'float': [REAL, FLOAT], 
     
    484484         
    485485        cols = [] 
    486         typer = self.db.adapterset 
     486        typer = self.db.typeset 
    487487        for row in data: 
    488488            # I tried passing criteria to OpenSchema, but passing None is 
     
    532532                    dbtype.bytes = (2 ** 31) - 1 
    533533             
    534             c.adapter = typer.default(pytype, dbtype) 
     534            c.adapter = dbtype.default_adapter(pytype) 
    535535            cols.append(c) 
    536536         
     
    645645     
    646646    decompiler = MSAccessDecompiler 
    647     adapterset = MSAccessAdapterSet() 
     647    typeset = MSAccessTypeSet() 
    648648    connectionmanager = MSAccessConnectionManager 
    649649    schemaclass = MSAccessSchema 
  • trunk/geniusql/providers/postgres.py

    r64 r65  
    353353 
    354354 
    355 class PgAdapterSet(adapters.AdapterSet): 
     355class PgTypeSet(dbtypes.DatabaseTypeSet): 
    356356     
    357357    known_types = {'float': [FLOAT4, FLOAT8], 
     
    385385            atoms = [] 
    386386            for x in op2.value: 
    387                 adapter = self.adapterset.default(type(x), op1.dbtype
     387                adapter = op1.dbtype.default_adapter(type(x)
    388388                atoms.append(adapter.push(x.lower(), op1.dbtype)) 
    389389            return self.get_expr("LOWER(%s) IN (%s)" % 
     
    515515        data, _ = self.db.fetch(sql, conn=conn) 
    516516        cols = [] 
    517         adapterset = self.db.adapterset 
     517        typeset = self.db.typeset 
    518518        for row in data: 
    519519            name = row[0] 
     
    526526            dbtype, _ = self.db.fetch("SELECT typname, typlen FROM pg_type " 
    527527                                      "WHERE oid = %s" % row[1], conn=conn) 
    528             dbtypetype = adapterset.canonicalize(dbtype[0][0].upper()) 
     528            dbtypetype = typeset.canonicalize(dbtype[0][0].upper()) 
    529529            dbtype = dbtypetype() 
    530530             
     
    532532                                None, key=row[2] in indices, 
    533533                                name=row[0], qname=self.db.quote(row[0])) 
    534             c.adapter = adapterset.default(c.pytype, dbtype) 
     534            c.adapter = dbtype.default_adapter(c.pytype) 
    535535             
    536536            if dbtypetype in (FLOAT4, FLOAT8): 
     
    660660    decompiler = PgDecompiler 
    661661    schemaclass = PgSchema 
    662     adapterset = PgAdapterSet() 
     662    typeset = PgTypeSet() 
    663663     
    664664    def quote(self, name): 
  • trunk/geniusql/providers/sqlserver.py

    r64 r65  
    240240 
    241241 
    242 class SQLServerAdapterSet(adapters.AdapterSet): 
     242class SQLServerTypeSet(dbtypes.DatabaseTypeSet): 
    243243     
    244244    known_types = {'float': [REAL, FLOAT], 
     
    403403         
    404404        cols = [] 
    405         typer = self.db.adapterset 
     405        typer = self.db.typeset 
    406406        for row in data: 
    407407            # I tried passing criteria to OpenSchema, but passing None is 
     
    444444                    dbtype.bytes = b = int(row[13]) 
    445445             
    446             c.adapter = typer.default(pytype, dbtype) 
     446            c.adapter = dbtype.default_adapter(pytype) 
    447447            cols.append(c) 
    448448        return cols 
     
    487487     
    488488    decompiler = SQLServerDecompiler 
    489     adapterset = SQLServerAdapterSet() 
     489    typeset = SQLServerTypeSet() 
    490490    connectionmanager = SQLServerConnectionManager 
    491491    schemaclass = SQLServerSchema 
  • trunk/geniusql/select.py

    r64 r65  
    247247        """Return an SQL WHERE clause, and an 'imperfect' flag.""" 
    248248        tpairs = [(t.alias or t.qname, t.table) for t in self.tables] 
    249         decom = self.db.decompiler(tpairs, self.restriction, self.db.adapterset) 
     249        decom = self.db.decompiler(tpairs, self.restriction, self.db.typeset) 
    250250        code = decom.code() 
    251251        return code, decom.imperfect 
     
    343343        tpairs = [(t.alias or t.qname, t.table) for t in self.tables] 
    344344        decom = self.db.decompiler 
    345         decom = decom(tpairs, self.attributes, self.db.adapterset) 
     345        decom = decom(tpairs, self.attributes, self.db.typeset) 
    346346##        decom.verbose = True 
    347347         
  • trunk/geniusql/test/test_msaccess.py

    r64 r65  
    2626##            def test_currency_dbtypes(obj): 
    2727##                db = zoo_fixture.db 
    28 ##                fta = db.adapterset.__class__.__name__ 
     28##                fta = db.typeset.__class__.__name__ 
    2929##                schema = zoo_fixture.schema 
    3030##                 
  • trunk/geniusql/test/zoo_fixture.py

    r64 r65  
    11031103            if db: 
    11041104                import math 
    1105                 maxprec = db.adapterset.numeric_max_precision 
     1105                maxprec = db.typeset.numeric_max_precision 
    11061106                if maxprec == 0: 
    11071107                    # SQLite, for example, must always use TEXT.