Changeset 802

Show
Ignore:
Timestamp:
03/07/07 21:33:36 (1 year ago)
Author:
mfenniak
Message:

add varchar support, begin adding unicode support, add notice response

Files:

Legend:

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

    r801 r802  
    470470        createFromData = staticmethod(createFromData) 
    471471 
     472    class NoticeResponse(object): 
     473        def __init__(self): 
     474            pass 
     475        def createFromData(data): 
     476            # we could read the notice here, but we don't care yet. 
     477            return Protocol.NoticeResponse() 
     478        createFromData = staticmethod(createFromData) 
     479 
    472480    class ErrorResponse(object): 
    473481        def __init__(self, severity, code, msg): 
     
    561569            data_len = struct.unpack("!i", bytes[1:])[0] - 4 
    562570            bytes = self.sock.recv(data_len) 
    563             return Protocol.message_types[message_code].createFromData(bytes) 
     571            msg = Protocol.message_types[message_code].createFromData(bytes) 
     572            if isinstance(msg, Protocol.NoticeResponse): 
     573                # ignore NoticeResponse 
     574                return self._read_message() 
     575            else: 
     576                return msg 
    564577 
    565578        def connect(self): 
     
    579592                    raise InterfaceError("authentication method %s failed" % msg.__class__.__name__) 
    580593            else: 
    581                 raise InternalError("StartupMessage was responded to with non-AuthenticationRequest msg"
     594                raise InternalError("StartupMessage was responded to with non-AuthenticationRequest msg %r" % msg
    582595 
    583596        def _waitForReady(self): 
     
    675688 
    676689    message_types = { 
     690        "N": NoticeResponse, 
    677691        "R": AuthenticationRequest, 
    678692        "S": ParameterStatus, 
     
    769783        return str(v) 
    770784 
     785    def varcharin(data, description): 
     786        return unicode(data, "utf-8") 
     787 
     788    def varcharout(v): 
     789        return v.encode("utf-8") 
     790 
    771791    py_types = { 
    772792        int: (1700, numeric_out, None), 
     793        str: (1043, varcharout, None), 
     794        unicode: (1043, varcharout, None), 
    773795    } 
    774796 
     
    777799        21: (None, int2recv), 
    778800        23: (int4in, int4recv), 
     801        1043: (varcharin, None), 
    779802        1114: (timestamp_in, timestamp_recv), 
    780803        1700: (numeric_in, None), 
  • pg8000/trunk/pg8000-test.py

    r801 r802  
    99cur2 = pg8000.Cursor(db) 
    1010 
    11 cur1.execute("DELETE FROM t1") 
    12 cur1.execute("INSERT INTO t1 (f1, f2) VALUES ($1, $2)", 1, 1) 
    13 cur1.execute("INSERT INTO t1 (f1, f2) VALUES ($1, $2)", 2, 10) 
    14 cur1.execute("INSERT INTO t1 (f1, f2) VALUES ($1, $2)", 3, 100) 
    15 cur1.execute("INSERT INTO t1 (f1, f2) VALUES ($1, $2)", 4, 1000) 
    16 cur1.execute("INSERT INTO t1 (f1, f2) VALUES ($1, $2)", 5, 10000) 
     11cur1.execute("DROP TABLE t1") 
     12cur1.execute("CREATE TABLE t1 (f1 int primary key, f2 int not null, f3 varchar(50) not null)") 
     13cur1.execute("INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", 1, 1, "hello") 
     14cur1.execute("INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", 2, 10, u"he\u0173llo") 
     15cur1.execute("INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", 3, 100, "hello") 
     16cur1.execute("INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", 4, 1000, "hello") 
     17cur1.execute("INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", 5, 10000, "hello") 
    1718 
    1819print "begin query..." 
     
    2829 
    2930print "begin query..." 
    30 cur1.execute("SELECT 5000 + 1 as int_test, True as bool_test, '2000-01-02 03:04:05.67'::timestamp as timestamp_test, 22::numeric") 
     31cur1.execute("SELECT 5000 + 1 as int_test, True as bool_test, '2000-01-02 03:04:05.67'::timestamp as timestamp_test, 99999999999999999999::numeric") 
    3132for row in cur1: 
    3233    print repr(row)