[CONPY-225] "Cursor.rowcount" and "Cursor.affected_rows" both return the same value, return 0 for UPDATE queries. Created: 2022-10-05 Updated: 2022-10-07 Resolved: 2022-10-07 |
|
| Status: | Closed |
| Project: | MariaDB Connector/Python |
| Component/s: | DBAPI 2.0, Documentation |
| Affects Version/s: | 1.1.4 |
| Fix Version/s: | 1.1.5 |
| Type: | Bug | Priority: | Major |
| Reporter: | Hunter LaFaille | Assignee: | Georg Richter |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Environment: |
Windows 11, PyCharm IDE with a virtualenv. Connecting to an Ubuntu LTS server with MariaDB 1:10.7.3+maria~focal running in Docker. |
||
| Python Version: | 3.10.7 |
| Description |
|
I have a class that handles my database connection and pooling, above is the output directly from an instance of that class. I'm very confused as to why 'rowcount' and 'affected_rows' both return the same result, and neither return the correct rows when running 'UPDATE' on a row. The above is also called before I return the connection back to the pool. At first, I figured it was just MariaDB ignoring the UPDATE because the row wouldn't change. No matter the state of the existing data, both 'affected_rows' and 'rowcount' both return 0. Edit: My code now randomly works, I apologize for any time I might've wasted. I do not see a clear way to close this issue or delete it. Thank you. |
| Comments |
| Comment by Georg Richter [ 2022-10-06 ] | |||
|
As stated in PEP-249 you should use rowcount to determine the number of rows in a result set or the number of rows from a INSERT/UPDATE/DELETE statement. Affected_rows was added for compatibility with other drivers and needs to be fixed. For UPDATE/DELETE operations rowcount will return 0, if no row was affected, e.g.
You can change this behavior, by specifying client_flag when connecting to your server:
|