ctdbBegin
Start a transaction.
Declaration
CTDBRET ctdbBegin(CTHANDLE Handle)
Description
ctdbBegin() marks the beginning of a transaction. All file updates done after this call will be held until they are committed with a matching call to ctdbCommit(), or aborted with a matching call to ctdbAbort(). Notice that the record locks still must be manually acquired with a call to ctdbLockRecord(), or, even better, automatically acquired via the session-wide locking mechanism (see ctdbLock()). If for any reason the transaction cannot be committed, it can be finished (by discarding it) with a call to ctdbAbort(). This function can be used to perform transaction-controlled file creates.
It is important to realize that c-treeDB API transactions are session-wide, and since c-treeDB API does not support nested transactions, you can only have one transaction "open" at a time. If you call ctdbBegin() twice in a row, the second call will return an error. You can use save points to mimic nested transactions, though (see ctdbSetSavePoint() and ctdbSetSingleSavePoint()). Transactions only affect certain types of tables; see the Creating tables for transaction processing section in Transactions under Data Integrity.
Returns
ctdbBegin() returns CTDBRET_OK if successful, or the c-tree error code on failure.
Example
ctdbBegin(pSession);
if (ctdbCreateTable(tHandle1,"table1",CTCREATE_NORMAL) == CTDBRET_OK)
ctdbCommit(pSession);
else
ctdbAbort(pSession);
See also
ctdbAbort(), ctdbClearSavePoint(), ctdbCommit(), ctdbRestoreSavePoint(), ctdbSetSavePoint(), ctdbSetSingleSavePoint()