[DB-SIG] Two phase commit API
David Rushby
davidrushby at yahoo.com
Thu Jun 22 14:28:08 CEST 2006
--- Stuart Bishop <stuart at stuartbishop.net> wrote:
> Are there any drivers out there that support two phase commit.
KInterbasDB does.
> If so, what syntax do they use?
The Connection class has a prepare method that triggers the first phase
of two-phase commit. The normal commit method then performs the second
phase.
There's also a ConnectionGroup class that makes it more convenient to
deal with a group of Connections that are all participating in the same
distributed transaction.
Here's an example:
---
import kinterbasdb
# Establish multiple connections the usual way:
con1 = kinterbasdb.connect(dsn='weasel:/temp/test.db', user='sysdba',
password='pass')
con2 = kinterbasdb.connect(dsn='coyote:/temp/test.db', user='sysdba',
password='pass')
# Create a ConnectionGroup to associate multiple connections in such a
# way that they can participate in a distributed transaction.
group = kinterbasdb.ConnectionGroup(connections=(con1,con2))
# Start a distributed transaction involving all of the members of
# the group (con1 and con2 in this case) with one of the following
# approaches:
# - Call group.begin()
# - Call con1.begin(); the operation will "bubble upward" and
# apply to the group.
# - Call con2.begin(); the operation will "bubble upward" and
# apply to the group.
# - Just start executing some SQL statements on either con1 or con2.
# A transaction will be started implicitly; it will be a
# distributed transaction because con1 and con2 are members
# of a ConnectionGroup.
group.begin()
# Perform some database changes the usual way (via cursors on con1 and
con2):
...
# Commit or roll back the distributed transaction by calling the
# commit or rollback method of the ConnectionGroup itself, or the
# commit or rollback method of any member connection (con1 or
# con2 in this case).
group.commit()
# Unless you want to perform another distributed transaction,
# disband the group so that member connections can operate
# independently again.
group.clear()
---
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
More information about the DB-SIG
mailing list