Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: executemany rowcount only reflected the last execution #660

Merged
merged 1 commit into from
May 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions google/cloud/bigquery/dbapi/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ def executemany(self, operation, seq_of_parameters):
Sequence of many sets of parameter values.
"""
if seq_of_parameters:
rowcount = 0
# There's no reason to format the line more than once, as
# the operation only barely depends on the parameters. So
# we just use the first set of parameters. If there are
Expand All @@ -230,6 +231,9 @@ def executemany(self, operation, seq_of_parameters):
self._execute(
formatted_operation, parameters, None, None, parameter_types
)
rowcount += self.rowcount

self.rowcount = rowcount

def _try_fetch(self, size=None):
"""Try to start fetching data, if not yet started.
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_dbapi_cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ def test_executemany_w_dml(self):
(("test",), ("anothertest",)),
)
self.assertIsNone(cursor.description)
self.assertEqual(cursor.rowcount, 12)
self.assertEqual(cursor.rowcount, 24) # 24 because 2 * 12 because cumulatve.

def test_executemany_empty(self):
from google.cloud.bigquery.dbapi import connect
Expand Down