Skip to content

Commit 7b70299

Browse files
test(e2e): verify DML cursor.rowcount against a live warehouse (#784)
End-to-end test in TestPySQLCoreSuite exercising INSERT/UPDATE/DELETE on a real Thrift warehouse and asserting cursor.rowcount reports the exact affected-row count (3/2/1), then that a following SELECT resets it to -1. Verified live on dogfood; fails with the fix reverted (rowcount stays -1). Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
1 parent 86b0c67 commit 7b70299

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

tests/e2e/test_driver.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,35 @@ def test_create_table_will_return_empty_result_set(self, extra_params):
455455
finally:
456456
cursor.execute("DROP TABLE IF EXISTS {}".format(table_name))
457457

458+
def test_dml_rowcount(self):
459+
"""cursor.rowcount reports the affected-row count for DML
460+
(INSERT/UPDATE/DELETE) instead of the hardcoded -1, and resets
461+
to -1 for a subsequent SELECT (GH #784)."""
462+
with self.cursor({}) as cursor:
463+
table_name = "table_{uuid}".format(uuid=str(uuid4()).replace("-", "_"))
464+
try:
465+
cursor.execute("CREATE TABLE {} (n INT)".format(table_name))
466+
467+
cursor.execute(
468+
"INSERT INTO {} VALUES (1), (2), (3)".format(table_name)
469+
)
470+
assert cursor.rowcount == 3, f"INSERT rowcount {cursor.rowcount!r}"
471+
472+
cursor.execute(
473+
"UPDATE {} SET n = n + 1 WHERE n >= 2".format(table_name)
474+
)
475+
assert cursor.rowcount == 2, f"UPDATE rowcount {cursor.rowcount!r}"
476+
477+
cursor.execute("DELETE FROM {} WHERE n = 1".format(table_name))
478+
assert cursor.rowcount == 1, f"DELETE rowcount {cursor.rowcount!r}"
479+
480+
# SELECT must reset rowcount to -1 (not leak the DELETE count).
481+
cursor.execute("SELECT * FROM {}".format(table_name))
482+
assert cursor.rowcount == -1, f"SELECT rowcount {cursor.rowcount!r}"
483+
assert len(cursor.fetchall()) == 2
484+
finally:
485+
cursor.execute("DROP TABLE IF EXISTS {}".format(table_name))
486+
458487
def test_get_tables(self):
459488
with self.cursor({}) as cursor:
460489
table_name = "table_{uuid}".format(uuid=str(uuid4()).replace("-", "_"))

0 commit comments

Comments
 (0)