Changeset 802
- Timestamp:
- 03/07/07 21:33:36 (1 year ago)
- Files:
-
- pg8000/trunk/pg8000.py (modified) (6 diffs)
- pg8000/trunk/pg8000-test.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
pg8000/trunk/pg8000.py
r801 r802 470 470 createFromData = staticmethod(createFromData) 471 471 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 472 480 class ErrorResponse(object): 473 481 def __init__(self, severity, code, msg): … … 561 569 data_len = struct.unpack("!i", bytes[1:])[0] - 4 562 570 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 564 577 565 578 def connect(self): … … 579 592 raise InterfaceError("authentication method %s failed" % msg.__class__.__name__) 580 593 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) 582 595 583 596 def _waitForReady(self): … … 675 688 676 689 message_types = { 690 "N": NoticeResponse, 677 691 "R": AuthenticationRequest, 678 692 "S": ParameterStatus, … … 769 783 return str(v) 770 784 785 def varcharin(data, description): 786 return unicode(data, "utf-8") 787 788 def varcharout(v): 789 return v.encode("utf-8") 790 771 791 py_types = { 772 792 int: (1700, numeric_out, None), 793 str: (1043, varcharout, None), 794 unicode: (1043, varcharout, None), 773 795 } 774 796 … … 777 799 21: (None, int2recv), 778 800 23: (int4in, int4recv), 801 1043: (varcharin, None), 779 802 1114: (timestamp_in, timestamp_recv), 780 803 1700: (numeric_in, None), pg8000/trunk/pg8000-test.py
r801 r802 9 9 cur2 = pg8000.Cursor(db) 10 10 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) 11 cur1.execute("DROP TABLE t1") 12 cur1.execute("CREATE TABLE t1 (f1 int primary key, f2 int not null, f3 varchar(50) not null)") 13 cur1.execute("INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", 1, 1, "hello") 14 cur1.execute("INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", 2, 10, u"he\u0173llo") 15 cur1.execute("INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", 3, 100, "hello") 16 cur1.execute("INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", 4, 1000, "hello") 17 cur1.execute("INSERT INTO t1 (f1, f2, f3) VALUES ($1, $2, $3)", 5, 10000, "hello") 17 18 18 19 print "begin query..." … … 28 29 29 30 print "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")31 cur1.execute("SELECT 5000 + 1 as int_test, True as bool_test, '2000-01-02 03:04:05.67'::timestamp as timestamp_test, 99999999999999999999::numeric") 31 32 for row in cur1: 32 33 print repr(row)
