pygresql returns incorrect result with fetchone - Mailing list pgsql-bugs

From pgsql-bugs@postgresql.org
Subject pygresql returns incorrect result with fetchone
Date
Msg-id 200103112135.f2BLZd768664@hub.org
Whole thread Raw
List pgsql-bugs
Robert Blyler (rlblyler@linuxmail.org) reports a bug with a severity of 2
The lower the number the more severe it is.

Short Description
pygresql returns incorrect result with fetchone

Long Description
The pgdb fetchone function always returns the first row. Interestingly it contains the correct rowcount. There is no
documentationregarding this behavior. Users are refered to the DBAPI documention at www.python.org. Python.org states
thatit should return the next row. 

 fetchone()
Fetch the next row of a query result set, returning a single sequence, or None when no more data is available. [6]

Sample Code
#!/usr/bin/env python
############################################################################################
#      pgdb module does not correctly return next data from fetchone. It does return       #
#      the correct number of records though. The following example should show the         #
#      same data for both fetchone and fetchmany.                                          #
############################################################################################
#
import pgdb
conx=pgdb.connect()
mycursor=conx.cursor()
print "Create noid..."
mycursor.execute("create table noid ( noid_id char(6), noid_desc char(20), primary key (noid_id) );")
print "Insert Noid..."
mycursor.execute("insert into noid (noid_id, noid_desc) values( '10', 'Huey');")
mycursor.execute("insert into noid (noid_id, noid_desc) values( '20', 'Dewy');")
mycursor.execute("insert into noid (noid_id, noid_desc) values( '30', 'Louie');")
#
print "----------- Using FetchOne ------------"
mycursor.execute('select * from noid;')
if mycursor.rowcount == 1:
   print mycursor.fetchone()
else:
   for i in range(mycursor.rowcount):
       print mycursor.fetchone()
#
print "---------- Using Fetchmany ------------"
mycursor.execute('select * from noid;')
test=mycursor.fetchmany()
for i in range(mycursor.rowcount):
    print test[i]
#
print "Delete the noids"
mycursor.execute("delete from noid;")
print "Drop noid"
mycursor.execute("drop table noid;")
#
#        The output I get from the script
#
#Create noid...
#NOTICE:  CREATE TABLE/PRIMARY KEY will create implicit index 'noid_pkey' for table 'noid'
#Insert Noid...
#----------- Using FetchOne ------------
#['10    ', 'Huey                ']
#['10    ', 'Huey                ']
#['10    ', 'Huey                ']
#---------- Using Fetchmany ------------
#['10    ', 'Huey                ']
#['20    ', 'Dewy                ']
#['30    ', 'Louie               ']
#Delete the noids
#Drop noid
#                               version
#---------------------------------------------------------------------
# PostgreSQL 7.0.2 on i686-pc-linux-gnu, compiled by gcc egcs-2.91.66
# Running from RPM downloaded from postgresql.org, with the exception
# of replacing that symlink that didn't point anywhere with the actual
# file.
# PyGreSQL-3.1 ( Same problem on older<unknown> version )
#Distribution:                  Red Hat Linux
#Operating System:              Linux
#Distribution Version:          Red Hat Linux release 6.2 (Zoot)
#
#Operating System Version:      #1 Tue Mar 7 21:07:39 EST 2000
#Operating System Release:      2.2.14-5.0
#Processor Type:                i686
#Host Name:                     pook.trilliji.org
#User Name:                     trilliji
#X Display Name:                :0
#System Status:                 2:54pm  up 16:45,  2 users,  load average: 0.04, 0.11




No file was uploaded with this report

pgsql-bugs by date:

Previous
From: pgsql-bugs@postgresql.org
Date:
Subject: PG 7.0.3SuSE7-1: /usr/include/pgsql/os.h points to nowhere
Next
From: Reinhard Max
Date:
Subject: Re: PG 7.0.3SuSE7-1: /usr/include/pgsql/os.h points to nowhere