Skip to content

fix(cursors): reset iterator counter between queries execution #36

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ on:

jobs:
tests:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
# last supported for sqlitecloud, last security maintained, last release
python-version: ["3.6", "3.8", "3.12"]
python-version: ["3.9", "3.10", "3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
9 changes: 7 additions & 2 deletions src/sqlitecloud/dbapi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,8 +584,7 @@ def execute(
sql, parameters, self.connection.sqlitecloud_connection
)

self._resultset = None
self._result_operation = None
self._reset()

if isinstance(result, SQLiteCloudResult):
self._resultset = result
Expand Down Expand Up @@ -853,6 +852,12 @@ def _get_value(self, row: int, col: int) -> Optional[Any]:

return self._convert_value(value, colname, decltype)

def _reset(self) -> None:
self._resultset = None
self._result_operation = None

self._iter_row = 0

def __iter__(self) -> "Cursor":
return self

Expand Down
15 changes: 15 additions & 0 deletions src/tests/integration/test_dbapi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,3 +441,18 @@ def test_connection_is_connected(self, sqlitecloud_dbapi2_connection):
connection.close()

assert not connection.is_connected()

def test_fetchall_returns_right_nrows_number(self, sqlitecloud_dbapi2_connection):
connection = sqlitecloud_dbapi2_connection

cursor = connection.cursor()

cursor.execute("SELECT * FROM Genres LIMIT 3")

assert len(cursor.fetchall()) == 3
assert cursor.rowcount == 3

cursor.execute("SELECT * FROM Albums LIMIT 4")

assert len(cursor.fetchall()) == 4
assert cursor.rowcount == 4
Loading