NAME

sp_begin - start a multi-statement transaction

SYNOPSIS

#include <sophia.h>

void *sp_begin(void *env);

DESCRIPTION

sp_begin(env): create a transaction

During transaction, all updates are not written to the database files until a sp_commit() is called. All updates that were made during transaction are available through sp_get() or by using cursor.

The sp_destroy() function is used to discard changes of a multi-statement transaction. All modifications that were made during the transaction are not written to the log file.

No nested transactions are supported.

For additional information take a look at Transactions and Deadlock sections.

EXAMPLE

void *a = sp_getobject(env, "db.database_a");
void *b = sp_getobject(env, "db.database_b");

char key[] = "hello";
char value[] = "world";

/* begin a transaction */
void *transaction = sp_begin(env);

void *o = sp_document(a);
sp_setstring(o, "key", key, sizeof(key));
sp_setstring(o, "value", value, sizeof(value));
sp_set(transaction, o);

o = sp_document(b);
sp_setstring(o, "key", key, sizeof(key));
sp_setstring(o, "value", value, sizeof(value));
sp_set(transaction, o);

/* complete */
sp_commit(transaction);

RETURN VALUE

On success, sp_begin() returns transaction object handle. On error, it returns NULL.

SEE ALSO

Sophia API

results matching ""

    No results matching ""