Skip to content

Commit c410398

Browse files
Cycle 18: document rowcount after INSERT...RETURNING with a test
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent b7f14e1 commit c410398

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/integration/test_returning.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,23 @@ def test_insert_returning(self, cluster_address: str) -> None:
1717
assert row == (1, "alice")
1818
cursor.execute("DROP TABLE ret_test")
1919

20+
def test_insert_returning_rowcount(self, cluster_address: str) -> None:
21+
"""After RETURNING, rowcount reflects the number of returned rows.
22+
23+
dqlite routes RETURNING through the query path, so rowcount is
24+
len(rows) — matches SQLAlchemy's expectation for RETURNING clauses.
25+
"""
26+
with connect(cluster_address, database="test_ret_rowcount") as conn:
27+
cursor = conn.cursor()
28+
cursor.execute("CREATE TABLE rc_test (id INTEGER PRIMARY KEY, v INT)")
29+
cursor.execute(
30+
"INSERT INTO rc_test (id, v) VALUES (1, 10), (2, 20), (3, 30) RETURNING id"
31+
)
32+
rows = cursor.fetchall()
33+
assert len(rows) == 3
34+
assert cursor.rowcount == 3
35+
cursor.execute("DROP TABLE rc_test")
36+
2037
def test_insert_returning_multiple(self, cluster_address: str) -> None:
2138
"""INSERT ... RETURNING should support fetching all returned rows."""
2239
with connect(cluster_address, database="test_returning_multi") as conn:

0 commit comments

Comments
 (0)