Skip to content

Commit 882cd3d

Browse files
committed
Update to Postgres 0.9
1 parent f481918 commit 882cd3d

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ repository = "https://github.com/sfackler/rust-postgres-array"
88
documentation = "https://sfackler.github.io/rust-postgres-array/doc/postgres_array"
99

1010
[dependencies]
11-
postgres = "0.8"
11+
postgres = "0.9"
1212
byteorder = "0.3"
1313

1414
[dev-dependencies]

src/impls.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use std::io::prelude::*;
2+
use std::error;
23
use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
34

4-
use postgres::{self, Error, Type, Kind, ToSql, FromSql, Oid};
5-
use postgres::types::{IsNull};
5+
use postgres;
6+
use postgres::error::Error;
7+
use postgres::types::{Type, Kind, ToSql, FromSql, Oid, IsNull, SessionInfo};
68

79
use {Array, Dimension};
810

911
impl<T> FromSql for Array<Option<T>> where T: FromSql {
10-
fn from_sql<R: Read>(ty: &Type, raw: &mut R) -> postgres::Result<Array<Option<T>>> {
12+
fn from_sql<R: Read>(ty: &Type, raw: &mut R, info: &SessionInfo)
13+
-> postgres::Result<Array<Option<T>>> {
1114
let element_type = match ty.kind() {
1215
&Kind::Array(ref ty) => ty,
1316
_ => panic!("unexpected type {:?}", ty),
@@ -37,9 +40,11 @@ impl<T> FromSql for Array<Option<T>> where T: FromSql {
3740
elements.push(None);
3841
} else {
3942
let mut limit = raw.take(len as u64);
40-
elements.push(Some(try!(FromSql::from_sql(&element_type, &mut limit))));
43+
elements.push(Some(try!(FromSql::from_sql(&element_type, &mut limit, info))));
4144
if limit.limit() != 0 {
42-
return Err(Error::BadResponse);
45+
let err: Box<error::Error+Sync+Send> =
46+
"from_sql call did not consume all data".into();
47+
return Err(Error::Conversion(err));
4348
}
4449
}
4550
}
@@ -56,15 +61,16 @@ impl<T> FromSql for Array<Option<T>> where T: FromSql {
5661
}
5762

5863
impl<T> ToSql for Array<T> where T: ToSql {
59-
fn to_sql<W: ?Sized+Write>(&self, ty: &Type, mut w: &mut W) -> postgres::Result<IsNull> {
64+
fn to_sql<W: ?Sized+Write>(&self, ty: &Type, mut w: &mut W, info: &SessionInfo)
65+
-> postgres::Result<IsNull> {
6066
let element_type = match ty.kind() {
6167
&Kind::Array(ref ty) => ty,
6268
_ => panic!("unexpected type {:?}", ty),
6369
};
6470

6571
try!(w.write_u32::<BigEndian>(self.dimensions().len() as u32));
6672
try!(w.write_i32::<BigEndian>(1));
67-
try!(w.write_u32::<BigEndian>(element_type.to_oid()));
73+
try!(w.write_u32::<BigEndian>(element_type.oid()));
6874

6975
for info in self.dimensions() {
7076
try!(w.write_u32::<BigEndian>(info.len as u32));
@@ -73,7 +79,7 @@ impl<T> ToSql for Array<T> where T: ToSql {
7379

7480
let mut inner_buf = vec![];
7581
for v in self {
76-
match try!(v.to_sql(element_type, &mut inner_buf)) {
82+
match try!(v.to_sql(element_type, &mut inner_buf, info)) {
7783
IsNull::Yes => try!(w.write_i32::<BigEndian>(-1)),
7884
IsNull::No => {
7985
try!(w.write_i32::<BigEndian>(inner_buf.len() as i32));
@@ -100,7 +106,8 @@ impl<T> ToSql for Array<T> where T: ToSql {
100106
mod test {
101107
use std::fmt;
102108

103-
use postgres::{Connection, SslMode, FromSql, ToSql};
109+
use postgres::{Connection, SslMode};
110+
use postgres::types::{FromSql, ToSql};
104111
use Array;
105112

106113
fn test_type<T: PartialEq+FromSql+ToSql, S: fmt::Display>(sql_type: &str, checks: &[(T, S)]) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy