Contact: fumanchu@aminus.org

Log in as guest/geniusql to create tickets

Changeset 31

Show
Ignore:
Timestamp:
03/12/07 20:21:31
Author:
fumanchu
Message:

Changed timedelta to use NUMERIC by default; floats were causing rounding errors. Also added new "add_pickled_type" methods to the adapter base classes to make adding user-defined types easier.

Files:

Legend:

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

    r30 r31  
    185185     
    186186    def coerce_datetime_timedelta_to_any(self, value): 
    187         float_val = value.days + (value.seconds / 86400.0) 
    188         return repr(float_val) 
     187        dec_val = (value.days * 86400) + value.seconds 
     188        return repr(dec_val) 
    189189     
    190190    coerce_decimal_to_any = str 
     
    232232    def _to_TEXT(self, value): 
    233233        return "'%s'" % str(value) 
     234     
     235    def add_pickled_type(self, pytype): 
     236        name = "coerce_%s_to_any" % getCoerceName(pytype) 
     237        setattr(self, name, self.do_pickle) 
     238 
    234239 
    235240for fromtype in ('decimal', 'decimal_Decimal', 'fixedpoint_FixedPoint', 
     
    291296     
    292297    def coerce_any_to_datetime_timedelta(self, value): 
    293         days, seconds = divmod(value, 1
    294         return datetime.timedelta(days, int(seconds * 86400)) 
     298        days, seconds = divmod(long(value), 86400
     299        return datetime.timedelta(int(days), int(seconds)) 
    295300     
    296301    def coerce_any_to_decimal(self, value): 
     
    337342        else: 
    338343            return unicode(value, self.encoding) 
     344     
     345    def add_pickled_type(self, pytype): 
     346        name = "coerce_any_to_%s" % getCoerceName(pytype) 
     347        setattr(self, name, self.do_pickle) 
    339348 
    340349 
     
    494503    def coerce_datetime_time(self, col): return "TIME" 
    495504     
    496     # I was seriously disinterested in writing a parser for interval
     505    # Use decimal instead of float to avoid rounding errors
    497506    def coerce_datetime_timedelta(self, col): 
    498         return self.coerce_float(col
     507        return self.int_type(self.numeric_max_bytes
    499508     
    500509    def decimal_type(self, colname, precision, scale): 
     
    553562            return self.coerce_long(col) 
    554563        return self.int_type(bytes) 
    555  
     564     
     565    def add_pickled_type(self, pytype): 
     566        name = "coerce_%s" % getCoerceName(pytype) 
     567        setattr(self, name, self.coerce_str) 
     568