- Fix crash in `~Cursor.executemany()` with no input sequence
(:ticket:`#179`).
+- Fix wrong `~Cursor.rowcount` after an `~Cursor.executemany()` returning no
+ rows (:ticket:`#178`).
Current release
# Override rowcout for the first result. Calls to nextset() will change
# it to the value of that result only, but we hope nobody will notice.
# You haven't read this comment.
- self._rowcount = nrows or -1
+ self._rowcount = nrows
self._last_query = query
for cmd in self._conn._prepared.get_maintenance_commands():
assert cur.rowcount == 2
+def test_executemany_rowcount_no_hit(conn, execmany):
+ cur = conn.cursor()
+ cur.executemany("delete from execmany where id = %s", [(-1,), (-2,)])
+ assert cur.rowcount == 0
+ cur.executemany("delete from execmany where id = %s", [])
+ assert cur.rowcount == 0
+ cur.executemany(
+ "delete from execmany where id = %s returning num", [(-1,), (-2,)]
+ )
+ assert cur.rowcount == 0
+
+
@pytest.mark.parametrize(
"query",
[
assert cur.rowcount == 2
+async def test_executemany_rowcount_no_hit(aconn, execmany):
+ cur = aconn.cursor()
+ await cur.executemany("delete from execmany where id = %s", [(-1,), (-2,)])
+ assert cur.rowcount == 0
+ await cur.executemany("delete from execmany where id = %s", [])
+ assert cur.rowcount == 0
+ await cur.executemany(
+ "delete from execmany where id = %s returning num", [(-1,), (-2,)]
+ )
+ assert cur.rowcount == 0
+
+
@pytest.mark.parametrize(
"query",
[