Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more than 2 consecutive cursor open execute and iter fail [PYFB15] #38

Closed
firebird-automations opened this issue Mar 6, 2012 · 7 comments

Comments

@firebird-automations
Copy link

Submitted by: @pmakowski

Assigned to: @pmakowski

#⁠coding:utf-8

import fdb

con = fdb.connect(dsn='localhost:employee', user='sysdba', password='masterkey')

cur = con.cursor()
SELECT = "select COUNTRY, CURRENCY from country"

cur.execute(SELECT)
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end1')
cur.execute(SELECT)
print('start2')
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end2')
cur.execute(SELECT)
print('start3')
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end3')

the third iteration fails
start3
Traceback (most recent call last):
File "test_bla.py", line 22, in <module>
for row in cur:
File "/usr/lib/python2.7/site-packages/fdb-0.7.1-py2.7.egg/fdb/fbcore.py", line 1633, in next
row = self.fetchone()
File "/usr/lib/python2.7/site-packages/fdb-0.7.1-py2.7.egg/fdb/fbcore.py", line 1697, in fetchone
return self._ps._fetchone()
File "/usr/lib/python2.7/site-packages/fdb-0.7.1-py2.7.egg/fdb/fbcore.py", line 1599, in _fetchone
"Cursor.fetchone: Unknown status returned by fetch operation:")
fdb.fbcore.ProgrammingError: ('Cursor.fetchone: Unknown status returned by fetch operation:\n- SQLCODE: -502\n- The cursor identified in an OPEN statement is already open.\n- Dynamic SQL Error', -502, 335544569)

if you close the cursor, all is ok
cur.execute(SELECT)
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end1')
cur.execute(SELECT)
print('start2')
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end2')
cur.close() #⁠ here added a close
cur.execute(SELECT)
print('start3')
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end3')

Commits: 324a05a

@firebird-automations
Copy link
Author

Modified by: @pmakowski

description: import fdb
con = fdb.connect(dsn='localhost:employee', user='sysdba', password='masterkey')
cur = con.cursor()
SELECT = "select COUNTRY, CURRENCY from country"
cur.execute(SELECT)
for row in cur.itermap():
print('%(country)s has been publicly available since %(currency)s.' % row)

return :
File "test_bla.py", line 23, in <module>
for row in cur.itermap():
File "/usr/lib/python2.7/site-packages/fdb-0.7.1-py2.7.egg/fdb/fbcore.py", line 1944, in next
result = self.getnext()
File "/usr/lib/python2.7/site-packages/fdb-0.7.1-py2.7.egg/fdb/fbcore.py", line 1712, in fetchonemap
row = self.fetchone()
File "/usr/lib/python2.7/site-packages/fdb-0.7.1-py2.7.egg/fdb/fbcore.py", line 1697, in fetchone
return self._ps._fetchone()
File "/usr/lib/python2.7/site-packages/fdb-0.7.1-py2.7.egg/fdb/fbcore.py", line 1599, in _fetchone
"Cursor.fetchone: Unknown status returned by fetch operation:")
fdb.fbcore.ProgrammingError: ('Cursor.fetchone: Unknown status returned by fetch operation:\n- SQLCODE: -502\n- The cursor identified in an OPEN statement is already open.\n- Dynamic SQL Error', -502, 335544569)

=>

#⁠coding:utf-8

import fdb

con = fdb.connect(dsn='localhost:employee', user='sysdba', password='masterkey')

cur = con.cursor()
SELECT = "select COUNTRY, CURRENCY from country"

cur.execute(SELECT)
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end1')
cur.execute(SELECT)
print('start2')
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end2')
cur.execute(SELECT)
print('start3')
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end3')

the third iteration fails
start3
Traceback (most recent call last):
File "test_bla.py", line 22, in <module>
for row in cur:
File "/usr/lib/python2.7/site-packages/fdb-0.7.1-py2.7.egg/fdb/fbcore.py", line 1633, in next
row = self.fetchone()
File "/usr/lib/python2.7/site-packages/fdb-0.7.1-py2.7.egg/fdb/fbcore.py", line 1697, in fetchone
return self._ps._fetchone()
File "/usr/lib/python2.7/site-packages/fdb-0.7.1-py2.7.egg/fdb/fbcore.py", line 1599, in _fetchone
"Cursor.fetchone: Unknown status returned by fetch operation:")
fdb.fbcore.ProgrammingError: ('Cursor.fetchone: Unknown status returned by fetch operation:\n- SQLCODE: -502\n- The cursor identified in an OPEN statement is already open.\n- Dynamic SQL Error', -502, 335544569)

if you close the cursor, all is ok
cur.execute(SELECT)
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end1')
cur.execute(SELECT)
print('start2')
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end2')
cur.close() #⁠ here added a close
cur.execute(SELECT)
print('start3')
for row in cur:
print('%s - %s.' % (row[0], row[1]))
print('end3')

summary: bub in cur.itermap() => more than 2 consecutive cursor open execute and iter fail

@firebird-automations
Copy link
Author

Commented by: @pmakowski

another test case that fail:

import fdb
con = fdb.connect(dsn='localhost:employee', user='sysdba', password='masterkey')
cur = con.cursor()
SELECT = "select COUNTRY, CURRENCY from country ROWS 1"
cur.execute(SELECT)
for row in cur:
print('%s - %s.' % (row[0], row[1]))
cur.execute(SELECT)
for row in cur:
print('%s - %s.' % (row[0], row[1]))
for row in cur:
print('%s - %s.' % (row[0], row[1]))

@firebird-automations
Copy link
Author

Commented by: @pmakowski

one solution can be to do a change in class Cursor

instead of :
def execute(self,operation, parameters = None):
if self._ps != None:
self._ps._free_handle()
...

put :
def execute(self,operation, parameters = None):
if self._ps != None:
self._ps._close()
for ps in self._prepared_statements.values():
ps._close()
self._prepared_statements.clear()
...

but the problem is then still there for PreparedStatement

@firebird-automations
Copy link
Author

Commented by: @pmakowski

Seems that the problem is in class PreparedStatement:

def \_free\_handle\(self\):
    if self\.\_stmt\_handle \!= None and not self\.\_\_closed:

if fact self.__closed is sometime wrongly reported as true

if you change class PreparedStatement _free_handle(self)

for :
def _free_handle(self):
if self._stmt_handle != None:

(without the condition on self.__closed)
all is ok

do I commit it ?

@firebird-automations
Copy link
Author

Commented by: @pmakowski

fixed in rev 54113

@firebird-automations
Copy link
Author

Modified by: @pmakowski

assignee: Pavel Cisar [ pcisar ] => Philippe Makowski [ makowski ]

status: Open [ 1 ] => Resolved [ 5 ]

resolution: Fixed [ 1 ]

Fix Version: 0.8.0 [ 10464 ]

@firebird-automations
Copy link
Author

Modified by: @pcisar

status: Resolved [ 5 ] => Closed [ 6 ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant