Ticket #4287: inf-bug.patch

File inf-bug.patch, 1.2 KB (added by calmez, 14 years ago)
  • django/db/backends/mysql/base.py

     
    4343DatabaseError = Database.DatabaseError
    4444IntegrityError = Database.IntegrityError
    4545
     46def Float2Str(value, conv):
     47    if value == float('inf'):
     48        return '2147483647'
     49    elif value == float('-inf'):
     50        return '-2147483648'
     51    else:
     52        return conversions[float](value, conv)
     53
     54def mysql_float_converter(value):
     55    if value == '2147483647':
     56        return float('inf')
     57    elif value == '-2147483648':
     58        return float('-inf')
     59    else:
     60        return float(value)
     61
    4662# MySQLdb-1.2.1 returns TIME columns as timedelta -- they are more like
    4763# timedelta in terms of actual behavior as they are signed and include days --
    4864# and Django expects time, so we still need to override that. We also need to
     
    5369    FIELD_TYPE.TIME: util.typecast_time,
    5470    FIELD_TYPE.DECIMAL: util.typecast_decimal,
    5571    FIELD_TYPE.NEWDECIMAL: util.typecast_decimal,
     72    float: Float2Str,
     73    FIELD_TYPE.DOUBLE: mysql_float_converter,
    5674})
    5775
    5876# This should match the numerical portion of the version numbers (we can treat
Back to Top