Forum OpenACS Q&A: Re: how do you get locking transactions to work?

Collapse
Posted by Derick Leony on
db_transaction should work, just make sure you use it like
db_transaction {
//step 1
//step 2
//step 3
}

and that you are using the same dbn that your db_0or1row and db_dml are using.

Cheers,

Derick

Collapse
Posted by Claudio Pasolini on
In the past I noticed that doing any db_dml within a db_foreach doesn't work as a transaction, because they use a different handle.

If this is the case simply get your rows with a db_list_of_lists and then loop over them with a foreach.

Collapse
Posted by Andrew Piskorski on
Derick's and Claudio's comments are exactly right, you should never use more than one database handle within a single db_transaction block. Breaking that rule is a problem that periodically pops up here in the forums. A good fix would be to implement this: db_transaction should throw error for multiple database handles.

It's not clear to me that this actually had anything directly to do with Robert's problem, but it's good advice regardless.

Claudio, would you mind if you add this comment to the db_dml or db_foreach procedure definition / api documentation? This is a valuable piece of information that should get in there.