Database Sessions and Transactions

Paul Boddie paul at
Mon Oct 22 12:32:12 CEST 2001

"DeepBlue" <DeepBlue at> wrote in message news:<tt0os832km0dbb at>...
> I am working on a CGI program in Python that connects to an Oracle database.
> I am wondering on how to implement a transaction that belongs to a database
> connection so that everything that belongs to the transaction can be rolled
> back.

Assuming that there isn't anything that the CGI program talks to,
between itself and the database system, which holds the connection
object and keeps the connection open...

> In other words, the scope of the rollback is NOT the database connection BUT
> the transaction that is defined from within the database connection. appear to want to be able to open a connection by instantiating
a connection object, explicitly define a transaction, do some work,
suspend the transaction as you close the connection, and then upon a
subsequent invocation of your CGI program, re-open the connection and
resume the transaction.

Is this a correct summary of your intentions?

> Please note that Python DB API 2 talks of a transaction as belonging to the
> scope of the database connection, and not something that can be created
> independently from the Connection.

That is my understanding. If you close a connection object, the DB-API
module should perform a rollback of any open transaction (depending on
various options, but this is generally the case).

> Also, I can find no reference in Python DB API 2 to Sessions.  How do we
> manage different sessions/connections?

There will definitely be people who know more about this than I do,
but you should subscribe to the DB-SIG mailing list and post your
question there - you can find the subscription page from, of course. I remember that there was one person
who was interested in improving the transaction support in the DB-API,
so this may be on someone's wish list.


More information about the Python-list mailing list