Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion pymonetdb/sql/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ def __init__(self, connection: 'pymonetdb.sql.connections.Connection'):
unpacker = '>q'
self._unpack_int64 = unpacker

def _check_closed(self):
if self.connection is None:
self._exception_handler(InterfaceError, "cursor is closed")

def _check_executed(self):
if not self._executed:
self._exception_handler(ProgrammingError, "do a execute() first")
Expand Down Expand Up @@ -199,7 +203,7 @@ def execute(self, operation: str, parameters: Optional[Union[Dict, Sequence[Any]
"""

if not self.connection:
self._exception_handler(ProgrammingError, "cursor is closed")
self._exception_handler(InterfaceError, "cursor is closed")

# clear message history
self.messages = []
Expand Down Expand Up @@ -276,6 +280,7 @@ def fetchone(self):
"""Fetch the next row of a query result set, returning a
single sequence, or None when no more data is available."""

self._check_closed()
self._check_executed()
if self._query_id is None:
msg = "query didn't result in a resultset"
Expand Down Expand Up @@ -304,6 +309,7 @@ def fetchmany(self, size=None):
call to .execute*() did not produce any result set or no
call was issued yet."""

self._check_closed()
self._check_executed()
if self._query_id is None:
msg = "query didn't result in a resultset"
Expand Down Expand Up @@ -338,6 +344,9 @@ def fetchall(self):
return self.fetchmany(self.rowcount)

def nextset(self) -> Optional[bool]:
if self.connection is None:
return None

if not self._next_result_sets:
self._query_id = None
self.description = None
Expand Down
4 changes: 2 additions & 2 deletions tests/test_capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from typing import List
import unittest

from pymonetdb.exceptions import ProgrammingError
from pymonetdb.exceptions import ProgrammingError, InterfaceError
import pymonetdb
from pymonetdb.sql import monetize
from tests.util import test_args
Expand Down Expand Up @@ -413,7 +413,7 @@ def test_bigresult(self):

def test_closecur(self):
self.cursor.close()
self.assertRaises(ProgrammingError, self.cursor.execute, "select * from tables")
self.assertRaises(InterfaceError, self.cursor.execute, "select * from tables")
self.cursor = self.connection.cursor()

def test_customtype(self):
Expand Down