Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get correct row count when using pyodbc cursor.executemany()

Tags:

python

sql

pyodbc

In pyodbc, cursor.rowcount works perfectly when using cursor.execute(). However, it always returns -1 when using cursor.executemany().

How does one get the correct row count for cursor.executemany()?

This applies to multiple inserts, updates, and deletes.

like image 205
Stephen K. Karanja Avatar asked Oct 31 '22 12:10

Stephen K. Karanja


1 Answers

You can't, only the last query row count is returned from executemany, at least that's how it says in the pyodbc code docs. -1 usually indicates problems with query though. If you absolutely need the rowcount, you need to either cursor.execute in a loop or write a patch for pyodbc library.

like image 85
Adam Owczarczyk Avatar answered Nov 15 '22 03:11

Adam Owczarczyk