Class DuckDbCommand
ADO.NET-compatible command object to execute a query/statement against a DuckDB database.
Inherited Members
Namespace: Mallard.Ado
Assembly: Mallard.dll
Syntax
public sealed class DuckDbCommand : IDbCommand, IDisposable
Remarks
An instance of this class should only be used from one thread at a time. While multi-thread access will not cause memory/.NET runtime corruption, the object may misbehave or throw exceptions due to inconsistent internal state.
Properties
| Edit this page View SourceCommandText
The SQL query or statement(s) to execute.
Declaration
public string CommandText { get; set; }
Property Value
Type | Description |
---|---|
string | The query or statement(s) in DuckDB's SQL dialect. Multiple statements may be separated/terminated by semicolons; the results returned are always from the last statement. |
Remarks
The default value is the empty string. This property must be changed to get a valid command. Setting this property will invalidate any preparation for the previously-set statement(s).
Connection
The connection that this command works on.
Declaration
public DuckDbConnection Connection { get; }
Property Value
Type | Description |
---|---|
DuckDbConnection |
Parameters
The parameters that should be applied to a parameterized SQL query or statement.
Declaration
public DuckDbParameterCollection Parameters { get; }
Property Value
Type | Description |
---|---|
DuckDbParameterCollection |
UpdatedRowSource
Gets or sets how command results are applied to the DataRow when used by the Update(DataSet) method of a DbDataAdapter.
Declaration
public UpdateRowSource UpdatedRowSource { get; set; }
Property Value
Type | Description |
---|---|
UpdateRowSource | One of the UpdateRowSource values. The default is |
Exceptions
Type | Condition |
---|---|
ArgumentException | The value entered was not one of the UpdateRowSource values. |
Methods
| Edit this page View SourceCancel()
Attempt to cancel the executing query or statement (invoked by a different thread).
Declaration
public void Cancel()
Remarks
This method is supposed to implement Cancel(), although its semantics are subtly different from the specification. Cancel() is supposed to cancel the specific command represented by its receiver. However, DuckDB's native API does not allow cancelling specific commands, but only the currently executing command on the database connection as a whole; see Interrupt(). This method can only be implemented in the same way. That is, this method might cancel the wrong command, that is not the method's receiver argument.
Since the same DuckDB connection cannot run multiple queries at the same time from different threads (execution is always serialized), the divergence of what this method does from the specification means little in practice: there should be only one "active" command per connection anyway.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The connection has already been disposed (closed). |
CreateParameter()
Creates a new instance of an IDbDataParameter object.
Declaration
public IDbDataParameter CreateParameter()
Returns
Type | Description |
---|---|
IDbDataParameter | An |
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
Declaration
public void Dispose()
ExecuteNonQuery()
Executes an SQL statement against the Connection
object of a .NET data provider, and returns the number of rows affected.
Declaration
public int ExecuteNonQuery()
Returns
Type | Description |
---|---|
int | The number of rows affected. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | The connection does not exist. -or- The connection is not open. |
ExecuteReader()
Executes the CommandText against the Connection and builds an IDataReader.
Declaration
public DuckDbDataReader ExecuteReader()
Returns
Type | Description |
---|---|
DuckDbDataReader | An IDataReader object. |
ExecuteReader(CommandBehavior)
Executes the CommandText against the Connection, and builds an IDataReader using one of the CommandBehavior values.
Declaration
public IDataReader ExecuteReader(CommandBehavior behavior)
Parameters
Type | Name | Description |
---|---|---|
CommandBehavior | behavior | One of the CommandBehavior values. |
Returns
Type | Description |
---|---|
IDataReader | An IDataReader object. |
ExecuteScalar()
Executes the query, and returns the first column of the first row in the resultset returned by the query. Extra columns or rows are ignored.
Declaration
public object? ExecuteScalar()
Returns
Type | Description |
---|---|
object | The first column of the first row in the resultset. |
Prepare()
Prepare the SQL statement for execution.
Declaration
public void Prepare()
Remarks
In DuckDB, in a sense, all statements must be prepared whether they use parameters or not. The statement set in CommandText will be implicitly prepared even without this calling this method.
Thus calling this method does not save any computational work. However, it may still be useful to call it to check for errors in the SQL statement before proceeding to set values for the parameters.
Exceptions
Type | Condition |
---|---|
ObjectDisposedException | The connection has already been disposed (closed). |
DuckDbException | There is an error in preparing the statement, e.g. from a syntax error. |