Skip to content

Commit 81431aa

Browse files
committed
Merge pull request #119 from nuodb/vduda/DB-12019
[DB-12019] cursor.close() - fails to clear the result set with error thrown with NuoDB version >2.1
2 parents 9395487 + 4e90fae commit 81431aa

File tree

4 files changed

+42
-5
lines changed

4 files changed

+42
-5
lines changed

pynuodb/cursor.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ def close(self):
6969
"""Closes the cursor into the database."""
7070
self._check_closed()
7171
self._statement_cache.shutdown()
72+
if self._result_set:
73+
self._result_set.close(self.session)
7274
self.closed = True
7375

7476
def _check_closed(self):
@@ -79,10 +81,7 @@ def _check_closed(self):
7981
raise Error("connection is closed")
8082

8183
def _reset(self):
82-
"""Resets SQL transaction variables.
83-
84-
Also closes any open statements and result sets.
85-
"""
84+
"""Resets SQL transaction variables."""
8685
self.description = None
8786
self.rowcount = -1
8887
self.colcount = -1

pynuodb/encodedsession.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,13 @@ def close_statement(self, statement):
271271
self._putMessageId(protocol.CLOSESTATEMENT).putInt(statement.handle)
272272
self._exchangeMessages(False)
273273

274+
def close_result_set(self, result_set):
275+
"""
276+
:type result_set: ResultSet
277+
"""
278+
self._putMessageId(protocol.CLOSERESULTSET).putInt(result_set.handle)
279+
self._exchangeMessages(False)
280+
274281
def create_prepared_statement(self, query):
275282
"""
276283
:type query: str

pynuodb/result_set.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,9 @@ def fetchone(self, session):
3535
res = self.results[self.results_idx]
3636
self.results_idx += 1
3737
return res
38+
39+
def close(self, session):
40+
"""
41+
:type session EncodedSession
42+
"""
43+
session.close_result_set(self)

tests/nuodb_cursor_test.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import unittest
44

55
from .nuodb_base import NuoBase
6-
from pynuodb.exception import DataError, ProgrammingError, BatchError
6+
from pynuodb.exception import DataError, ProgrammingError, BatchError, OperationalError
7+
from distutils.version import LooseVersion
8+
from os import getenv
79

810

911
class NuoDBCursorTest(NuoBase):
@@ -125,6 +127,29 @@ def test_executemany_somefail(self):
125127

126128
cursor.execute("DROP TABLE executemany_table")
127129

130+
def test_result_set_gets_closed(self):
131+
current_version = getenv('NUODB_VERSION', None) # skipif <2.1
132+
if current_version is not None and not LooseVersion(current_version) < LooseVersion("2.1"):
133+
# Server will throw error after 1000 open result sets
134+
con = self._connect()
135+
for j in [False, True]:
136+
for i in range(2015):
137+
if not j:
138+
cursor = con.cursor()
139+
cursor.execute('select 1 from dual;')
140+
con.commit()
141+
cursor.close()
142+
else:
143+
if i >= 1000:
144+
with self.assertRaises(OperationalError):
145+
cursor = con.cursor()
146+
cursor.execute('select 1 from dual;')
147+
con.commit()
148+
else:
149+
cursor = con.cursor()
150+
cursor.execute('select 1 from dual;')
151+
con.commit()
152+
128153

129154
if __name__ == '__main__':
130155
unittest.main()

0 commit comments

Comments
 (0)