Bug #1582 | mysql_insert_id differs from manual | ||
---|---|---|---|
Submitted: | 16 Oct 2003 21:58 | Modified: | 3 Feb 2004 11:46 |
Reporter: | L. Blunt Jackson | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S3 (Non-critical) |
Version: | 4.0.15 | OS: | Linux (linux / x86) |
Assigned to: | Paul DuBois | CPU Architecture: | Any |
[16 Oct 2003 21:58]
L. Blunt Jackson
[17 Oct 2003 3:49]
Sergei Golubchik
It's a documentation issue. A) I wasn't able to repeat this. select and updates that did not affect auto_increment column always returned 0 in mysql_insert_id() for me. B) No, manual specifies that updates to a table that do not generate auto_increment value (not "invokes auto_increment behaviour") will set mysql_insert_id() to 0. That's what happened to me too. Your examples: create table test (test_id int not null auto_increment primary key, test_text varchar(10)); insert into test (test_text) values ('Hello.'); > fetch value with mysql_insert_id returns '1'. insert into test (test_id, test_text) values ('40', 'Hi 40'); > fetch value with mysql_insert_id: expected '1', received '40'; ==> wrong. new auto_increment value for a column was generated. You can easily see it by inserting NULL in the column - new auto_increment value will be 41. That is your insert indeed affected auto_increment value for a column. update test set test_text = 'Yo!' where test_id = '1'; > fetch value with mysql_insert_id: expectations unclear due to contradictory documentation. actual return value: 0. ==> correct, auto_increment value was not affected. On inserting NULL new auto-generated auto_increment value will not be affected by the above upfate. Probably, we need to clarify this in the manual, thanks for pointing this out.
[3 Feb 2004 11:46]
Michael Widenius
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant product(s).