pub struct CachedStatement { /* private fields */ }Expand description
A prepared statement suitable for caching and re-execution. A prepared statement that can be reset and re-executed with different bindings.
Unlike Statement, CachedStatement is not tied to a connection’s lifetime.
It remains valid as long as the underlying database is open.
This type is used by Diesel statement cache
(StatementCache<DuckDb, CachedStatement>).
Implementations§
Source§impl CachedStatement
impl CachedStatement
Sourcepub fn prepare(conn: &RawConnection, sql: impl AsRef<str>) -> Result<Self>
pub fn prepare(conn: &RawConnection, sql: impl AsRef<str>) -> Result<Self>
Prepares sql against the given connection.
§Errors
Returns Error::DuckDBFailure if DuckDB cannot parse or plan the query,
or Error::NulError if sql contains an interior nul byte.
Sourcepub fn reset_bindings(&mut self) -> Result<()>
pub fn reset_bindings(&mut self) -> Result<()>
Resets all parameter bindings so the statement can be re-executed.
§Errors
Returns Error::DuckDBFailure if the DuckDB clear-bindings call fails.
Sourcepub fn bind<T: AppendAble + ?Sized>(
&mut self,
idx: u64,
value: &mut T,
) -> Result<()>
pub fn bind<T: AppendAble + ?Sized>( &mut self, idx: u64, value: &mut T, ) -> Result<()>
Binds value at the given 1-based parameter index.
§Errors
Returns an error if the underlying DuckDB bind call fails or idx is out of range.
Sourcepub fn execute(&mut self) -> Result<DuckResult>
pub fn execute(&mut self) -> Result<DuckResult>
Executes the prepared statement and returns the result.
Works for all statement types:
- SELECT — iterate rows via the
Iteratorimpl onDuckResult. - INSERT / UPDATE / DELETE — check
DuckResult::changes()for affected rows. - DDL (
CREATE TABLEetc.) —.changes()returns0, no rows to iterate. - INSERT … RETURNING — iterate rows and/or call
.changes().
§Errors
Returns Error::DuckDBFailure if execution fails.