[CONPY-105] Change behavior of cursor->rowcount and cursor->lastrowid Created: 2020-08-13  Updated: 2020-08-16  Resolved: 2020-08-14

Status: Closed
Project: MariaDB Connector/Python
Component/s: DBAPI 2.0
Affects Version/s: 1.0.0
Fix Version/s: 1.0.1

Type: New Feature Priority: Major
Reporter: Georg Richter Assignee: Georg Richter
Resolution: Fixed Votes: 0
Labels: sqlalchemy

Issue Links:
Blocks
blocks CONPY-77 Add mariadb dialect to sqlalchemy Closed

 Description   

For compatibility with SQLAlchemy (close_with_result) values for lastrowid and rowcount should be retrieved immediately after execute/executemany, and stored in cursor->lastrowid and cursor->rowcount.

When using unbuffered result sets, rowcount should be updated per fetch.

Also the behaviour of rowcount and lastrowid should be changed:

rowcount:
In case of an error, or if statement wasn't executed rowcount should be -1 (see PEP-249)

  • For DML statements the number of affected rows returned in OK packet by server:
    • > 0 for DML statements which modify or insert, e.g. ALTER TABLE or CREATE TABLE .. SELECT FROM
    • otherwise 0
  • For DQL statement
    • if field_count > 0: number of rows returned
    • otherwise affected rows returned in OK packet by server.

lastrowid:

  • if server returns no value (0) for last_insert_id, lastrowid should be None.
  • if last_insert_id is > 0, return it's value


 Comments   
Comment by Georg Richter [ 2020-08-14 ]

Fixed rev. afea68191003aa92231879a9f32f17074ad9d6bf

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