[Zope] Returning incremented id from mysql query?
Ed Leafe
ed@leafe.com
Wed, 14 Aug 2002 19:46:25 -0400
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