Skip to content

Commit

Permalink
Fixed rowcount for executemany() when connected
Browse files Browse the repository at this point in the history
to a MySQL database server.
  • Loading branch information
9EOR9 committed Aug 16, 2021
1 parent a614b9f commit d3d1cfc
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion mariadb/cursors.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self, connection, **kwargs):
self._prepared= False
self._prev_stmt= None
self._force_binary= None
self._rowcount= 0

self._parseinfo= None
self._data= None
Expand Down Expand Up @@ -160,6 +161,7 @@ def callproc(self, sp: str, data=()):
if len(data):
params= ("?," * len(data))[:-1]
statement= "CALL %s(%s)" % (sp, params)
self._rowcount= 0
self.execute(statement, data)

def _parse_execute(self, statement:str, data=()):
Expand Down Expand Up @@ -222,6 +224,7 @@ def execute(self, statement: str, data=(), buffered=False):

# Parse statement
do_parse= True
self._rowcount= 0

if buffered:
self.buffered= True
Expand Down Expand Up @@ -301,15 +304,18 @@ def executemany(self, statement, parameters):
# by looping
# TODO: insert/replace statements are not optimized yet, rowcount not set
if not (self.connection.server_capabilities & (CLIENT.BULK_OPERATIONS >> 32)):
count= 0
for row in parameters:
self.execute(statement, row)
#todo: rowcount ?!
count+= self.rowcount
self._rowcount= count
else:
# parse statement
self._parse_execute(statement, parameters[0])
self._data= parameters
self.is_text= False
self._execute_bulk()
self._rowcount= 0

def _fetch_row(self):
"""
Expand Down Expand Up @@ -471,6 +477,12 @@ def __exit__(self, exc_type, exc_val, exc_tb):
def __del__(self):
self.close()

@property
def rowcount(self):
if self._rowcount > 0:
return self._rowcount
return super().rowcount

@property
def sp_outparams(self):
"""
Expand Down

0 comments on commit d3d1cfc

Please sign in to comment.