Contact: fumanchu@aminus.org

Log in as guest/geniusql to create tickets

Changeset 60

Show
Ignore:
Timestamp:
04/05/07 22:19:10
Author:
fumanchu
Message:

Better class names; in general, most DatabaseTypes? are now SQL92* and adapters are now pytype_to_dbtype.

Files:

Legend:

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

    r59 r60  
    1212majority of cases, a reasonable set of default adapters can be generated 
    1313by Geniusql. For example, a Column of pytype "datetime.date" can default 
    14 to an SQL92DATE adapter (but an MSAccess_Date adapter if necessary), based 
     14to a DateAdapter (but an MSAccess_Date adapter if necessary), based 
    1515entirely on the Python type. 
    1616 
     
    355355 
    356356 
    357 class SQL99BOOLEAN(Adapter): 
     357class bool_to_SQL92BIT(Adapter): 
     358     
     359    def push(self, value, dbtype): 
     360        if value is None: 
     361            return 'NULL' 
     362        if value: 
     363            return '1' 
     364        return '0' 
     365     
     366    def pull(self, value, dbtype): 
     367        return bool(int(value)) 
     368 
     369 
     370class bool_to_SQL99BOOLEAN(Adapter): 
    358371     
    359372    def push(self, value, dbtype): 
     
    367380        return bool(value) 
    368381 
    369 # SQL92 types: INTEGER (INT), SMALLINT, NUMERIC, DECIMAL, REAL, 
    370 #   DOUBLE PRECISION (DOUBLE), BIT, BIT VARYING, DATE, TIME, TIMESTAMP, 
    371 #   CHARACTER (CHAR), CHARACTER VARYING (VARCHAR), INTERVAL 
    372  
    373 class SQL92BIT(Adapter): 
    374     def push(self, value, dbtype): 
    375         if value is None: 
    376             return 'NULL' 
    377         if value: 
    378             return '1' 
    379         return '0' 
    380      
    381     def pull(self, value, dbtype): 
    382         return bool(int(value)) 
    383  
    384382 
    385383# The great thing about these 3 date coercers is that you can use 
    386384# them with (VAR)CHAR columns just as well as with DATETIME, etc. 
    387385# and comparisons will still work! 
    388 class SQL92TIMESTAMP(Adapter): 
     386class datetime_to_SQL92TIMESTAMP(Adapter): 
    389387     
    390388    def push(self, value, dbtype): 
     
    404402 
    405403 
    406 class SQL92DATE(Adapter): 
     404class date_to_SQL92DATE(Adapter): 
    407405     
    408406    def push(self, value, dbtype): 
     
    423421 
    424422 
    425 class SQL92TIME(Adapter): 
     423class time_to_SQL92TIME(Adapter): 
    426424     
    427425    def push(self, value, dbtype): 
     
    437435 
    438436 
    439 class INTERVAL(Adapter): 
     437class timedelta_to_SQL92DECIMAL(Adapter): 
    440438    """Adapter for storing datetime.timedelta values in whole seconds. 
    441439     
    442440    SQL-92 defines an INTERVAL type, but few commercial databases 
    443441    implement it in a reasonable manner. This adapter stores the 
    444     value (days * 86400) + seconds in a NUMERIC field instead, 
     442    value (days * 86400) + seconds in a DECIMAL field instead, 
    445443    which should work with most databases. Note that a custom 
    446444    binary_op method MUST be written for each DB which subclasses 
     
    463461 
    464462 
    465 class SQL92REAL(Adapter): 
     463class float_to_SQL92REAL(Adapter): 
     464    """Adapter from Python float to SQL92-compliant REAL.""" 
     465     
    466466    def push(self, value, dbtype): 
    467467        if value is None: 
     
    473473        return float(value) 
    474474 
    475 class SQL92DOUBLE(Adapter): 
    476     def push(self, value, dbtype): 
    477         if value is None: 
    478             return 'NULL' 
    479         # Very important we use repr here so we get all 17 decimal digits. 
    480         return repr(value) 
    481      
    482     def pull(self, value, dbtype): 
    483         return float(value) 
    484  
    485 class SQL92SMALLINT(Adapter): 
     475class float_to_SQL92DOUBLE(float_to_SQL92REAL): 
     476    """Adapter from Python float to SQL92-compliant DOUBLE.""" 
     477    pass 
     478 
     479 
     480class int_to_SQL92INTEGER(Adapter): 
     481     
    486482    def push(self, value, dbtype): 
    487483        if value is None: 
     
    489485        return str(value) 
    490486     
    491     # SQL-92 SMALLINT should be 2 bytes 
     487    # SQL-92 INTEGER is usually 4 bytes 
     488    if maxint_bytes >= 4: 
     489        def pull(self, value, dbtype): 
     490            return int(value) 
     491    else: 
     492        def pull(self, value, dbtype): 
     493            return long(value) 
     494 
     495class int_to_SQL92SMALLINT(Adapter): 
     496     
     497    def push(self, value, dbtype): 
     498        if value is None: 
     499            return 'NULL' 
     500        return str(value) 
     501     
     502    # SQL-92 SMALLINT is usually 2 bytes 
    492503    if maxint_bytes >= 2: 
    493504        def pull(self, value, dbtype): 
     
    497508            return long(value) 
    498509 
    499 class SQL92INTEGER(Adapter): 
    500     def push(self, value, dbtype): 
    501         if value is None: 
    502             return 'NULL' 
    503         return str(value) 
    504      
    505     # SQL-92 INTEGER should be 4 bytes 
    506     if maxint_bytes >= 4: 
    507         def pull(self, value, dbtype): 
    508             return int(value) 
    509     else: 
    510         def pull(self, value, dbtype): 
    511             return long(value) 
    512  
    513  
    514 class SQL92VARCHAR(Adapter): 
     510 
     511 
     512class str_to_SQL92VARCHAR(Adapter): 
    515513     
    516514    # Default escapes for string values. 
     
    533531 
    534532 
    535 class UNICODE(SQL92VARCHAR): 
     533class unicode_to_SQL92VARCHAR(str_to_SQL92VARCHAR): 
    536534     
    537535    def pull(self, value, dbtype): 
     
    543541 
    544542 
    545 class Pickler(SQL92VARCHAR): 
     543class Pickler(Adapter): 
     544     
     545    # Default escapes for string values. 
     546    escapes = [("'", "''"), ("\\", r"\\")] 
    546547     
    547548    def push(self, value, dbtype): 
     
    566567 
    567568 
    568 class Numeric_to_TEXT(Adapter): 
     569class numeric_to_TEXT(Adapter): 
    569570    """Adapt a numeric Python type (int|long|float) to a TEXT dbtype.""" 
    570571     
     
    604605 
    605606 
    606 class Numeric_to_DECIMAL(Adapter): 
    607     """Adapt a numeric Python type (int|long|float) to a DECIMAL dbtype.""" 
     607class numeric_to_SQL92DECIMAL(Adapter): 
     608    """Adapt a numeric Python type (int|long|float) to SQL92DECIMAL.""" 
    608609     
    609610    def __init__(self, pytype): 
     
    623624 
    624625if typerefs.decimal: 
    625     class DECIMAL(Adapter): 
     626    class decimal_to_SQL92DECIMAL(Adapter): 
    626627        def push(self, value, dbtype): 
    627628            if value is None: 
     
    642643            return value 
    643644     
    644     class Decimal_to_TEXT(DECIMAL): 
     645    class decimal_to_TEXT(decimal_to_SQL92DECIMAL): 
    645646        def push(self, value, dbtype): 
    646647            if value is None: 
     
    659660 
    660661if typerefs.fixedpoint: 
    661     class FIXEDPOINT(Adapter): 
     662    class fixedpoint_to_SQL92DECIMAL(Adapter): 
    662663        def push(self, value, dbtype): 
    663664            if value is None: 
     
    680681            else: 
    681682                return typerefs.fixedpoint.FixedPoint(value) 
    682     class FixedPoint_to_TEXT(FIXEDPOINT): 
     683     
     684    class fixedpoint_to_TEXT(fixedpoint_to_SQL92DECIMAL): 
    683685        def push(self, value, dbtype): 
    684686            if value is None: 
  • trunk/geniusql/dbtypes.py

    r59 r60  
     1# Any otherwise-unattributed quotes in this module are probably from: 
     2# http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt 
     3 
    14import datetime 
    25 
     
    98101 
    99102 
    100 class FrozenStringType(FrozenByteType): 
    101     """DatabaseType for string types whose byte-length is not adjustable. 
    102      
    103     A FrozenStringType does not imply that the type is a fixed-byte 
    104     type like CHAR as opposed to a variable-byte type like VARCHAR 
    105     (that difference is specified in the "variable" attribute). 
    106     Instead, a Frozen* type implies that the type takes no size 
    107     argument in DDL; for example, Microsoft Access' MEMO type 
    108     is always 65535 bytes, and is not user-specifiable. 
    109     """ 
    110      
    111     _initargs = FrozenByteType._initargs + ("variable", "encoding") 
    112      
    113     # CHAR vs VARCHAR 
    114     variable = True 
    115     encoding = 'utf8' 
    116      
    117     default_pytype = str 
    118     default_adapters = {str: adapters.SQL92VARCHAR(), 
    119                         unicode: adapters.UNICODE(), 
    120                         float: adapters.Numeric_to_TEXT(float), 
    121                         int: adapters.Numeric_to_TEXT(int), 
    122                         long: adapters.Numeric_to_TEXT(long), 
    123                         datetime.timedelta: adapters.INTERVAL(), 
    124                         None: adapters.Pickler(), 
    125                         } 
    126     if typerefs.decimal: 
    127         if hasattr(typerefs.decimal, "Decimal"): 
    128             default_adapters[typerefs.decimal.Decimal] = adapters.Decimal_to_TEXT() 
    129         else: 
    130             default_adapters[typerefs.decimal] = adapters.Decimal_to_TEXT() 
    131     if typerefs.fixedpoint: 
    132         default_adapters[typerefs.fixedpoint.FixedPoint] = adapters.FixedPoint_to_TEXT() 
    133  
    134  
    135 class AdjustableStringType(AdjustableByteType): 
    136     """DatabaseType for adjustable-byte string types.""" 
    137      
    138     _initargs = AdjustableByteType._initargs + ("variable", "encoding") 
    139      
    140     # CHAR vs VARCHAR 
    141     variable = True 
    142     encoding = 'utf8' 
    143      
    144     default_pytype = str 
    145     default_adapters = {str: adapters.SQL92VARCHAR(), 
    146                         unicode: adapters.UNICODE(), 
    147                         float: adapters.Numeric_to_TEXT(float), 
    148                         int: adapters.Numeric_to_TEXT(int), 
    149                         long: adapters.Numeric_to_TEXT(long), 
    150                         datetime.timedelta: adapters.INTERVAL(), 
    151                         None: adapters.Pickler(), 
    152                         } 
    153     if typerefs.decimal: 
    154         if hasattr(typerefs.decimal, "Decimal"): 
    155             default_adapters[typerefs.decimal.Decimal] = adapters.Decimal_to_TEXT() 
    156         else: 
    157             default_adapters[typerefs.decimal] = adapters.Decimal_to_TEXT() 
    158     if typerefs.fixedpoint: 
    159         default_adapters[typerefs.fixedpoint.FixedPoint] = adapters.FixedPoint_to_TEXT() 
    160  
    161  
    162 class IntegerType(FrozenByteType): 
    163      
    164     _initargs = FrozenByteType._initargs + ("signed", ) 
    165      
    166     default_pytype = int 
    167     default_adapters = {int: adapters.SQL92INTEGER(), 
    168                         long: adapters.SQL92INTEGER(), 
    169                         } 
    170     signed = True 
    171      
    172     def range(self): 
    173         """Return self.max - self.min.""" 
    174         return 2 ** (self.bytes * 8) 
    175      
    176     def min(self): 
    177         """Return the minimum value allowed.""" 
    178         if self.signed: 
    179             return 0 - (self.range() / 2) 
    180         else: 
    181             return 0 
    182      
    183     def max(self): 
    184         """Return the maximum value allowed.""" 
    185         if self.signed: 
    186             return (self.range() / 2) - 1 
    187         else: 
    188             return self.range() - 1 
    189  
    190  
    191103class FrozenPrecisionType(DatabaseType): 
    192104    """DatabaseType which specifies a frozen 'precision' attribute.""" 
     
    234146 
    235147 
    236 class InexactNumericType(FrozenPrecisionType): 
     148class FixedRangeType(DatabaseType): 
     149    """DatabaseType which represents values within a fixed range.""" 
     150    _min = None 
     151    _max = None 
     152     
     153    _initargs = DatabaseType._initargs + ("_min", "_max") 
     154     
     155    def range(self): 
     156        """Return self.max - self.min.""" 
     157        return self._max - self._min 
     158     
     159    def min(self): 
     160        """Return the minimum value allowed.""" 
     161        return self._min 
     162     
     163    def max(self): 
     164        """Return the maximum value allowed.""" 
     165        return self._max 
     166 
     167 
     168# SQL92 types: INTEGER (INT), SMALLINT, NUMERIC, DECIMAL, FLOAT, REAL, 
     169#   DOUBLE PRECISION (DOUBLE), BIT, BIT VARYING, DATE, TIME, TIMESTAMP, 
     170#   CHARACTER (CHAR), CHARACTER VARYING (VARCHAR), INTERVAL 
     171 
     172class TEXT(FrozenByteType): 
     173    """DatabaseType for string types whose byte-length is not adjustable. 
     174     
     175    A FrozenStringType does not imply that the type is a fixed-byte 
     176    type like CHAR as opposed to a variable-byte type like VARCHAR 
     177    (that difference is specified in the "variable" attribute). 
     178    Instead, a Frozen* type implies that the type takes no size 
     179    argument in DDL; for example, Microsoft Access' MEMO type 
     180    is always 65535 bytes, and is not user-specifiable. 
     181    """ 
     182     
     183    _initargs = FrozenByteType._initargs + ("variable", "encoding") 
     184     
     185    # CHAR vs VARCHAR 
     186    variable = True 
     187    encoding = 'utf8' 
     188     
     189    default_pytype = str 
     190    default_adapters = {str: adapters.str_to_SQL92VARCHAR(), 
     191                        unicode: adapters.unicode_to_SQL92VARCHAR(), 
     192                        float: adapters.numeric_to_TEXT(float), 
     193                        int: adapters.numeric_to_TEXT(int), 
     194                        long: adapters.numeric_to_TEXT(long), 
     195                        datetime.timedelta: adapters.timedelta_to_SQL92DECIMAL(),  #?? 
     196                        None: adapters.Pickler(), 
     197                        } 
     198    if typerefs.decimal: 
     199        if hasattr(typerefs.decimal, "Decimal"): 
     200            default_adapters[typerefs.decimal.Decimal] = adapters.decimal_to_TEXT() 
     201        else: 
     202            default_adapters[typerefs.decimal] = adapters.decimal_to_TEXT() 
     203    if typerefs.fixedpoint: 
     204        default_adapters[typerefs.fixedpoint.FixedPoint] = adapters.fixedpoint_to_TEXT() 
     205 
     206 
     207class SQL92VARCHAR(AdjustableByteType): 
     208    """DatabaseType for adjustable-byte string types.""" 
     209     
     210    _initargs = AdjustableByteType._initargs + ("variable", "encoding") 
     211     
     212    # CHAR vs VARCHAR 
     213    variable = True 
     214    encoding = 'utf8' 
     215     
     216    default_pytype = str 
     217    default_adapters = {str: adapters.str_to_SQL92VARCHAR(), 
     218                        unicode: adapters.unicode_to_SQL92VARCHAR(), 
     219                        float: adapters.numeric_to_TEXT(float), 
     220                        int: adapters.numeric_to_TEXT(int), 
     221                        long: adapters.numeric_to_TEXT(long), 
     222                        datetime.timedelta: adapters.timedelta_to_SQL92DECIMAL(),  #?? 
     223                        None: adapters.Pickler(), 
     224                        } 
     225    if typerefs.decimal: 
     226        if hasattr(typerefs.decimal, "Decimal"): 
     227            default_adapters[typerefs.decimal.Decimal] = adapters.decimal_to_TEXT() 
     228        else: 
     229            default_adapters[typerefs.decimal] = adapters.decimal_to_TEXT() 
     230    if typerefs.fixedpoint: 
     231        default_adapters[typerefs.fixedpoint.FixedPoint] = adapters.fixedpoint_to_TEXT() 
     232 
     233 
     234class SQL92CHAR(SQL92VARCHAR): 
     235    variable = False 
     236 
     237 
     238class SQL92INTEGER(FrozenByteType): 
     239    """A base class for DatabaseTypes which conform to SQL92 INTEGER. 
     240     
     241    "INTEGER specifies the data type exact numeric, with binary or 
     242    decimal precision and scale of 0. The choice of binary versus 
     243    decimal precision is implementation-defined, but shall be the 
     244    same as SMALLINT." 
     245    """ 
     246     
     247    _initargs = FrozenByteType._initargs + ("signed", ) 
     248     
     249    default_pytype = int 
     250    default_adapters = {int: adapters.int_to_SQL92INTEGER(), 
     251                        long: adapters.int_to_SQL92INTEGER(), 
     252                        } 
     253    signed = True 
     254    _bytes = max_bytes = 4 
     255     
     256    def range(self): 
     257        """Return self.max - self.min.""" 
     258        return 2 ** (self.bytes * 8) 
     259     
     260    def min(self): 
     261        """Return the minimum value allowed.""" 
     262        if self.signed: 
     263            return 0 - (self.range() / 2) 
     264        else: 
     265            return 0 
     266     
     267    def max(self): 
     268        """Return the maximum value allowed.""" 
     269        if self.signed: 
     270            return (self.range() / 2) - 1 
     271        else: 
     272            return self.range() - 1 
     273 
     274 
     275class SQL92SMALLINT(SQL92INTEGER): 
     276    # The precision of SMALLINT shall be less than or 
     277    # equal to the precision of INTEGER. 
     278    _bytes = max_bytes = 2 
     279 
     280 
     281# "FLOAT specifies the data type approximate numeric, with binary 
     282#    precision equal to or greater than the value of the specified 
     283#    <precision>. The maximum value of <precision> is implementation- 
     284#    defined. <precision> shall not be greater than this value." 
     285 
     286class SQL92FLOAT(AdjustablePrecisionType): 
     287    """Base class for SQL 92 FLOAT types.""" 
    237288    default_pytype = float 
    238289 
    239290 
    240 class ExactNumericType(DatabaseType): 
    241      
    242     _initargs = DatabaseType._initargs + ("precision", "max_precision", 
    243                                           "scale") 
     291# "REAL specifies the data type approximate numeric, with implementation- 
     292#    defined precision." 
     293
     294# "DOUBLE PRECISION specifies the data type approximate numeric, 
     295#    with implementation-defined precision that is greater than the 
     296#    implementation-defined precision of REAL. 
     297 
     298class SQL92REAL(FrozenPrecisionType): 
     299    """Base class for SQL 92 REAL types.""" 
     300    default_pytype = float 
     301    _precision = max_precision = 24 
     302    default_adapters = {float: adapters.float_to_SQL92REAL()} 
     303 
     304class SQL92DOUBLE(SQL92REAL): 
     305    """Base class for SQL 92 DOUBLE PRECISION types.""" 
     306    _precision = max_precision = 53 
     307    default_adapters = {float: adapters.float_to_SQL92DOUBLE()} 
     308 
     309 
     310# "NUMERIC specifies the data type exact numeric, with the decimal 
     311# precision and scale specified by the <precision> and <scale>." 
     312
     313# "DECIMAL specifies the data type exact numeric, with the decimal 
     314# scale specified by the <scale> and the implementation-defined 
     315# decimal precision equal to or greater than the value of the 
     316# specified <precision>." 
     317
     318# In terms of adaptation, there's not much difference between these. 
     319# Plenty of databases make them synonyms anyway. 
     320 
     321class SQL92DECIMAL(AdjustablePrecisionType): 
     322     
     323    _initargs = AdjustablePrecisionType._initargs + ("scale",) 
     324     
     325    scale = None 
    244326     
    245327    # For exact numeric types, 'precision' refers to decimal digits 
    246     precision = None 
    247     scale = None 
    248      
    249     # Max decimal precision for NUMERIC columns (= 1000 for PostgreSQL 8). 
     328    _precision = 18 
    250329    max_precision = 1000 
    251330     
     
    260339        default_pytype = float 
    261340     
    262     default_adapters = {int: adapters.Numeric_to_DECIMAL(int), 
    263                         long: adapters.Numeric_to_DECIMAL(long), 
    264                         float: adapters.Numeric_to_DECIMAL(float), 
    265                         datetime.timedelta: adapters.INTERVAL(), 
     341    default_adapters = {int: adapters.numeric_to_SQL92DECIMAL(int), 
     342                        long: adapters.numeric_to_SQL92DECIMAL(long), 
     343                        float: adapters.numeric_to_SQL92DECIMAL(float), 
     344                        datetime.timedelta: adapters.timedelta_to_SQL92DECIMAL(), 
    266345                        } 
    267346    if typerefs.fixedpoint: 
    268         default_adapters[typerefs.fixedpoint.FixedPoint] = adapters.FIXEDPOINT() 
     347        default_adapters[typerefs.fixedpoint.FixedPoint] = adapters.fixedpoint_to_SQL92DECIMAL() 
    269348    if typerefs.decimal: 
    270349        if hasattr(typerefs.decimal, "Decimal"): 
    271             default_adapters[typerefs.decimal.Decimal] = adapters.DECIMAL() 
    272         else: 
    273             default_adapters[typerefs.decimal] = adapters.DECIMAL() 
     350            default_adapters[typerefs.decimal.Decimal] = adapters.decimal_to_SQL92DECIMAL() 
     351        else: 
     352            default_adapters[typerefs.decimal] = adapters.decimal_to_SQL92DECIMAL() 
    274353     
    275354    def range(self): 
     
    297376 
    298377 
    299 class FixedRangeType(DatabaseType): 
    300     """DatabaseType which represents values within a fixed range.""" 
    301     _min = None 
    302     _max = None 
    303      
    304     _initargs = DatabaseType._initargs + ("_min", "_max") 
    305      
    306     def range(self): 
    307         """Return self.max - self.min.""" 
    308         return self._max - self._min 
    309      
    310     def min(self): 
    311         """Return the minimum value allowed.""" 
    312         return self._min 
    313      
    314     def max(self): 
    315         """Return the maximum value allowed.""" 
    316         return self._max 
    317  
    318 class DateTimeType(FixedRangeType): 
     378class SQL92TIMESTAMP(FixedRangeType): 
    319379    default_pytype = datetime.datetime 
    320     default_adapters = {datetime.datetime: adapters.SQL92TIMESTAMP()} 
    321  
    322 class DateType(FixedRangeType): 
     380    default_adapters = {datetime.datetime: adapters.datetime_to_SQL92TIMESTAMP()} 
     381 
     382class SQL92DATE(FixedRangeType): 
    323383    default_pytype = datetime.date 
    324     default_adapters = {datetime.date: adapters.SQL92DATE()} 
    325  
    326 class TimeType(DatabaseType): 
     384    default_adapters = {datetime.date: adapters.date_to_SQL92DATE()} 
     385 
     386class SQL92TIME(DatabaseType): 
    327387    default_pytype = datetime.time 
    328     default_adapters = {datetime.time: adapters.SQL92TIME()} 
    329  
    330  
    331 class BooleanType(DatabaseType): 
    332     """DatabaseType which uses boolean values (True, False, Null).""" 
    333     default_pytype = bool 
    334     default_adapters = {bool: adapters.SQL99BOOLEAN()} 
    335  
    336 class BitType(DatabaseType): 
     388    default_adapters = {datetime.time: adapters.time_to_SQL92TIME()} 
     389 
     390class SQL92BIT(DatabaseType): 
    337391    """DatabaseType which uses boolean values (0, 1, Null).""" 
    338392    default_pytype = bool 
    339     default_adapters = {bool: adapters.SQL92BIT()} 
    340  
    341  
     393    default_adapters = {bool: adapters.bool_to_SQL92BIT()} 
     394 
     395 
     396 
     397# SQL99 types: CLOB, BLOB, BOOLEAN, ARRAY, ROW 
     398 
     399class SQL99BOOLEAN(DatabaseType): 
     400    """DatabaseType which uses boolean values (True, False, Null).""" 
     401    # ANSI SQL:1999 says something like: 
     402    # "The data type boolean comprises the distinct truth values 
     403    # true and false. Unless prohibited by a NOT NULL constraint, 
     404    # the boolean data type also supports the unknown truth value as 
     405    # the null value. This specification does not make a distinction 
     406    # between the null value of the boolean data type and the unknown 
     407    # truth value that is the result of an SQL <predicate>, <search 
     408    # condition>, or <boolean value expression>; they may be used 
     409    # interchangeably to mean exactly the same thing." 
     410    default_pytype = bool 
     411    default_adapters = {bool: adapters.bool_to_SQL99BOOLEAN()} 
     412 
  • trunk/geniusql/providers/ado.py

    r59 r60  
    8282 
    8383 
    84 class COM_timedelta(adapters.INTERVAL): 
     84class COM_timedelta(adapters.timedelta_to_SQL92DECIMAL): 
    8585     
    8686    def pull(self, value, dbtype): 
     
    122122 
    123123 
    124 class COM_time(adapters.SQL92TIME): 
     124class COM_time(adapters.time_to_SQL92TIME): 
    125125    def pull(self, value, dbtype): 
    126126        t = timedelta_from_com(value) 
     
    132132 
    133133 
    134 class COM_datetime(adapters.SQL92TIMESTAMP): 
     134class COM_datetime(adapters.datetime_to_SQL92TIMESTAMP): 
    135135     
    136136    epoch = datetime.datetime(1899, 12, 30) 
     
    186186 
    187187 
    188 class COM_date(adapters.SQL92DATE): 
     188class COM_date(adapters.date_to_SQL92DATE): 
    189189     
    190190    epoch = datetime.datetime(1899, 12, 30) 
  • trunk/geniusql/providers/msaccess.py

    r59 r60  
    9090 
    9191 
    92 class CURRENCY_float(adapters.SQL92DOUBLE): 
     92class CURRENCY_float(adapters.float_to_SQL92DOUBLE): 
    9393     
    9494    def pull(self, value, dbtype): 
     
    100100        return float(value) 
    101101 
    102 class CURRENCY_decimal(adapters.DECIMAL): 
     102class CURRENCY_decimal(adapters.decimal_to_SQL92DECIMAL): 
    103103     
    104104    def pull(self, value, dbtype): 
     
    114114        return value 
    115115 
    116 class CURRENCY_FixedPoint(adapters.FIXEDPOINT): 
     116class CURRENCY_FixedPoint(adapters.fixedpoint_to_SQL92DECIMAL): 
    117117     
    118118    def pull(self, value, dbtype): 
     
    151151                        "using %r in a case-sensitive way." % sqlop) 
    152152 
    153 class MSAccess_VARCHAR_Adapter(adapters.SQL92VARCHAR): 
     153class MSAccess_VARCHAR_Adapter(adapters.str_to_SQL92VARCHAR): 
    154154    escapes = [("'", "''")] 
    155155    compare_op = _compare_strings 
    156156 
    157 class MSAccess_UNICODE_Adapter(adapters.UNICODE): 
     157class MSAccess_UNICODE_Adapter(adapters.unicode_to_SQL92VARCHAR): 
    158158    escapes = [("'", "''")] 
    159159    compare_op = _compare_strings 
     
    180180# when you sort or group on a Memo field." 
    181181 
    182 class TEXT(dbtypes.AdjustableStringType): 
    183      
    184     _initargs = dbtypes.AdjustableStringType._initargs + ("with_compression",) 
     182class TEXT(dbtypes.SQL92VARCHAR): 
     183     
     184    _initargs = dbtypes.SQL92VARCHAR._initargs + ("with_compression",) 
    185185     
    186186    # Actually 255 chars, 2 bytes per char unless compressed 
     
    204204    with_compression = False 
    205205     
    206     default_adapters = dbtypes.AdjustableStringType.default_adapters.copy() 
     206    default_adapters = dbtypes.SQL92VARCHAR.default_adapters.copy() 
    207207    default_adapters.update({str: MSAccess_VARCHAR_Adapter(), 
    208208                             unicode: MSAccess_UNICODE_Adapter(), 
     
    218218 
    219219 
    220 class MEMO(dbtypes.FrozenStringType): 
     220class MEMO(dbtypes.TEXT): 
    221221    # MEMO is 1 GB max when set programatically (only 64K when set 
    222222    # in Access UI). But then, 1 GB is the limit for the whole DB. 
     
    227227    encoding = 'ISO-8859-1' 
    228228         
    229     default_adapters = dbtypes.FrozenStringType.default_adapters.copy() 
     229    default_adapters = dbtypes.TEXT.default_adapters.copy() 
    230230    default_adapters.update({str: MSAccess_VARCHAR_Adapter(), 
    231231                             unicode: MSAccess_UNICODE_Adapter(), 
     
    234234 
    235235 
    236 class TINYINT(dbtypes.IntegerType): 
     236class TINYINT(dbtypes.SQL92SMALLINT): 
    237237    synonyms = ['INTEGER1', 'BYTE'] 
    238238    bytes = max_bytes = 1 
    239239    signed = False 
    240240 
    241 class SMALLINT(dbtypes.IntegerType): 
     241class SMALLINT(dbtypes.SQL92SMALLINT): 
    242242    synonyms = ['SHORT', 'INTEGER2'] 
    243     bytes = max_bytes = 2 
    244  
    245 class INTEGER(dbtypes.IntegerType): 
     243 
     244class INTEGER(dbtypes.SQL92INTEGER): 
    246245    synonyms = ['LONG', 'INT', 'INTEGER4'] 
    247     bytes = max_bytes = 4 
    248  
    249 class FLOAT(dbtypes.InexactNumericType): 
     246 
     247 
     248class REAL(dbtypes.SQL92REAL): 
     249    synonyms = ['SINGLE', 'FLOAT4', 'IEEESINGLE'] 
     250 
     251class FLOAT(dbtypes.SQL92DOUBLE): 
    250252    synonyms = ['DOUBLE', 'FLOAT8', 'IEEEDOUBLE', 'NUMBER'] 
    251     precision = max_precision = 53 
    252     default_adapters = {float: adapters.SQL92DOUBLE()} 
    253  
    254 class REAL(dbtypes.InexactNumericType): 
    255     synonyms = ['SINGLE', 'FLOAT4', 'IEEESINGLE'] 
    256     precision = max_precision = 24 
    257     default_adapters = {float: adapters.SQL92REAL()} 
    258     implicit_conversions = [TINYINT, SMALLINT, INTEGER, FLOAT] 
    259  
    260  
    261 class DECIMAL(dbtypes.ExactNumericType): 
     253 
     254 
     255class DECIMAL(dbtypes.SQL92DECIMAL): 
    262256    synonyms = ['NUMERIC', 'DEC'] 
    263257     
    264258    # "...precision, the default is 18 and the maximum allowed value is 28. 
    265259    # For the scale, the default is 0 and the maximum allowed value is 28." 
    266     precision = 18 
     260    _precision = 18 
    267261    max_precision = 28 
    268262    scale = 0 
    269 ##     
    270 ##    # Hm. Docs say 28, but I can't seem to get more than 12 working. 
    271 ##    numeric_max_precision = 12 
    272 ##    numeric_max_bytes = 6 
    273263 
    274264 
     
    296286 
    297287 
    298 class YESNO(dbtypes.BooleanType): 
     288class YESNO(dbtypes.SQL99BOOLEAN): 
    299289    # "The BOOLEAN data types are logical types that result in either True 
    300290    # or False values. They use 1 byte of memory for storage, and their 
     
    318308 
    319309 
    320 class DATETIME(dbtypes.DateTimeType): 
     310class DATETIME(dbtypes.SQL92TIMESTAMP): 
    321311    # "The DATETIME data type is used to store date, time, and combination 
    322312    # date/time values for the years ranging from 100 to 9999.