Hmm, just did some reading on last_insert_id, and it says that it works on a per-connection basis. How are Zope's connections handled? Is it simply one connection that various SQL scripts can use when they need it? How about if a single SQL method contained multiple statements? Will these statements all be fed into the connection at once, or is there a possibility of another statement from another file sneaking in between two of them. -----Original Message----- From: Ed Leafe [mailto:ed@leafe.com] Sent: August 14, 2002 8:46 PM To: Alec Munro Cc: zope@zope.org Subject: Re: [Zope] Returning incremented id from mysql query? On Wednesday, August 14, 2002, at 07:21 PM, Alec Munro wrote:
I'm looking for a way to get the id generated when I insert data into a table with an auto-incremented key? I've found vague references to this, but assuming I do an insert from a python script, calling an SQL
method like: container.SQL.insertSomething(name="bob") how would I get the id.
Thanks very much, hope someone can help me with this.
I have a python script that I call after inserting a new record; it takes the name of the table as its parameter, named 'tcTable'. The script reads: laRes = context.lastInsertID(tcTable=tcTable) lastID = laRes[0][0] return lastID 'lastInsertID' is a Z SQL method that also takes the name of the table as a parameter. Its code is: select last_insert_id() from <dtml-var tcTable> Note that this syntax is specific to MySQL; other databases have similar calls to retrieve the last created ID. ___/ / __/ / ____/ Ed Leafe http://leafe.com/ http://foxcentral.net