pub struct PreparedStatement<'a, V: SQLParam> {
pub text_segments: Box<[CompactString]>,
pub params: Box<[Param<'a, V>]>,
pub sql: CompactString,
}Expand description
A statement rendered once, whose placeholders are bound each time it runs.
Create one with prepare_render; drivers wrap it in their own prepared
statement types. The SQL is stored as text segments with one parameter
between each pair: [text, param, text, param, text]. Parameters that
already had a value when the statement was rendered keep it.
§Examples
use drizzle_core::prepared::prepare_render;
use drizzle_core::{ParamBind, Placeholder, SQL, ToSQL};
let sql: SQL<'_, Value> = SQL::raw("SELECT * FROM users WHERE id =")
.append(Placeholder::named("id").to_sql());
let prepared = prepare_render(&sql);
assert_eq!(prepared.sql(), "SELECT * FROM users WHERE id = :id");
assert_eq!(prepared.external_param_count(), 1);
let (text, values) = prepared.bind([ParamBind::new("id", Value(5))])?;
assert_eq!(text, "SELECT * FROM users WHERE id = :id");
assert_eq!(values.collect::<Vec<_>>(), [Value(5)]);Fields§
§text_segments: Box<[CompactString]>Rendered SQL text between the parameters; one more than params.
params: Box<[Param<'a, V>]>The parameters, in order.
sql: CompactStringThe full SQL text, with the dialect’s placeholders.
Implementations§
Source§impl<'a, V: SQLParam> PreparedStatement<'a, V>
impl<'a, V: SQLParam> PreparedStatement<'a, V>
Sourcepub fn external_param_count(&self) -> usize
pub fn external_param_count(&self) -> usize
Returns how many bindings bind expects.
Counts parameters without a value, with each placeholder name counted once, since one binding fills every use of a name.
Sourcepub fn bind<T: SQLParam + Into<V>>(
&self,
param_binds: impl IntoIterator<Item = ParamBind<'a, T>>,
) -> Result<(&str, impl Iterator<Item = V>)>
pub fn bind<T: SQLParam + Into<V>>( &self, param_binds: impl IntoIterator<Item = ParamBind<'a, T>>, ) -> Result<(&str, impl Iterator<Item = V>)>
Binds values to the placeholders and returns the SQL text with the values to send, in order.
Named bindings match placeholders by name; unnamed ones
(ParamBind::positional) fill unnamed placeholders in order. For
SQLite, a name used more than once is sent once.
§Errors
Returns DrizzleError::ParameterError when a name is bound twice,
a placeholder has no binding, or a binding matches no placeholder.
Trait Implementations§
Source§impl<V: SQLParam> Display for PreparedStatement<'_, V>
impl<V: SQLParam> Display for PreparedStatement<'_, V>
Source§impl<V: SQLParam> From<OwnedPreparedStatement<V>> for PreparedStatement<'_, V>
impl<V: SQLParam> From<OwnedPreparedStatement<V>> for PreparedStatement<'_, V>
Source§fn from(value: OwnedPreparedStatement<V>) -> Self
fn from(value: OwnedPreparedStatement<V>) -> Self
Source§impl<'a, V: SQLParam> From<PreparedStatement<'a, V>> for OwnedPreparedStatement<V>
impl<'a, V: SQLParam> From<PreparedStatement<'a, V>> for OwnedPreparedStatement<V>
Source§fn from(prepared: PreparedStatement<'a, V>) -> Self
fn from(prepared: PreparedStatement<'a, V>) -> Self
Auto Trait Implementations§
impl<'a, V> Freeze for PreparedStatement<'a, V>
impl<'a, V> RefUnwindSafe for PreparedStatement<'a, V>
impl<'a, V> Send for PreparedStatement<'a, V>
impl<'a, V> Sync for PreparedStatement<'a, V>
impl<'a, V> Unpin for PreparedStatement<'a, V>
impl<'a, V> UnsafeUnpin for PreparedStatement<'a, V>
impl<'a, V> UnwindSafe for PreparedStatement<'a, V>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<List> ListIncludes<Nil, ()> for List
impl<Mk> MarkerAggValidFor<()> for Mk
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more