dbTalk Databases Forums  

Re: problem saving and retrieving an AUTO_INCREMENT value using MySQL

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss Re: problem saving and retrieving an AUTO_INCREMENT value using MySQL in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Warren Young
 
Posts: n/a

Default Re: problem saving and retrieving an AUTO_INCREMENT value using MySQL - 10-10-2005 , 01:49 PM






Steve Povilaitis wrote:
Quote:
Thanks for the prompt reply! I also noticed another problem. From reading
the mySQL documentation variable's aren't persistent across connections.
Since I was using separate connections for the parent and child classes the
variable isn't visible between the two. Thanks again for your help!
The whole point of this feature is for your code to save the ID right
after you insert the new record. You could then pass it to any child
classes that need it.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #2  
Old   
Ovidiu Bivolaru
 
Posts: n/a

Default Re: problem saving and retrieving an AUTO_INCREMENT value using MySQL - 10-10-2005 , 02:10 PM






Hi Steve,

Keep the the insert_id() after each executed QueryParent in a variable
which you can use later for storing in child queries.

PS: I will always forget to use Reply to All and my initial reply was
not sent to the list too. Sorry!

Regards,
Ovidiu

Steve Povilaitis wrote:

Quote:
Thanks for the prompt reply! I also noticed another problem. From reading
the mySQL documentation variable's aren't persistent across connections.
Since I was using separate connections for the parent and child classes the
variable isn't visible between the two. Thanks again for your help!

Steve



-----Original Message-----
From: Ovidiu Bivolaru [mailtovidiu (AT) targujiu (DOT) rdsnet.ro]
Sent: Monday, October 10, 2005 2:13 PM
To: Steve Povilaitis
Subject: Re: problem saving and retrieving an AUTO_INCREMENT
value using MySQL variable and LAST_INSERT_ID()

Hi Steve,

You could use: Connection::insert_id().

Regards,
Ovidiu

Steve Povilaitis wrote:



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.







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.



--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.