Merge pull request #836 from subzerocloud/master
Implement Unknown encoding for query parameters
This commit is contained in:
commit
09e86560dd
@ -834,8 +834,32 @@ pub trait ToSql: fmt::Debug {
|
||||
ty: &Type,
|
||||
out: &mut BytesMut,
|
||||
) -> Result<IsNull, Box<dyn Error + Sync + Send>>;
|
||||
|
||||
/// Specify the encode format
|
||||
fn encode_format(&self) -> Format { Format::Binary }
|
||||
}
|
||||
|
||||
/// Supported Postgres message format types
|
||||
///
|
||||
/// Using Text format in a message assumes a Postgres `SERVER_ENCODING` of `UTF8`
|
||||
pub enum Format {
|
||||
/// Text format (UTF-8)
|
||||
Text,
|
||||
/// Compact, typed binary format
|
||||
Binary,
|
||||
}
|
||||
|
||||
/// Convert from `Format` to the Postgres integer representation of those formats
|
||||
impl From<Format> for i16 {
|
||||
fn from(format: Format) -> Self {
|
||||
match format {
|
||||
Format::Text => 0,
|
||||
Format::Binary => 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
impl<'a, T> ToSql for &'a T
|
||||
where
|
||||
T: ToSql,
|
||||
|
@ -156,6 +156,7 @@ where
|
||||
I: IntoIterator<Item = P>,
|
||||
I::IntoIter: ExactSizeIterator,
|
||||
{
|
||||
let (param_formats, params):(Vec<_>, Vec<_>) = params.into_iter().map(|p|->(i16, P){(p.borrow_to_sql().encode_format().into(),p)}).unzip();
|
||||
let params = params.into_iter();
|
||||
|
||||
assert!(
|
||||
@ -169,7 +170,7 @@ where
|
||||
let r = frontend::bind(
|
||||
portal,
|
||||
statement.name(),
|
||||
Some(1),
|
||||
param_formats,
|
||||
params.zip(statement.params()).enumerate(),
|
||||
|(idx, (param, ty)), buf| match param.borrow_to_sql().to_sql_checked(ty, buf) {
|
||||
Ok(IsNull::No) => Ok(postgres_protocol::IsNull::No),
|
||||
|
Loading…
Reference in New Issue
Block a user