[Zope-DB] Are transactions/atomicity implicit in ZSQL Methods ? + questions

kapil thangavelu k_vertigo@yahoo.com
Wed, 20 Mar 2002 09:25:28 -0800

On Wednesday 20 March 2002 10:02 am, you wrote:
> Hello,
> I need to make a ZSQL method that inserts data in a table this way:
> 1) first, generate a new ID with something like SELECT MAX(ID)+1 AS my_id
> FROM ...
> 2) then, INSERT with the ID previously generated ( is INSERT INTO ...
> VALUES (<dtml-var my_id>.... the right way to do this ?)

it would be much better to use a sequence. the above is only safe in a 
transaction serialized mode. 

> 3) display my_id to the user for future reference.
> I'm not sure how to do 3) : how do I pass my_id back to the original DTML
> document (which calls the ZSQL method with dtml-call) ?
> Also (main question), is there something particular to do to ensure
> SELECT+INSERT is done in a single transaction, thus avoiding concurrency
> problems ?

zope's integration with databases depends on whats supported by the database 
adapter. if the adapter supports transactions than zope will commit 
transactions involving any changed persistent objects within zope and the dbs 
at the end of a request.