Statement:
XA {start| BEGIN} XID
XA END XID
XA PREPARE XID
XA COMMIT XID [one PHASE]
XA ROLLBACK XID
XA RECOVER
XA START XID | XA BEGIN XID
begins a transaction and puts the transaction into the active state, after which the SQL statement executed will be placed in the transaction.
XA END XID
puts the transaction in an idle state, indicating that the SQL operation within the transaction is complete.
Subsequent transactional operations can make XA PREPARE xid or xa COMMIT xid one PHASE.
XA PREPARE XID
to enable the preparation of transaction commits, the transaction state is placed in the prepared state.
If the transaction cannot be committed, the statement will fail.
Thereafter, the XC commit and XA ROLLBACK can be executed
XA COMMIT XID
The transaction is finally committed, the persistence is complete, and the transaction completes.
XA COMMIT XID One PHASE
executed after the XA end, the statement contains both XA prepare and XA COMMIT.
XA ROLLBACK XID
The transaction is rolled back and terminated.
Sample program:
// Create a connection to two databases, respectively, and create the respective tables, and the DDL statements cannot be executed during the transaction. create_connection1 (&_g_connect1); Create_connection2 (&_G_CONNECT2); create_table_member (&_G_connect1) ; create_table_member (&_G_CONNECT2); // Two databases create two distributed transaction _g_connect1.direct_exec ("xa begin ' Xa-trans '"), respectively; _g_connect2.direct_exec ("xa start ' Xa-trans '"); // Write Data insert_record_direct (&_G_CONNECT1) to two library tables separately; insert_record_direct (&_G_CONNECT2); // sql Operation Complete _g_connect1.direct_exec ("xa end ' Xa-trans '"); _ G_connect2.direct_exec ("xa end ' Xa-trans '"); // transaction Readiness Submission _g_connect1.direct_exec ("xa prepare ' Xa-trans '"); _g_connect2.direct_exec ("xa prepare ' Xa-trans '"); // transaction final submission _g_connect1.direct_exec ("xa commit ' Xa-trans '"); _g_connect2.direct_exec ("xa commit ' Xa-trans '"); // If a database is ready to commit failed, the transaction can be rolled back //_g_connect1.direct_exec ("xa rollback " Xa-trans ' "); //_g_connect1.direct_exec (" xa rollback ' Xa-trans ' "); // xa prepare and Xa commit, you can use a xa commit one phase statement to complete _g_connect1.direct_exec ("xa commit ' Xa-trans ' one Phase "); _g_connect2.direct_exec (" xa commit ' Xa-trans ' one phase ");
MySQL Distributed TRANSACTION statement operations