[Zope-DB] working with zope rdbms transaction mgmt

Dieter Maurer dieter at handshake.de
Fri Jul 9 14:01:57 EDT 2004


Jim Abramson wrote at 2004-7-1 17:19 -0400:
>My question is, if i grab a reference to the cursor from some db connection inside a python script, and do a bunch of statements directly on this cursor, and something goes wrong on the nth statement (i.e. uncaught Exception), should I expect all of the statements performed using that cursor up to that point will be automatically rolled back?
>
>If yes, next question is, if I trap an exception that's raised during the nth statement, and proceed (using the same cursor) to the (n+1)th statement, and the REQUEST wraps up cleanly, should I expect all of the successful statements will be automatically committed?

What you do may result in undefined behaviour...

  When you use the official DA API, the DA registers itself
  with Zope's transaction.
  Due to this registration Zope's transaction can inform the
  DA when it commits/rolls back. The DA then issues
  a commit/rollback to the database.

  When you simply steal (and use) the cursor, the DA may or may
  not be registered with Zope's transaction (depending
  on whether the request used the official API as well).
  If it is not registered, the database transaction will
  not follow the Zope transaction...
  Chaos is the result...

  You can call "register" (or similar) explicitly on the
  DA -- if you feel a need to use its cursor directly.
  Look at the "query" method implementation, for details.

-- 
Dieter


More information about the Zope-DB mailing list