[CONPY-67] cursor.rowcount returns 0 after a SELECT query that produces 1 row Created: 2020-05-27  Updated: 2020-10-07  Resolved: 2020-10-07

Status: Closed
Project: MariaDB Connector/Python
Component/s: Generic
Affects Version/s: 0.9.59
Fix Version/s: 1.0.0

Type: Bug Priority: Minor
Reporter: Serge Rogatch Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows 10 64-bit, Python 3.8.3, MariaDB 10.4 (x64), MariaDB Connector/C 3.1.7



 Description   

After cursor.execute() for a few SELECT queries I am always getting cursor.rowcount==0. The documentation here https://github.com/mariadb-corporation/mariadb-connector-python/wiki/cursor.md says "... the number of rows that the last execute*() produced (for DQL statements like SELECT) ..."



 Comments   
Comment by Georg Richter [ 2020-05-27 ]

I compared the result with other drivers, the correct value should be -1 instead of 0 if cursor is unbuffered and now rows were fetched before:

>>> import mariadb
>>> 
>>> conn= mariadb.connect(user="georg", unix_socket="/tmp/mysql.sock")
>>> cursor=conn.cursor()
>>> cursor.execute("SELECT 1")
>>> # should be -1
>>> cursor.rowcount
0
>>> rows= cursor.fetchall()
>>> cursor.rowcount
1
>>> cursor=conn.cursor(buffered=True)
>>> cursor.execute("SELECT 1")
>>> cursor.rowcount
1

Comment by Serge Rogatch [ 2020-05-27 ]

Thanks for fixing this in the code. However, I believe the documentation should also say about the cases of a buffered and unbuffered cursor. When reading the docs I got the impression that the function always returns the row count, because there wasn't a hint about an unbuffered cursor.

Comment by Georg Richter [ 2020-05-27 ]

rev. e58caef84cb59d78ba6eb2263b8d32cdaa9ed4bd

Generated at Thu Feb 08 03:30:00 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.