List:MySQL ODBC« Previous MessageNext Message »
From:Paul DuBois Date:May 5 2001 10:32pm
Subject:Re: Results from Insert
View as plain text  
At 9:33 PM -0800 4/23/01, Joshua J. Kugler wrote:
>Yes, you can, but if someone else inserted a row between the time you insert
>and the time you select, it won't be accurate.  You run into a race condition.

That's incorrect, actually.  LAST_INSERT_ID() is returned on a
connection-specific basis.  You get back your own previous AUTO_INCREMENT
value, even if someone else creates a new record in the meantime.  So
the original advice (SELECT LAST_INSERT_ID()) is correct.

>
>Yeah, I know, a pain.  Let me know if you figure anything out. :)
>
>j----- k-----
>
>On Monday 23 April 2001 20:56, Andrés Becerra wrote:
>>  how about this then?
>>
>>  insert into tbWhatever (...) values (...)
>>  select max(auto_increment_field) from tbWhatever
>>
>>  -----Original Message-----
>>  From: Joshua J. Kugler [mailto:isd@stripped]
>>  Sent: Tuesday, April 24, 2001 12:36 AM
>>  To: Andrés Becerra
>>  Subject: Re: Results from Insert
>>
>>
>>  The problem is, this doesn't wokr in a Microsoft Jet workspace, only in an
>>  ODBCDirect work space (if using Access).  But using an ODBCDirect work
>>  space breaks other things.  So, it's a catch 22.
>>
>>  j----- k-----
>>
>>  On Monday 23 April 2001 20:00, you wrote:
>>  > select LAST_INSERT_ID() as NewCustomerID
>>  >
>>  > and then use the 1st field in the recordset that gets returned
>>  >
>>  > -----Original Message-----
>  > > From: Julian Lynch [mailto:julian.lynch@stripped]
>>  > Sent: Monday, April 23, 2001 11:39 PM
>>  > To: myodbc@stripped
>>  > Subject: Results from Insert
>>  >
>>  >
>>  > When performing an insert on a table that has an auto_increment primary
>>
>>  key
>>
>>  > field, I would like to know what the primary key value of the row is. I
>>  > do not know hoe to do this without the support of something like stored
>>  > procedures etc. Does anybody know how this may be done?
>>  >
>>  > Thanks
>  > > Julian Lynch


-- 
Paul DuBois, paul@stripped
Thread
Results from InsertJulian Lynch24 Apr
  • RE: Results from InsertAndrés Becerra24 Apr
RE: Results from InsertAndrés Becerra24 Apr
  • Re: Results from InsertJoshua J. Kugler24 Apr
    • Re: Results from InsertMichael Widenius24 Apr
      • Re: Results from InsertJoshua J. Kugler24 Apr
    • Re: Results from InsertPaul DuBois6 May