Skip to content

Commit

Permalink
Merge pull request #119 from nuodb/vduda/DB-12019
Browse files Browse the repository at this point in the history
[DB-12019] cursor.close() - fails to clear the result set with error thrown with NuoDB version >2.1
  • Loading branch information
mjmichaels committed Aug 25, 2015
2 parents 9395487 + 4e90fae commit 81431aa
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
7 changes: 3 additions & 4 deletions pynuodb/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ def close(self):
"""Closes the cursor into the database."""
self._check_closed()
self._statement_cache.shutdown()
if self._result_set:
self._result_set.close(self.session)
self.closed = True

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

def _reset(self):
"""Resets SQL transaction variables.
Also closes any open statements and result sets.
"""
"""Resets SQL transaction variables."""
self.description = None
self.rowcount = -1
self.colcount = -1
Expand Down
7 changes: 7 additions & 0 deletions pynuodb/encodedsession.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ def close_statement(self, statement):
self._putMessageId(protocol.CLOSESTATEMENT).putInt(statement.handle)
self._exchangeMessages(False)

def close_result_set(self, result_set):
"""
:type result_set: ResultSet
"""
self._putMessageId(protocol.CLOSERESULTSET).putInt(result_set.handle)
self._exchangeMessages(False)

def create_prepared_statement(self, query):
"""
:type query: str
Expand Down
6 changes: 6 additions & 0 deletions pynuodb/result_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,9 @@ def fetchone(self, session):
res = self.results[self.results_idx]
self.results_idx += 1
return res

def close(self, session):
"""
:type session EncodedSession
"""
session.close_result_set(self)
27 changes: 26 additions & 1 deletion tests/nuodb_cursor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import unittest

from .nuodb_base import NuoBase
from pynuodb.exception import DataError, ProgrammingError, BatchError
from pynuodb.exception import DataError, ProgrammingError, BatchError, OperationalError
from distutils.version import LooseVersion
from os import getenv


class NuoDBCursorTest(NuoBase):
Expand Down Expand Up @@ -125,6 +127,29 @@ def test_executemany_somefail(self):

cursor.execute("DROP TABLE executemany_table")

def test_result_set_gets_closed(self):
current_version = getenv('NUODB_VERSION', None) # skipif <2.1
if current_version is not None and not LooseVersion(current_version) < LooseVersion("2.1"):
# Server will throw error after 1000 open result sets
con = self._connect()
for j in [False, True]:
for i in range(2015):
if not j:
cursor = con.cursor()
cursor.execute('select 1 from dual;')
con.commit()
cursor.close()
else:
if i >= 1000:
with self.assertRaises(OperationalError):
cursor = con.cursor()
cursor.execute('select 1 from dual;')
con.commit()
else:
cursor = con.cursor()
cursor.execute('select 1 from dual;')
con.commit()


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

0 comments on commit 81431aa

Please sign in to comment.