tpc_prepare()
This page is part of MariaDB's Enterprise Documentation.
The parent of this page is: Connector/Python API
Topics on this page:
Overview
Performs the verification phase of two-phase-commit transaction started with the tpc_begin() method.
See also: MariaDB Connector/Python 1.1 and in 1.0
DETAILS
Performs the verification phase of a transaction started with tpc_begin().
A ProgrammingError
will be raised when using this method outside of a TPC transaction.
EXAMPLES
import mariadb
conn1 = mariadb.connect(
host = 'host1',
user = 'user1',
password = 'secret1',
database = 'db1',
)
conn2 = mariadb.connect(
host = 'host2',
user = 'user2',
password = 'secret2',
database = 'db2',
)
cursor1 = conn1.cursor()
cursor2 = conn2.cursor()
xid1 = conn1.xid(999, 'xyz trans', 'conn1')
xid2 = conn2.xid(999, 'xyz trans', 'conn2')
conn1.tpc_begin(xid1)
conn2.tpc_begin(xid2)
# ... perform the updates for your interrelated change ...
try:
# These prepare calls validate that all the commits can be made.
conn1.tpc_prepare(xid1)
conn2.tpc_prepare(xid2)
except mariadb.DatabaseError:
conn1.tpc_rollback(xid1)
conn2.tpc_rollback(xid2)
else:
conn1.tpc_commit(xid1)
conn2.tpc_commit(xid2)
CHANGE HISTORY
Release Series | History |
---|---|
1.1 |
|
1.0 |
|