[go: up one dir, main page]

Statement

Trait Statement 

Source
pub trait Statement: Optionable<Option = OptionStatement> {
    // Required methods
    fn bind(&mut self, batch: RecordBatch) -> Result<()>;
    fn bind_stream(
        &mut self,
        reader: Box<dyn RecordBatchReader + Send>,
    ) -> Result<()>;
    fn execute(&mut self) -> Result<impl RecordBatchReader + Send>;
    fn execute_update(&mut self) -> Result<Option<i64>>;
    fn execute_schema(&mut self) -> Result<Schema>;
    fn execute_partitions(&mut self) -> Result<PartitionedResult>;
    fn get_parameter_schema(&self) -> Result<Schema>;
    fn prepare(&mut self) -> Result<()>;
    fn set_sql_query(&mut self, query: impl AsRef<str>) -> Result<()>;
    fn set_substrait_plan(&mut self, plan: impl AsRef<[u8]>) -> Result<()>;
    fn cancel(&mut self) -> Result<()>;
}
Expand description

A handle to an ADBC statement.

A statement is a container for all state needed to execute a database query, such as the query itself, parameters for prepared statements, driver parameters, etc.

Statements may represent queries or prepared statements.

Statements may be used multiple times and can be reconfigured (e.g. they can be reused to execute multiple different queries). However, executing a statement (and changing certain other state) will invalidate result sets obtained prior to that execution.

Multiple statements may be created from a single connection. However, the driver may block or error if they are used concurrently (whether from a single thread or multiple threads).

Required Methods§

Source

fn bind(&mut self, batch: RecordBatch) -> Result<()>

Bind Arrow data. This can be used for bulk inserts or prepared statements.

Source

fn bind_stream( &mut self, reader: Box<dyn RecordBatchReader + Send>, ) -> Result<()>

Bind Arrow data. This can be used for bulk inserts or prepared statements.

Source

fn execute(&mut self) -> Result<impl RecordBatchReader + Send>

Execute a statement and get the results.

This invalidates any prior result sets.

Source

fn execute_update(&mut self) -> Result<Option<i64>>

Execute a statement that doesn’t have a result set and get the number of affected rows.

This invalidates any prior result sets.

§Result

Will return the number of rows affected. If the affected row count is unknown or unsupported by the database, will return None.

Source

fn execute_schema(&mut self) -> Result<Schema>

Get the schema of the result set of a query without executing it.

This invalidates any prior result sets.

Depending on the driver, this may require first executing Statement::prepare.

§Since

ADBC API revision 1.1.0

Source

fn execute_partitions(&mut self) -> Result<PartitionedResult>

Execute a statement and get the results as a partitioned result set.

Source

fn get_parameter_schema(&self) -> Result<Schema>

Get the schema for bound parameters.

This retrieves an Arrow schema describing the number, names, and types of the parameters in a parameterized statement. The fields of the schema should be in order of the ordinal position of the parameters; named parameters should appear only once.

If the parameter does not have a name, or the name cannot be determined, the name of the corresponding field in the schema will be an empty string. If the type cannot be determined, the type of the corresponding field will be NA (NullType).

This should be called after Statement::prepare.

Source

fn prepare(&mut self) -> Result<()>

Turn this statement into a prepared statement to be executed multiple times.

This invalidates any prior result sets.

Source

fn set_sql_query(&mut self, query: impl AsRef<str>) -> Result<()>

Set the SQL query to execute.

The query can then be executed with Statement::execute. For queries expected to be executed repeatedly, call Statement::prepare first.

Source

fn set_substrait_plan(&mut self, plan: impl AsRef<[u8]>) -> Result<()>

Set the Substrait plan to execute.

The query can then be executed with Statement::execute. For queries expected to be executed repeatedly, call Statement::prepare first.

Source

fn cancel(&mut self) -> Result<()>

Cancel execution of an in-progress query.

This can be called during Statement::execute (or similar), or while consuming a result set returned from such.

§Since

ADBC API revision 1.1.0

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§