Statement is returned by conn.prepare(). It holds a compiled form of the SQL and can be executed many times with different parameter values.
stmt.query(params)
Executes the statement and returns a Rows iterator.
Bind parameters. Pass
() for no parameters.Result<Rows>
stmt.execute(params)
Executes the statement, discarding any result rows. Returns the number of rows affected.
Bind parameters.
Result<u64>
stmt.query_row(params)
Executes the statement and returns the first row. Returns Error::QueryReturnedNoRows if the result set is empty.
Bind parameters.
Result<Row>
stmt.reset()
Resets the statement back to its pre-execution state so it can be re-used. Called automatically by query() and execute() at the start of each execution.
Returns Result<()>
Column metadata
stmt.column_count()
Returns the number of columns in the result set.
Returns usize
stmt.column_name(idx)
Returns the name of the column at the given zero-based index. Returns Error::Misuse if the index is out of bounds.
Zero-based column index.
Result<String>
stmt.column_names()
Returns the names of all columns in the result set.
Returns Vec<String>
stmt.column_index(name)
Returns the zero-based index of the column with the given name (case-insensitive). Returns Error::Misuse if the name is not found.
Column name to look up.
Result<usize>
stmt.columns()
Returns a Vec<Column> describing each column in the result set.
Returns Vec<Column>
Each Column has two methods:
| Method | Returns | Description |
|---|---|---|
col.name() | &str | Column name |
col.decl_type() | Option<&str> | Declared type (e.g. "TEXT", "INTEGER"), or None if the column is an expression |
Rows — iterating results
Rows is returned by stmt.query() and conn.query().
rows.next().await
Fetches the next row. Returns Ok(None) when the result set is exhausted.
Returns Result<Option<Row>>
Rows also exposes the same column metadata methods as Statement:
column_count(), column_name(idx), column_names(), column_index(name), columns().
Row — reading column values
row.get_value(idx)
Returns the value at the given zero-based column index as a Value enum.
Zero-based column index.
Result<Value>
The Value enum variants:
| Variant | Rust type | SQLite type |
|---|---|---|
Value::Null | — | NULL |
Value::Integer(i64) | i64 | INTEGER |
Value::Real(f64) | f64 | REAL |
Value::Text(String) | String | TEXT |
Value::Blob(Vec<u8>) | Vec<u8> | BLOB |
row.get::<T>(idx)
Converts the value at index idx directly into a Rust type T that implements FromValue.
Zero-based column index.
Result<T>
row.column_count()
Returns the number of columns in this row.
Returns usize
Bind parameters (IntoParams)
The IntoParams trait is implemented for:
| Type | Binding mode |
|---|---|
() | No parameters |
[Value; N] | Positional |
&[Value] | Positional |
Vec<Value> | Positional |
Params::Positional(Vec<Value>) | Positional |
Params::Named(Vec<(String, Value)>) | Named (by parameter name) |
params_from_iter(iter) to build positional params from any iterator.