encode format with types
This commit is contained in:
parent
8f955eb3ac
commit
569689deaa
@ -836,7 +836,7 @@ pub trait ToSql: fmt::Debug {
|
||||
) -> Result<IsNull, Box<dyn Error + Sync + Send>>;
|
||||
|
||||
/// Specify the encode format
|
||||
fn encode_format(&self) -> Format {
|
||||
fn encode_format(&self, _ty: &Type) -> Format {
|
||||
Format::Binary
|
||||
}
|
||||
}
|
||||
@ -868,8 +868,8 @@ where
|
||||
T::accepts(ty)
|
||||
}
|
||||
|
||||
fn encode_format(&self) -> Format {
|
||||
(*self).encode_format()
|
||||
fn encode_format(&self, ty: &Type) -> Format {
|
||||
(*self).encode_format(ty)
|
||||
}
|
||||
|
||||
to_sql_checked!();
|
||||
@ -891,9 +891,9 @@ impl<T: ToSql> ToSql for Option<T> {
|
||||
<T as ToSql>::accepts(ty)
|
||||
}
|
||||
|
||||
fn encode_format(&self) -> Format {
|
||||
fn encode_format(&self, ty: &Type) -> Format {
|
||||
match self {
|
||||
Some(ref val) => val.encode_format(),
|
||||
Some(ref val) => val.encode_format(ty),
|
||||
None => Format::Binary,
|
||||
}
|
||||
}
|
||||
|
@ -156,16 +156,18 @@ where
|
||||
I: IntoIterator<Item = P>,
|
||||
I::IntoIter: ExactSizeIterator,
|
||||
{
|
||||
let param_types = statement.params();
|
||||
let (param_formats, params): (Vec<_>, Vec<_>) = params
|
||||
.into_iter()
|
||||
.map(|p| (p.borrow_to_sql().encode_format() as i16, p))
|
||||
.zip(param_types.iter())
|
||||
.map(|(p, ty)| (p.borrow_to_sql().encode_format(ty) as i16, p))
|
||||
.unzip();
|
||||
let params = params.into_iter();
|
||||
|
||||
assert!(
|
||||
statement.params().len() == params.len(),
|
||||
param_types.len() == params.len(),
|
||||
"expected {} parameters but got {}",
|
||||
statement.params().len(),
|
||||
param_types.len(),
|
||||
params.len()
|
||||
);
|
||||
|
||||
@ -174,7 +176,7 @@ where
|
||||
portal,
|
||||
statement.name(),
|
||||
param_formats,
|
||||
params.zip(statement.params()).enumerate(),
|
||||
params.zip(param_types).enumerate(),
|
||||
|(idx, (param, ty)), buf| match param.borrow_to_sql().to_sql_checked(ty, buf) {
|
||||
Ok(IsNull::No) => Ok(postgres_protocol::IsNull::No),
|
||||
Ok(IsNull::Yes) => Ok(postgres_protocol::IsNull::Yes),
|
||||
|
Loading…
Reference in New Issue
Block a user