Bug #11993 MQB always returns '0' with LAST_INSERT_ID().
Submitted: 18 Jul 2005 3:21 Modified: 18 Jul 2005 11:19
Reporter: [ name withheld ] Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Query Browser Severity:S3 (Non-critical)
Version:1.1.12 OS:2.6.12-gentoo-r6
Assigned to: CPU Architecture:Any

[18 Jul 2005 3:21] [ name withheld ]
Description:
INSERT INTO `polls` (`question`) VALUES('test');

SELECT LAST_INSERT_ID() FROM `polls`;
# Returns one row with one column with the value of '0'

show create table `polls`;
# Returns the following:

CREATE TABLE `polls` (
  `ID` int(11) NOT NULL auto_increment,
  `question` varchar(255) NOT NULL default '',
  `result` enum('aye','nay') NOT NULL default 'nay',
  `status` enum('open','closed') NOT NULL default 'open',
  `asker` varchar(50) NOT NULL default '',
  PRIMARY KEY  (`ID`)
) TYPE=MyISAM

select max(ID) from polls;
# Returns one row with one column with the value of '1'

select * from polls where question='test';
# Returns the following:

ID --- question --- result --- status --- asker
1  --- test     --- nay    --- open   --- NULL

select last_insert_id();
# Returns one row with one column with the value of '0'

Works on command line and everywhere else.

How to repeat:
Follow steps above.

Suggested fix:
Maybe the connection isn't the same somehow? That's the only thing I would think that would cause such a problem as LAST_INSERT_ID is connection-specific.
[18 Jul 2005 11:19] Aleksey Kishkin
hi. if you use query tab, that qb will use separate connection for each query.
You must use script tab for some sequences of commands.