Skip to content

Commit 34a9d6d

Browse files
Correct the documented threadsafety level and rowcount behaviour
The module exports threadsafety=2 (connections may be shared across threads, cursors may not), but the class docstring, a cursor comment, and DEVELOPMENT.md still described it as 1. Update them to match. Also document in the rowcount property docstrings that a SELECT reports the produced row count rather than -1, since dqlite buffers the full result. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6a5fc4c commit 34a9d6d

4 files changed

Lines changed: 12 additions & 7 deletions

File tree

DEVELOPMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,5 @@ for.
9696
This package implements the DB-API 2.0 specification (PEP 249):
9797

9898
- `apilevel = "2.0"`
99-
- `threadsafety = 1` (threads may share module, not connections)
99+
- `threadsafety = 2` (threads may share module and connections, not cursors)
100100
- `paramstyle = "qmark"` (question mark placeholders)

src/dqlitedbapi/aio/cursor.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,9 @@ def completed_iterations(self) -> int:
164164

165165
@property
166166
def rowcount(self) -> int:
167-
"""Rows affected by the last execute, or -1 if unknown/inapplicable."""
167+
"""Rows affected (DML) or, for SELECT, rows produced (dqlite buffers the
168+
full result, unlike stdlib's -1); -1 if unknown/inapplicable.
169+
"""
168170
return self._rowcount
169171

170172
@property

src/dqlitedbapi/connection.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -810,9 +810,10 @@ class Connection:
810810
mid-batch cancel without a surrounding BEGIN persists the completed
811811
iterations.
812812
813-
Thread-affinity: ``check_same_thread=True`` (default) enforces the
814-
threadsafety=1 contract — foreign-thread calls raise
815-
ProgrammingError. ``check_same_thread=False`` relaxes the
813+
Thread-affinity: ``threadsafety`` is 2 (threads may share the module
814+
and connections, but not cursors). ``check_same_thread=True``
815+
(default) confines a connection to its creating thread — foreign-thread
816+
calls raise ProgrammingError; ``check_same_thread=False`` relaxes the
816817
cross-thread check (the wire is already serialised by ``_op_lock``).
817818
Under it, the contract matches stdlib sqlite3: **share connections
818819
across threads; create one cursor per thread** (per-cursor result

src/dqlitedbapi/cursor.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,9 @@ def description(self) -> _Description:
937937

938938
@property
939939
def rowcount(self) -> int:
940-
"""Rows affected by the last execute; -1 if unknown / not applicable."""
940+
"""Rows affected (DML) or, for SELECT, rows produced (dqlite buffers the
941+
full result, unlike stdlib's -1); -1 if unknown / not applicable.
942+
"""
941943
return self._rowcount
942944

943945
@property
@@ -998,7 +1000,7 @@ def arraysize(self, value: int) -> None:
9981000
# Closed-state guard on the SETTER only; the getter stays
9991001
# permissive like peer drivers.
10001002
self._check_closed()
1001-
# Enforce threadsafety=1 affinity. _check_thread short-circuits
1003+
# Enforce the default per-thread affinity. _check_thread short-circuits
10021004
# under check_same_thread=False, where the cursor-per-thread
10031005
# sub-contract becomes the caller's responsibility.
10041006
self._connection._check_thread()

0 commit comments

Comments
 (0)