Database Sessions and Transactions

Steve Holden sholden at holdenweb.com
Fri Oct 19 14:00:38 EDT 2001


"DeepBlue" <DeepBlue at DeepBlue.org> wrote in message
news:tt0os832km0dbb at corp.supernews.com...
> 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.

Maybe this is a semantic thing. What you think of as a "session", I suspect,
the DB-API refers to as a "connection". But Oracle isn't my first( or
second) database platform, so don't take that as gospel.

> In other words, the scope of the rollback is NOT the database connection
BUT
> the transaction that is defined from within the database connection.

On any given connection, once you call the commit() method of that
connection every change that has been made using that connection is now
committed to the database, and further interactions take place in a new
transaction. Similarly, if you call the rollback() method, every change made
using that connection since the last commit() or rollback() call will be
undone.

> 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.

A transaction is a sequence of interactions with an RDBMS over a single
connection. It is terminated (successfully) by calling commit(), or
(unsuccessfully) by calling rollback(). At this point a new transaction
begins.

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

Perhaps you now have enough information to clarify the difference between a
"session" and a connection, so we can answer your question more fully?

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list