This commit is contained in:
Steven Fackler 2015-04-07 23:57:22 -07:00
parent 704d15bece
commit 4b877e0a33
5 changed files with 24 additions and 18 deletions

View File

@ -115,7 +115,7 @@ pub enum ConnectTarget {
Unix(PathBuf) Unix(PathBuf)
} }
/// Authentication information /// Authentication information.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct UserInfo { pub struct UserInfo {
/// The username /// The username
@ -502,7 +502,8 @@ impl InnerConnection {
} }
match self.raw_prepare(TYPEINFO_QUERY, match self.raw_prepare(TYPEINFO_QUERY,
"SELECT typname, typelem, NULL::OID FROM pg_catalog.pg_type \ "SELECT typname, typelem, NULL::OID \
FROM pg_catalog.pg_type \
WHERE oid = $1") { WHERE oid = $1") {
Ok(..) => Ok(()), Ok(..) => Ok(()),
Err(Error::IoError(e)) => Err(ConnectError::IoError(e)), Err(Error::IoError(e)) => Err(ConnectError::IoError(e)),

View File

@ -263,8 +263,7 @@ impl<R: BufRead> ReadCStr for R {
let mut buf = vec![]; let mut buf = vec![];
try!(self.read_until(0, &mut buf)); try!(self.read_until(0, &mut buf));
buf.pop(); buf.pop();
String::from_utf8(buf).map_err(|_| io::Error::new(io::ErrorKind::Other, String::from_utf8(buf).map_err(|err| io::Error::new(io::ErrorKind::Other, err))
"received a non-utf8 string from server"))
} }
} }
@ -320,11 +319,7 @@ impl<R: BufRead> ReadMessage for R {
b't' => try!(read_parameter_description(&mut rdr)), b't' => try!(read_parameter_description(&mut rdr)),
b'T' => try!(read_row_description(&mut rdr)), b'T' => try!(read_row_description(&mut rdr)),
b'Z' => ReadyForQuery { _state: try!(rdr.read_u8()) }, b'Z' => ReadyForQuery { _state: try!(rdr.read_u8()) },
_ => { _ => return Err(io::Error::new(io::ErrorKind::Other, "unexpected message tag")),
return Err(io::Error::new(io::ErrorKind::Other,
"unexpected message tag"))
}
}; };
if rdr.limit() != 0 { if rdr.limit() != 0 {
return Err(io::Error::new(io::ErrorKind::Other, "didn't read entire message")); return Err(io::Error::new(io::ErrorKind::Other, "didn't read entire message"));
@ -380,10 +375,7 @@ fn read_auth_message<R: Read>(buf: &mut R) -> io::Result<BackendMessage> {
6 => AuthenticationSCMCredential, 6 => AuthenticationSCMCredential,
7 => AuthenticationGSS, 7 => AuthenticationGSS,
9 => AuthenticationSSPI, 9 => AuthenticationSSPI,
_ => { _ => return Err(io::Error::new(io::ErrorKind::Other, "unexpected authentication tag")),
return Err(io::Error::new(io::ErrorKind::Other,
"unexpected authentication tag"));
}
}) })
} }

View File

@ -8,6 +8,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
use Result; use Result;
use error::Error; use error::Error;
use util;
pub use ugh_privacy::Other; pub use ugh_privacy::Other;
@ -106,7 +107,16 @@ macro_rules! make_postgres_type {
} }
/// Returns the OID of the `Type`. /// Returns the OID of the `Type`.
///
/// # Deprecated
///
/// Use `oid` instead.
pub fn to_oid(&self) -> Oid { pub fn to_oid(&self) -> Oid {
self.oid()
}
/// Returns the OID of the `Type`.
pub fn oid(&self) -> Oid {
match *self { match *self {
$(Type::$variant => as_expr!($oid),)+ $(Type::$variant => as_expr!($oid),)+
Type::Other(ref u) => u.oid(), Type::Other(ref u) => u.oid(),
@ -464,7 +474,7 @@ pub trait FromSql: Sized {
} }
} }
/// Creates a new value of this type from a `Read` of the binary format /// Creates a new value of this type from a `Read`er of the binary format
/// of the specified Postgres `Type`. /// of the specified Postgres `Type`.
/// ///
/// The caller of this method is responsible for ensuring that this type /// The caller of this method is responsible for ensuring that this type
@ -564,7 +574,8 @@ impl FromSql for HashMap<String, Option<String>> {
for _ in 0..count { for _ in 0..count {
let key_len = try!(raw.read_i32::<BigEndian>()); let key_len = try!(raw.read_i32::<BigEndian>());
let mut key = vec![]; let mut key = vec![];
try!(raw.take(key_len as u64).read_to_end(&mut key)); key.extend((0..key_len).map(|_| 0));
try!(util::read_all(raw, &mut key));
let key = match String::from_utf8(key) { let key = match String::from_utf8(key) {
Ok(key) => key, Ok(key) => key,
Err(_) => return Err(Error::BadResponse), Err(_) => return Err(Error::BadResponse),
@ -575,7 +586,8 @@ impl FromSql for HashMap<String, Option<String>> {
None None
} else { } else {
let mut val = vec![]; let mut val = vec![];
try!(raw.take(val_len as u64).read_to_end(&mut val)); val.extend((0..val_len).map(|_| 0));
try!(util::read_all(raw, &mut val));
match String::from_utf8(val) { match String::from_utf8(val) {
Ok(val) => Some(val), Ok(val) => Some(val),
Err(_) => return Err(Error::BadResponse), Err(_) => return Err(Error::BadResponse),

View File

@ -46,8 +46,8 @@ impl<'a, T: 'a + ToSql> ToSql for Slice<'a, T> {
try!(w.write_i32::<BigEndian>(self.0.len() as i32)); try!(w.write_i32::<BigEndian>(self.0.len() as i32));
try!(w.write_i32::<BigEndian>(0)); // index offset try!(w.write_i32::<BigEndian>(0)); // index offset
for e in self.0 {
let mut inner_buf = vec![]; let mut inner_buf = vec![];
for e in self.0 {
match try!(e.to_sql(&member_type, &mut inner_buf)) { match try!(e.to_sql(&member_type, &mut inner_buf)) {
IsNull::No => { IsNull::No => {
try!(w.write_i32::<BigEndian>(inner_buf.len() as i32)); try!(w.write_i32::<BigEndian>(inner_buf.len() as i32));
@ -55,6 +55,7 @@ impl<'a, T: 'a + ToSql> ToSql for Slice<'a, T> {
} }
IsNull::Yes => try!(w.write_i32::<BigEndian>(-1)), IsNull::Yes => try!(w.write_i32::<BigEndian>(-1)),
} }
inner_buf.clear();
} }
Ok(IsNull::No) Ok(IsNull::No)

View File

@ -57,7 +57,7 @@ pub struct DbError {
constraint: Option<String>, constraint: Option<String>,
file: String, file: String,
line: u32, line: u32,
routine: String routine: String,
} }
pub fn dberror_new_raw(fields: Vec<(u8, String)>) -> result::Result<DbError, ()> { pub fn dberror_new_raw(fields: Vec<(u8, String)>) -> result::Result<DbError, ()> {