25#ifndef FBCPP_TRANSACTION_H
26#define FBCPP_TRANSACTION_H
126 const std::vector<std::uint8_t>&
getTpb()
const
147 tpb = std::move(value);
156 return isolationLevel;
164 isolationLevel = value;
173 return readCommittedMode;
181 readCommittedMode = value;
260 return restartRequests;
268 restartRequests = value;
290 std::vector<std::uint8_t> tpb;
291 std::optional<TransactionIsolationLevel> isolationLevel;
292 std::optional<TransactionReadCommittedMode> readCommittedMode;
293 std::optional<TransactionAccessMode> accessMode;
294 std::optional<TransactionWaitMode> waitMode;
295 bool noAutoUndo =
false;
296 bool ignoreLimbo =
false;
297 bool restartRequests =
false;
298 bool autoCommit =
false;
375 std::span<std::reference_wrapper<Attachment>> attachments,
const TransactionOptions& options = {});
383 handle{std::move(o.handle)},
385 isMultiDatabase{o.isMultiDatabase}
390 Transaction& operator=(Transaction&&) =
delete;
392 Transaction(
const Transaction&) =
delete;
393 Transaction& operator=(
const Transaction&) =
delete;
406 "Prepared transaction must be explicitly committed or rolled back");
426 return handle !=
nullptr;
458 void prepare(std::string_view message);
465 void prepare(std::span<const std::uint8_t> message);
499 const bool isMultiDatabase =
false;
Represents a connection to a Firebird database.
Represents a Firebird client library instance.
Reference-counted smart pointer for Firebird objects using addRef/release semantics.
Represents options used when creating a Transaction object.
bool getAutoCommit() const
Returns whether the transaction will be automatically committed.
const std::vector< std::uint8_t > & getTpb() const
Returns the TPB (Transaction Parameter Block) which will be used to start the transaction.
TransactionOptions & setWaitMode(TransactionWaitMode value)
Sets the transaction wait mode.
TransactionOptions & setTpb(std::vector< std::uint8_t > &&value)
Sets the TPB (Transaction Parameter Block) which will be used to start the transaction.
bool getRestartRequests() const
Returns whether the transaction will restart requests.
const std::optional< TransactionAccessMode > getAccessMode() const
Returns the transaction access mode.
bool getNoAutoUndo() const
Returns whether the transaction will not automatically undo changes in case of a deadlock or update c...
bool getIgnoreLimbo() const
Returns whether the transaction will ignore limbo transactions.
const std::optional< TransactionIsolationLevel > getIsolationLevel() const
Returns the transaction isolation level.
const std::optional< TransactionReadCommittedMode > getReadCommittedMode() const
Returns the read committed mode.
TransactionOptions & setAccessMode(TransactionAccessMode value)
Sets the transaction access mode.
TransactionOptions & setTpb(const std::vector< std::uint8_t > &value)
Sets the TPB (Transaction Parameter Block) which will be used to start the transaction.
TransactionOptions & setReadCommittedMode(TransactionReadCommittedMode value)
Sets the read committed mode.
TransactionOptions & setNoAutoUndo(bool value)
Sets whether the transaction will not automatically undo changes in case of a deadlock or update conf...
TransactionOptions & setIsolationLevel(TransactionIsolationLevel value)
Sets the transaction isolation level.
TransactionOptions & setAutoCommit(bool value)
Sets whether the transaction will be automatically committed.
const std::optional< TransactionWaitMode > getWaitMode() const
Returns the transaction wait mode.
TransactionOptions & setIgnoreLimbo(bool value)
Sets whether the transaction will ignore limbo transactions.
TransactionOptions & setRestartRequests(bool value)
Sets whether the transaction will restart requests.
Represents a transaction in one or more Firebird databases.
void rollback()
Rolls back the transaction.
Transaction(Transaction &&o) noexcept
Move constructor.
~Transaction() noexcept
Rolls back the transaction if it is still active.
void commit()
Commits the transaction.
void prepare()
Prepares the transaction for two-phase commit (2PC phase 1).
TransactionState getState() const noexcept
Returns the current transaction state.
bool isValid() noexcept
Returns whether the Transaction object is valid.
FbRef< fb::ITransaction > getHandle() noexcept
Returns the internal Firebird ITransaction handle.
void commitRetaining()
Commits the transaction while maintains it active.
void rollbackRetaining()
Rolls back the transaction while maintains it active.
TransactionState
Transaction state for tracking two-phase commit lifecycle.
@ ACTIVE
Transaction is active and can execute statements.
@ COMMITTED
Transaction has been committed.
@ PREPARED
Transaction has been prepared (2PC phase 1).
@ ROLLED_BACK
Transaction has been rolled back.
TransactionAccessMode
Transaction access mode.
@ READ_ONLY
Transaction can only read data; write operations are not permitted.
@ READ_WRITE
Transaction can read and write data.
TransactionReadCommittedMode
Transaction read committed mode.
@ NO_RECORD_VERSION
Does not allow reading of record versions; waits for or errors on uncommitted changes.
@ RECORD_VERSION
Allows reading of the latest committed version of a record.
TransactionIsolationLevel
Transaction isolation level.
@ READ_COMMITTED
Allows reading of committed changes from other transactions.
@ SNAPSHOT
Provides a stable snapshot of the database at transaction start time.
@ CONSISTENCY
Ensures full transaction consistency at the expense of concurrency.
TransactionWaitMode
Transaction wait mode.
@ WAIT
Transaction waits until a conflicting lock is released.
@ NO_WAIT
Transaction returns an error immediately if a lock conflict occurs.