List:MySQL++« Previous MessageNext Message »
From:Steve Povilaitis Date:October 10 2005 5:47pm
Subject:problem saving and retrieving an AUTO_INCREMENT value using MySQL variable and LAST_INSERT_ID()
View as plain text  
Hi,

This is more of a mySQL question but I hope someone can help me out.

I'm trying to save the most recent AUTO_INCREMENT value from a parent table
to use, later, in multiple records of a child table that also has an
AUTO_INCREMENT field. My relevant code:

// In the parent class
queryParent << "SET @sim_id = LAST_INSERT_ID()";
queryParent.execute();  

// In the child class get the value of the last auto_inc field from the
parent and insert into child

queryChild << "INSERT INTO child (simid) values (@simid)";
queryChild.execute();

Yet looking at the child table each record has a NULL value for simid, where
I would expect the value from the parent table to be. So either I'm not
setting or retrieving the MySQL variable properly. Any ideas? 

Thanks in advance!


This e-mail and any attachments are provided through AEgis 
Technologies' e-mail services and may contain company sensitive and/or 
privileged information. If you are not the intended recipient, please 
notify the sender immediately by return e-mail, delete this e-mail and 
destroy any copies. Any dissemination or use of this information by a 
person other than the intended recipient is unauthorized and may be 
illegal.
Thread
problem saving and retrieving an AUTO_INCREMENT value using MySQL variable and LAST_INSERT_ID()Steve Povilaitis10 Oct
RE: problem saving and retrieving an AUTO_INCREMENT value using MySQL variable and LAST_INSERT_ID()Steve Povilaitis10 Oct
  • Re: problem saving and retrieving an AUTO_INCREMENT value using MySQLvariable and LAST_INSERT_ID()Warren Young10 Oct
  • Re: problem saving and retrieving an AUTO_INCREMENT value using MySQLvariable and LAST_INSERT_ID()Ovidiu Bivolaru10 Oct