Directory
eXtremeDB_rt/samples/transactions_nestedDescription
Demonstrates a nested transaction
Used API
Code snippet
/* Insert two Transaction records */ MCO_RET insert_two(mco_db_h db, mco_uint4 from1, mco_uint4 to1, mco_uint4 from2, mco_uint4 to2) { MCO_RET rc; mco_trans_h t; Transaction trans; rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t); if ( rc != MCO_S_OK) return rc; rc = Transaction_new(t, &trans); if ( MCO_S_OK != rc ) { mco_trans_rollback(t); return rc; } /* Put values in first 'new' object */ Transaction_from_put(&trans, from1); Transaction_to_put(&trans, to1); /* Call nested transaction in insert_one() to insert second object */ insert_one(db, from2, to2 ); /* Now commit the transaction to complete the insert of the first object */ return mco_trans_commit(t); } /* Insert one Transaction record within a read-write transaction */ MCO_RET insert_one(mco_db_h db, mco_uint4 from, mco_uint4 to ) { MCO_RET rc; mco_trans_h t; Transaction trans; rc = mco_trans_start(db, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t); if ( rc != MCO_S_OK) return rc; rc = Transaction_new(t, &trans); if ( MCO_S_OK != rc ) { mco_trans_rollback(t); return rc; } Transaction_from_put(&trans, from); Transaction_to_put(&trans, to); return mco_trans_commit(t); }What to expect as an output
Insert two objects : Successful