Skip to content

Commit aeadc8c

Browse files
author
Jim Fulton
authored
fix: executemany rowcount only reflected the last execution (#660)
1 parent 615d139 commit aeadc8c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

google/cloud/bigquery/dbapi/cursor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ def executemany(self, operation, seq_of_parameters):
218218
Sequence of many sets of parameter values.
219219
"""
220220
if seq_of_parameters:
221+
rowcount = 0
221222
# There's no reason to format the line more than once, as
222223
# the operation only barely depends on the parameters. So
223224
# we just use the first set of parameters. If there are
@@ -230,6 +231,9 @@ def executemany(self, operation, seq_of_parameters):
230231
self._execute(
231232
formatted_operation, parameters, None, None, parameter_types
232233
)
234+
rowcount += self.rowcount
235+
236+
self.rowcount = rowcount
233237

234238
def _try_fetch(self, size=None):
235239
"""Try to start fetching data, if not yet started.

tests/unit/test_dbapi_cursor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ def test_executemany_w_dml(self):
612612
(("test",), ("anothertest",)),
613613
)
614614
self.assertIsNone(cursor.description)
615-
self.assertEqual(cursor.rowcount, 12)
615+
self.assertEqual(cursor.rowcount, 24) # 24 because 2 * 12 because cumulatve.
616616

617617
def test_executemany_empty(self):
618618
from google.cloud.bigquery.dbapi import connect

0 commit comments

Comments
 (0)