Page 1 of 1

How to retrieve id number when inserting new record

Posted: Mon Aug 26, 2002 4:40 am
by 9902468
I'msaving a new order and I need the id number of the order, so that I can later add more things to this order.

Is this bulletproof?

Code: Select all

start transaction;
execute insert;
if (insert succesfull){
 execute select current(sequence_name) as number;
  if (select succesfull){
        commit;
  }else{
        rollback;
        (error handling)
  } 

}else{
  rollback;
  (error handling)
}
i'm worried that if there are two or more new order creations at the same time, will I get the right number for every order?

-9902468

According to MySQL

Posted: Sun Sep 15, 2002 12:23 pm
by EricS
According to MySQL, LAST_INSERT_ID is supposed to return the last auto_increment value for the table specified on a session basis. I'm guessing that if two different visitors create an entry at the same time, then each will get back their own ID.

If anyone one else knows for sure, let us know, I'm currently in the same problem you are.