MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / runFuncInTransaction

Method runFuncInTransaction

src/main/client_context.cpp:640–662  ·  view source on GitHub ↗

If there is an active transaction in the context, we execute the function in the current active transaction. If there is no active transaction, we start an auto commit transaction.

Source from the content-addressed store, hash-verified

638// If there is an active transaction in the context, we execute the function in the current active
639// transaction. If there is no active transaction, we start an auto commit transaction.
640void ClientContext::TransactionHelper::runFuncInTransaction(TransactionContext& context,
641 const std::function<void()>& fun, bool readOnlyStatement, bool isTransactionStatement,
642 TransactionCommitAction action) {
643 DASSERT(context.isAutoTransaction() || context.hasActiveTransaction());
644 const bool requireNewTransaction =
645 context.isAutoTransaction() && !context.hasActiveTransaction() && !isTransactionStatement;
646 if (requireNewTransaction) {
647 context.beginAutoTransaction(readOnlyStatement);
648 }
649 try {
650 fun();
651 if ((requireNewTransaction && commitIfNew(action)) ||
652 (context.isAutoTransaction() && commitIfAuto(action))) {
653 context.commit();
654 }
655 } catch (CheckpointException&) {
656 context.clearTransaction();
657 throw;
658 } catch (std::exception&) {
659 context.rollback();
660 throw;
661 }
662}
663
664bool ClientContext::canExecuteWriteQuery() const {
665 if (getDBConfig()->readOnly) {

Callers

nothing calls this directly

Calls 5

hasActiveTransactionMethod · 0.80
beginAutoTransactionMethod · 0.80
clearTransactionMethod · 0.80
commitMethod · 0.45
rollbackMethod · 0.45

Tested by

no test coverage detected