[Zope] ZSQL Method Question

Peter Bengtsson peter at fry-it.com
Tue Jul 18 04:33:09 EDT 2006


What if you have 1,000,000 requests/sec?
What if between the INSERT and the LAST_INSERT_ID() another INSERT is made?

I use PostgreSQL and with postgres you can always ask the sequence what 
the next id is going to be. It goes something like this::

next_id = context.GetNextId()[0].next_id
context.SQLInsertUser(uid=next_id, name='Peter')

where 'GetNextId' is a ZSQL method that looks like this::

<params></params>
SELECT NEXTVAL('users_uid_seq') AS next_id

Cliff Ford wrote:
> This is how it works for MySQL:
> 
> insert into org (org_name, org_phone) values ('x', 'y')
> <dtml-var sql_delimiter>
> select LAST_INSERT_ID() as org_id
> 
> You have to have the select LAST_INSERT_ID call in the same query as the 
> insert, and you have to have the sql_delimiter.
> 
> I assume you know that the x and y values should be <sql-var ...> types.
> 
> Cliff
> 
> 
> Benjamin Menking wrote:
>> New to python/Zope, old-timer on PHP....
>>
>> I'm using MySQL and a ZSQL method to insert data into the database.  ex:
>>
>>    insert into org (org_name, org_phone) values ('x', 'y')
>>
>> What I'm trying to figure out is that org_id (also part of the org 
>> table, but not specified in the sql statement) is an auto_increment 
>> primary key field and in PHP I can use mysql_insert_id() to find out 
>> what org_id was set to after the mysql_query() call.
>>
>> Is there a way to retrieve that value with ZSQL method, or must I use 
>> some other mechanism?
>>
>> Thanks!
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> Zope maillist  -  Zope at zope.org
>> http://mail.zope.org/mailman/listinfo/zope
>> **   No cross posts or HTML encoding!  **
>> (Related lists -  http://mail.zope.org/mailman/listinfo/zope-announce
>>  http://mail.zope.org/mailman/listinfo/zope-dev )
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
> http://mail.zope.org/mailman/listinfo/zope-dev )
> 

-- 
Peter Bengtsson,
work www.fry-it.com
home www.peterbe.com
hobby www.issuetrackerproduct.com


More information about the Zope mailing list