Repository: googleapis/python-bigquery

Issue:
DB API rowcount incorrect for executemany

```
(3.9) jim@ds9:~/p/g/python-bigquery$ python
>>> from google.cloud.bigquery.dbapi import connect
>>> conn = connect()
>>> cursor = conn.cursor()
>>> cursor.executemany("select %s", [[1],[2],[3]])
>>> cursor.rowcount
1
```

Discussion:

Patch:
diff --git a/google/cloud/bigquery/dbapi/cursor.py b/google/cloud/bigquery/dbapi/cursor.py
index f74781df..c8fc4937 100644
--- a/google/cloud/bigquery/dbapi/cursor.py
+++ b/google/cloud/bigquery/dbapi/cursor.py
@@ -218,6 +218,7 @@ class Cursor(object):
                 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
@@ -230,6 +231,9 @@ class Cursor(object):
                 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.


Test patch:
diff --git a/tests/unit/test_dbapi_cursor.py b/tests/unit/test_dbapi_cursor.py
index 5afe269e..55e45325 100644
--- a/tests/unit/test_dbapi_cursor.py
+++ b/tests/unit/test_dbapi_cursor.py
@@ -612,7 +612,7 @@ class TestCursor(unittest.TestCase):
             (("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