Jerry, in the code above you're using two different database handles
both within a db_transaction block, right? Are the semantics of that
even defined in the db_* API? What is it really doing? I bet only
the first handle is getting a "begin transaction", the second is not
doing anything special and is still in autocommit mode.
But either way it doesn't matter, if the intention is that the whole
db_transaction block be one atomic transaction, that's impossible, as
you're using two handles. Hm, probably db_transaction should notice
this and throw an error... This seems like a good example of when the
db_transaction syntactic sugar is noticeably more confusing than the
simple "begin transaction ... end transaction" commands that are going
on underneath.
I don't think db_transaction needs any form of timeout or deadlock
detection. What it needs is to throw an error when people try to use
two handles (to the same schema) within a db_transaction block, as two
handles, by definition, cannot ever be part of one transaction. Even
if using two handles within a db_transaction block happens to
accidentally do what you want in any particuar case I'd still call it
a programming error, and likely to make future maintenance of any such
code rather confusing.
I'm still wondering whether we ought to simply turn off all
use of more than one handle at once by default. I haven't yet seen
any case where using two database handles at once (to the same schema)
was actually a good idea. Seems normally we only do it by accident...