[MDEV-16593] mysql_stmt_insert_id returns first generated id when using MYSQL_TYPE_NULL Created: 2018-06-27  Updated: 2019-10-11  Resolved: 2019-10-11

Status: Closed
Project: MariaDB Server
Component/s: Data Manipulation - Insert, Prepared Statements
Affects Version/s: 10.2.16, 10.3.7
Fix Version/s: 5.5.66

Type: Bug Priority: Major
Reporter: Georg Richter Assignee: Oleksandr Byelkin
Resolution: Not a Bug Votes: 0
Labels: None

Attachments: File bulk_insert_id.c    

 Description   

When inserting values into a table with auto_increment column via bulk operation, the result of mysql_stmt_insert_id() differs:
In case buffer_type MYSQL_TYPE_NULL is used, or indicator variable was set to STMT_INDICATOR_IGNORE the values of first inserted row will be returned.

Output from attached test case:

 Insert id with buffer_type MYSQL_TYPE_LONG: 2
 Max value for t1.a=2
 Insert id with buffer_type MYSQL_TYPE_NULL: 1
 Max value for t1.a=2
 Insert id with buffer_type STMT_INDICATOR_NULL: 1
 Max value for t1.a=2



 Comments   
Comment by Oleksandr Byelkin [ 2019-10-11 ]

It is according to our documentation https://mariadb.com/kb/en/library/last_insert_id/
if statement insert several rows, mysql_stmt_insert_id is assigned with first insert value

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