This function creates index nodes with the object’s new or updated values.
MCO_RET classname_checkpoint( /*IN*/ classname * handle );
handle | The address of a variable of type
|
This function completes one or more put methods by creating index nodes and/or other tasks necessary to incorporate the object’s new or updated values into the database.
MCO_S_OK | The object was updated successfully |
MCO_E_ACCESS | The transaction handle is MCO_READ_ONLY |
MCO_E_TRANSACT | Transaction is in error state |
MCO_E_DELETED |
This object has been deleted |
MCO_E_NOMEM |
Database memory allocation error |
MCO_S_DUPLICATE |
Attempt to insert a duplicate value into a unique index |
MCO_ERR_OBJECT_HANDLE |
Invalid object handle |
MCO_ERR_TRN |
Error in the enclosing transaction |
MCO_ERR_INDEX |
Error inserting into the index structure |
The following code snippets demonstrate how
classname_checkpoint()
can be used to update indexes to be able to lookup newly created or updated database objects within a transaction; ie. before the transaction is committed.
Snippet from schema file: class A { uint4 id; char<256> name; tree <id> idx; }; Application snippet: int main(int argc, char* argv[]) { MCO_RET rc; ... mco_db_h db = 0; mco_trans_h t; mco_cursor_t csr; A a1, a2; A a_out; char * name = "Test #N"; uint4 id = 999; uint4 id_out = 0; char name_out[64] = ""; ... rc = mco_trans_start(connection, MCO_READ_WRITE, MCO_TRANS_FOREGROUND, &t); if ( MCO_S_OK == rc ) { // Insert two instances of A A_new(t, &a1); A_id_put(&a1, id); name[6] = '1'; A_name_put(&a1, name, strlen(name)); A_new(t, &a2); A_id_put(&a2, id + 1); name[6] = '2'; A_name_put(&a2, name, strlen(name)); // Checkpoint to create index entries A_checkpoint(&a1); A_checkpoint(&a2); // Lookup inserted objects by index rc = A_idx_index_cursor(t, &csr); if (MCO_S_OK == rc) { printf("\nInside transaction; objects inserted into index: \n"); for (rc = mco_cursor_first(t, &csr); rc == MCO_S_OK; rc = mco_cursor_next(t, &csr)) { A_from_cursor(t, &csr, &a_out); A_id_get(&a_out, &id_out); A_name_get(&a_out, name_out, sizeof(name_out)); printf("\tid=%d, name {%s} \n", id_out, name_out); } } // Rollback the transaction so no inserts are committed mco_trans_rollback(t); } // Start a new transaction to check for inserted items rc = mco_trans_start(db, MCO_READ_ONLY, MCO_TRANS_FOREGROUND, &t); if (MCO_S_OK == rc) { // Lookup to verify that no objects were inserted - transaction rolled back rc = A_idx_index_cursor(t, &csr); if (MCO_S_OK == rc) { printf("\nObjects inserted: \n"); for (rc = mco_cursor_first(t, &csr); rc == MCO_S_OK; rc = mco_cursor_next(t, &csr)) { A_from_cursor(t, &csr, &a_out); A_id_get(&a_out, &id_out); A_name_get(&a_out, name_out, sizeof(name_out)); printf("\tid=%d, name {%s} \n", id_out, name_out); } } else { sample_rc_check("\n Attempt to open a cursor after rollback:", rc); } } mco_trans_rollback(t); ... }