[vox-tech] MySQL + Zope

Troy Arnold vox-tech@lists.lugod.org
Wed, 14 May 2003 11:28:17 -0700


On Wed, May 14, 2003 at 10:10:06AM -0700, David Siedband wrote:
> Hello all,
> 
> I'm trying to do an SQL insert from within Zope that makes entries in 
> two separate tables.  The data entity is a calendar event and most of 
> it's fields go in an events table, except the event date.  The event 
> date gets stored only in an index table that is linked by an event id.  
> The tricky part is to get the event ID (eid) that is auto-incremented 
> by MySQL from the first query and pass it to the second insert 
> statement.

There's a mysql function, last_insert_id() which returns the last
generated auto_increment value.  Perhaps you could call that, or perhaps
there's a zope wrapper around the same function.

For instance, in perl:
$dbh->do('some insert query');
$last_id = $dbh->{mysql_insertid};

It's a common enough thing to do that Zope oughta have something similar.

-troy