tpc_begin()

Overview

In 1.1:

Begins a TPC transaction with the given transaction ID xid. This method should be called outside of a transaction (i.e., nothing may have executed since the last .commit() or .rollback()). Furthermore, it is an error to call .commit() or .rollback() within the TPC transaction. A ProgrammingError is raised, if the application calls .commit() or .rollback() during an active TPC transaction.

In 1.0:

Begins a TPC transaction with the given transaction ID xid.

See also: MariaDB Connector/Python 1.1 and in 1.0

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

  • Present starting in MariaDB Connector/Python 1.1.0rc1.

1.0

  • Present starting in MariaDB Connector/Python 1.0.0.