Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09e8656

Browse files
authored
Merge pull request#836 from subzerocloud/master
Implement Unknown encoding for query parameters
2 parents8736f45 +6838688 commit09e8656

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

‎postgres-types/src/lib.rs‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,8 +834,32 @@ pub trait ToSql: fmt::Debug {
834834
ty:&Type,
835835
out:&mutBytesMut,
836836
) ->Result<IsNull,Box<dynError +Sync +Send>>;
837+
838+
/// Specify the encode format
839+
fnencode_format(&self) ->Format{Format::Binary}
837840
}
838841

842+
/// Supported Postgres message format types
843+
///
844+
/// Using Text format in a message assumes a Postgres `SERVER_ENCODING` of `UTF8`
845+
pubenumFormat{
846+
/// Text format (UTF-8)
847+
Text,
848+
/// Compact, typed binary format
849+
Binary,
850+
}
851+
852+
/// Convert from `Format` to the Postgres integer representation of those formats
853+
implFrom<Format>fori16{
854+
fnfrom(format:Format) ->Self{
855+
match format{
856+
Format::Text =>0,
857+
Format::Binary =>1,
858+
}
859+
}
860+
}
861+
862+
839863
impl<'a,T>ToSqlfor&'aT
840864
where
841865
T:ToSql,

‎tokio-postgres/src/query.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ where
156156
I:IntoIterator<Item =P>,
157157
I::IntoIter:ExactSizeIterator,
158158
{
159+
let(param_formats, params):(Vec<_>,Vec<_>) = params.into_iter().map(|p|->(i16,P){(p.borrow_to_sql().encode_format().into(),p)}).unzip();
159160
let params = params.into_iter();
160161

161162
assert!(
@@ -169,7 +170,7 @@ where
169170
let r = frontend::bind(
170171
portal,
171172
statement.name(),
172-
Some(1),
173+
param_formats,
173174
params.zip(statement.params()).enumerate(),
174175
|(idx,(param, ty)), buf|match param.borrow_to_sql().to_sql_checked(ty, buf){
175176
Ok(IsNull::No) =>Ok(postgres_protocol::IsNull::No),

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp