$1, $2, … (or ?). Bind them with execute_with,
passing values as &mut dyn AppendAble. Every DuckValue and the
primitive Rust types (i32, f64, &str / String, bool, …) implement
AppendAble, and mixed types coerce to
&mut dyn AppendAble at the call site.
execute_with
execute_with(sql, binds: &mut [&mut dyn AppendAble]) -> Result<DuckResult>. Heterogeneous types
are fine; binds fill $1, $2, … in slice order.
&mut? Binding goes through DuckDB’s value API, and the AppendAble contract takes the value
by mutable reference so it can hand ownership of a built duckdb_value to the FFI call without an
extra copy. The slice itself is &mut for the same reason.
Binding an explicit NULL
Option<T> also binds as Null / Some — None becomes SQL NULL.
The params! macro
With the derive feature, params![…] builds the &mut [&mut dyn AppendAble] slice for you,
mixing literals, owned values, and Null without the &mut x as &mut dyn … boilerplate:
insert — homogeneous bind-and-run
For a statement filled from a homogeneous iterator,insert is terser:
Errors
- Wrong number of bound parameters →
Error::InvalidParameterCount. - A value that doesn’t fit its target type →
Error::IntegralValueOutOfRangeor aConversionError.
See also
- Named parameters — bind by
$name. - Prepared statements — reuse a statement across many binds.
- Values overview — the
AppendAbletrait.