Skip to content

Commit 5fc0ce6

Browse files
author
James William Pye
committed
Properly fix first()'s handling of extracted count.
Bad logic returned the command tag instead of zero.
1 parent 52aeca8 commit 5fc0ce6

3 files changed

Lines changed: 12 additions & 3 deletions

File tree

postgresql/documentation/changes.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Changes
44
1.0.1 in development
55
--------------------
66

7-
* <No changes>
7+
* First .first()'s handling of counts and commands.
8+
Bad logic caused zero-counts to return the command tag.
89

910
1.0 release on 2010-03-27
1011
-------------------------

postgresql/driver/pq3.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,13 @@ def first(self, *parameters):
15931593
else:
15941594
# Probably a Null command.
15951595
return None
1596-
return cm.extract_count() or cm.extract_command()
1596+
1597+
count = cm.extract_count()
1598+
if count is None:
1599+
command = cm.extract_command()
1600+
if command is not None:
1601+
return command.decode('ascii')
1602+
return count
15971603

15981604
def _load_copy_chunks(self, chunks, *parameters):
15991605
"""

postgresql/test/test_driver.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,8 @@ def testStatementCall(self):
424424

425425
@pg_tmp
426426
def testStatementFirstDML(self):
427-
db.execute("CREATE TEMP TABLE first (i int)")
427+
cmd = prepare("CREATE TEMP TABLE first (i int)").first()
428+
self.failUnlessEqual(cmd, 'CREATE TABLE')
428429
fins = db.prepare("INSERT INTO first VALUES (123)").first
429430
fupd = db.prepare("UPDATE first SET i = 321 WHERE i = 123").first
430431
fdel = db.prepare("DELETE FROM first").first
@@ -436,6 +437,7 @@ def testStatementFirstDML(self):
436437
self.failUnlessEqual(fins(), 1)
437438
self.failUnlessEqual(fupd(), 2)
438439
self.failUnlessEqual(fdel(), 3)
440+
self.failUnlessEqual(fdel(), 0)
439441

440442
@pg_tmp
441443
def testStatementRowsPersistence(self):

0 commit comments

Comments
 (0)