Changeset 840

Show
Ignore:
Timestamp:
03/13/07 09:42:35 (1 year ago)
Author:
mfenniak
Message:

Fix bugs in NULL parameter send. Finish adding bytea type.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pg8000/trunk/pg8000.py

    r839 r840  
    713713            val = val + struct.pack("!h", len(self.type_oids)) 
    714714            for oid in self.type_oids: 
     715                # Parse message doesn't seem to handle the -1 type_oid for NULL 
     716                # values that other messages handle.  So we'll provide type_oid 705, 
     717                # the PG "unknown" type. 
     718                if oid == -1: oid = 705 
    715719                val = val + struct.pack("!i", oid) 
    716720            val = struct.pack("!i", len(val) + 4) + val 
     
    12801284        } 
    12811285 
     1286class Bytea(str): 
     1287    pass 
     1288 
    12821289class Types(object): 
     1290 
    12831291    def pg_type_info(typ): 
    12841292        data = Types.py_types.get(typ) 
     
    12881296        if type_oid == None: 
    12891297            raise InternalError("type %r has no type_oid" % typ) 
     1298        elif type_oid == -1: 
     1299            # special case: NULL values 
     1300            return type_oid, 0 
    12901301        prefer = data.get("prefer") 
    12911302        if prefer != None: 
     
    14771488            return datetime.timedelta(0) 
    14781489 
     1490    def byteasend(v, **kwargs): 
     1491        return str(v) 
     1492 
    14791493    def bytearecv(data, **kwargs): 
    14801494        return Bytea(data) 
     
    14911505        float: {"tid": 701, "bin_out": float8send}, 
    14921506        decimal.Decimal: {"tid": 1700, "txt_out": numeric_out}, 
     1507        Bytea: {"tid": 17, "bin_out": byteasend}, 
    14931508        type(None): {"tid": -1}, 
    14941509    } 
     
    15121527        #1184: (timestamptz_in, None), # timestamp w/ tz 
    15131528 
    1514 class Bytea(str): 
    1515     pass 
    1516  
    1517  
     1529 
     1530