Documentation Home
MySQL Internals Manual

MySQL Internals Manual  /  ...  /  Starting a Transaction from a start_stmt() Call Starting a Transaction from a start_stmt() Call

The first method call that can start a transaction is the [custom-engine.html#custom-engine-transactions-starting-start-stmt start_stmt()] method.

The following example shows how a storage engine could register a transaction:

int my_handler::start_stmt(THD *thd, thr_lock_type lock_type)
  int error= 0;
  my_txn *txn= (my_txn *) thd->ha_data[my_handler_hton.slot];

  if (txn == NULL)
    thd->ha_data[my_handler_hton.slot]= txn= new my_txn;
  if (txn->stmt == NULL && !(error= txn->tx_begin()))
    txn->stmt= txn->new_savepoint();
    trans_register_ha(thd, FALSE, &my_handler_hton);
  return error;

THD is the current client connection. It holds state relevant data for the current client, such as identity, network connection and other per-connection data.

thd->ha_data[my_handler_hton.slot] is a pointer in thd to the connection-specific data of this storage engine. In this example we use it to store the transaction context.

An additional example of implementing start_stmt() can be found in