Struct DuckDbTransaction
Controls a database transaction in DuckDB.
Inherited Members
Namespace: Mallard
Assembly: Mallard.dll
Syntax
public readonly struct DuckDbTransaction : IDbTransaction, IDisposable, IEquatable<DuckDbTransaction>
Remarks
An instance is obtained by BeginTransaction().
It should be put as the subject of a using
block in C#, and within
that using
block, statements may be submitted to the
originating DuckDbConnection object.
This object should not be accessed from multiple threads at the same time. (If that is done, exceptions will be thrown when attempting to commit or roll back the transaction.)
This type is a value type only to avoid GC allocation. All of the transaction state is actually lives inside DuckDbConnection. (A DuckDB connection can only accept at most one transaction at once.)
Properties
| Edit this page View SourceConnection
The database connection that this transaction was created on.
Declaration
public DuckDbConnection Connection { get; }
Property Value
Type | Description |
---|---|
DuckDbConnection |
IsolationLevel
The isolation level of the database transaction.
Declaration
public IsolationLevel IsolationLevel { get; }
Property Value
Type | Description |
---|---|
IsolationLevel |
Remarks
DuckDB only supports snapshot-level isolation (Snapshot and that is what this property always reports.
Methods
| Edit this page View SourceCommit()
Commits this database transaction.
Declaration
public void Commit()
Remarks
This transaction becomes inactive (same as its disposed state) once this method is called, whether it succeeds or fails.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The underlying connection has already been disposed (closed). |
InvalidOperationException | This transaction cannot be committed because it is no longer active (e.g. it has already been committed or rolled back). |
DuckDbException | There has been a database-level error in committing the transaction, e.g. another connection made changes to the database which causes conflict with the changes from this transaction. |
Dispose()
Disposes of the transaction, equivalent to rolling it back if it has not been committed or rolled back already.
Declaration
public void Dispose()
Equals(DuckDbTransaction)
Whether this instance and the other instance refers to the same transaction on the same database.
Declaration
public bool Equals(DuckDbTransaction other)
Parameters
Type | Name | Description |
---|---|---|
DuckDbTransaction | other |
Returns
Type | Description |
---|---|
bool |
Equals(object?)
Indicates whether this instance and a specified object are equal.
Declaration
public override bool Equals(object? obj)
Parameters
Type | Name | Description |
---|---|---|
object | obj | The object to compare with the current instance. |
Returns
Type | Description |
---|---|
bool | true if |
Overrides
| Edit this page View SourceGetHashCode()
Returns the hash code for this instance.
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
int | A 32-bit signed integer that is the hash code for this instance. |
Overrides
| Edit this page View SourceRollback()
Rolls back changes from this database transaction.
Declaration
public void Rollback()
Remarks
This transaction becomes inactive (same as its disposed state) once this method is called, whether it succeeds or fails.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The underlying connection has already been disposed (closed). |
InvalidOperationException | This transaction cannot be rolled back because it is no longer active (e.g. it has already been committed or rolled back). |
DuckDbException | There has been a database-level error in rolling back the transaction. |