Changeset 816

Show
Ignore:
Timestamp:
03/08/07 23:12:42 (2 years ago)
Author:
mfenniak
Message:

Add support for NULL DB parameters and values

Files:

Legend:

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

    r812 r816  
    417417            val = val + struct.pack("!h", len(self.params)) 
    418418            for param in self.params: 
    419                 val = val + struct.pack("!i", len(param)) + param 
     419                if param == None: 
     420                    # special case, NULL value 
     421                    val = val + struct.pack("!i", -1) 
     422                else: 
     423                    val = val + struct.pack("!i", len(param)) + param 
    420424            val = val + struct.pack("!h", len(self.out_fc)) 
    421425            for fc in self.out_fc: 
     
    976980        if data == None: 
    977981            raise NotSupportedError("type %r not mapped to pg type" % typ) 
     982        elif data.get("tid") == -1: 
     983            # special case: NULL values 
     984            return None 
    978985        if fc == 0: 
    979986            func = data.get("txt_out") 
     
    10161023 
    10171024    def py_value(v, description, **kwargs): 
     1025        if v == None: 
     1026            # special case - NULL value 
     1027            return None 
    10181028        type_oid = description['type_oid'] 
    10191029        format = description['format'] 
     
    11341144        str: {"tid": 25, "txt_out": textout}, 
    11351145        unicode: {"tid": 25, "txt_out": textout}, 
     1146        type(None): {"tid": -1}, 
    11361147    } 
    11371148 
  • pg8000/trunk/pg8000-test.py

    r815 r816  
    1212 
    1313db.execute("DROP TABLE t1") 
    14 db.execute("CREATE TABLE t1 (f1 int primary key, f2 int not null, f3 varchar(50) not null)") 
     14db.execute("CREATE TABLE t1 (f1 int primary key, f2 int not null, f3 varchar(50) null)") 
    1515 
    1616s1 = pg8000.PreparedStatement(db, "INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", int, int, str) 
     
    1818s1.execute(2, 10, "he\u0173llo") 
    1919s1.execute(3, 100, "hello") 
    20 s1.execute(4, 1000, "hello"
     20s1.execute(4, 1000, None
    2121s1.execute(5, 10000, "hello") 
    2222s1.execute(6, 100000, "hello")