Start a database transaction creating a Transaction instance.
For an overview see page McoSqlEngine
Prototypes
Transaction* SqlEngine::beginTransaction(Transaction::Mode mode, int priority = 0, Transaction::IsolationLevel level = Transaction::DefaultIsolationLevel)Arguments
mode A Transaction::Mode: Exclusive, ReadOnly, ReadWrite
orUpdate
priority An integer value specifying the transaction priority. (See page Transaction Priorities and Scheduling for further details) level A Transaction::IsolationLevel: DefaultIsolationLevel, ReadCommitted, RepeatableRead
orSerializable
. (See page Transaction Isolation Levels for further details)Description
This method starts a database transaction creating a Transaction instance. When completed, the Transaction method
commit()
orrollback()
must be called to close the transaction, andrelease()
to release system resources associated with the transaction. In multi-threaded applications, if it is necessary to share a single database connection between multiple threads, the McoSqlSession class must be used and it's Database member'sbeginTransaction()
methodReturns
This method returns a Transaction or throws a RuntimeException in the case of an error.
Example
const char * dbname = "SqlDb"; int main(int argc, char* argv[]) { McoSqlEngine engine; ... engine.open(db_name, // database name SqlDb_get_dictionary(), // database dictionary DATABASE_SIZE, // database size MEMORY_PAGE_SIZE, // page size MAP_ADDRESS); // mapping address for shared memory mode ... Transaction* trans = engine.beginTransaction(Transaction::ReadWrite); engine.executeStatement(trans, "update Member set balance=%i where id=%i", fromBalance, idFrom); engine.executeStatement(trans, "update Member set balance=%i where id=%i", toBalance, idTo); trans->commit(); trans->release(); ... }