{"issue":{"state":"open","created_at":"2011-12-07T23:33:45Z","updated_at":"2011-12-07T23:33:45Z","user":{"gravatar_id":"f79ab2878590f876e266645713cb60d5","id":36335,"url":"https://api.github.com/users/uberbrady","login":"uberbrady","avatar_url":"https://secure.gravatar.com/avatar/f79ab2878590f876e266645713cb60d5?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-140.png"},"comments":0,"body":"In an environment where you aren't sure about what order your queries will execute, using MySQL's \"LAST_INSERT_ID()\" to determine which auto_increment value was used doesn't seem to work.\r\n\r\n\r\n```js\r\n#!/usr/local/bin/node\r\n\"use strict\";\r\n\r\n// Test table (you must create this): \r\n// create table foo (id integer not null auto_increment primary key,val text);\r\n\r\n\r\nvar util = require('util');\r\nvar sys=require('sys');\r\n\r\nvar username='USERNAME',dbname='DBNAME';\r\n\r\nvar conn = new require(\"mysql\").createClient({user: username,database: dbname});\r\n\r\nconn.query(\"INSERT INTO foo (val) VALUES ('string1')\",function (err,results,fields) {\r\n\tconn.query(\"SELECT LAST_INSERT_ID()\",function (err,results,fields) {\r\n\t\tconsole.log(\"string1: \",results);\r\n\t});\r\n});\r\n\r\nconn.query(\"INSERT INTO foo (val) VALUES ('second')\",function (err,results,fields) {\r\n\tconn.query(\"SELECT LAST_INSERT_ID()\",function (err,results,fields) {\r\n\t\tconsole.log(\"second: \",results);\r\n\t});\r\n});\r\n```\r\n\r\nFrom the above code, I would expect to see:\r\n\r\nstring1:  [ { 'LAST_INSERT_ID()': 1 } ]\r\nsecond:  [ { 'LAST_INSERT_ID()': 2 } ]\r\n\r\nOr maybe even\r\n\r\nstring1:  [ { 'LAST_INSERT_ID()': 2 } ]\r\nsecond:  [ { 'LAST_INSERT_ID()': 1 } ]\r\n\r\nBut instead I get\r\n\r\nstring1:  [ { 'LAST_INSERT_ID()': 2 } ]\r\nsecond:  [ { 'LAST_INSERT_ID()': 2 } ]\r\n\r\nThis makes using an auto_increment  column in a web application difficult.\r\n\r\nThe only fix I can think of (since SQL statement queueing is a necessity) is to permit multiple statement execution.\r\n\r\nThis *may* be a documentation bug, if it will work when you chain the statements - if so, the documentation should be updated to state that.\r\n","assignee":null,"id":2481777,"pull_request":{"patch_url":null,"html_url":null,"diff_url":null},"labels":[],"number":152,"title":"Query queing makes auto_increment columns hard to use","html_url":"https://github.com/felixge/node-mysql/issues/152","closed_at":null,"url":"https://api.github.com/repos/felixge/node-mysql/issues/152","milestone":null},"action":"opened"}