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.
| 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. |
| 640 | void 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 | |
| 664 | bool ClientContext::canExecuteWriteQuery() const { |
| 665 | if (getDBConfig()->readOnly) { |
nothing calls this directly
no test coverage detected