Cleanup
This commit is contained in:
parent
704d15bece
commit
4b877e0a33
@ -115,7 +115,7 @@ pub enum ConnectTarget {
|
||||
Unix(PathBuf)
|
||||
}
|
||||
|
||||
/// Authentication information
|
||||
/// Authentication information.
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct UserInfo {
|
||||
/// The username
|
||||
@ -502,7 +502,8 @@ impl InnerConnection {
|
||||
}
|
||||
|
||||
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") {
|
||||
Ok(..) => Ok(()),
|
||||
Err(Error::IoError(e)) => Err(ConnectError::IoError(e)),
|
||||
|
@ -263,8 +263,7 @@ impl<R: BufRead> ReadCStr for R {
|
||||
let mut buf = vec![];
|
||||
try!(self.read_until(0, &mut buf));
|
||||
buf.pop();
|
||||
String::from_utf8(buf).map_err(|_| io::Error::new(io::ErrorKind::Other,
|
||||
"received a non-utf8 string from server"))
|
||||
String::from_utf8(buf).map_err(|err| io::Error::new(io::ErrorKind::Other, err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -320,11 +319,7 @@ impl<R: BufRead> ReadMessage for R {
|
||||
b't' => try!(read_parameter_description(&mut rdr)),
|
||||
b'T' => try!(read_row_description(&mut rdr)),
|
||||
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 {
|
||||
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,
|
||||
7 => AuthenticationGSS,
|
||||
9 => AuthenticationSSPI,
|
||||
_ => {
|
||||
return Err(io::Error::new(io::ErrorKind::Other,
|
||||
"unexpected authentication tag"));
|
||||
}
|
||||
_ => return Err(io::Error::new(io::ErrorKind::Other, "unexpected authentication tag")),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ use byteorder::{ReadBytesExt, WriteBytesExt, BigEndian};
|
||||
|
||||
use Result;
|
||||
use error::Error;
|
||||
use util;
|
||||
|
||||
pub use ugh_privacy::Other;
|
||||
|
||||
@ -106,7 +107,16 @@ macro_rules! make_postgres_type {
|
||||
}
|
||||
|
||||
/// Returns the OID of the `Type`.
|
||||
///
|
||||
/// # Deprecated
|
||||
///
|
||||
/// Use `oid` instead.
|
||||
pub fn to_oid(&self) -> Oid {
|
||||
self.oid()
|
||||
}
|
||||
|
||||
/// Returns the OID of the `Type`.
|
||||
pub fn oid(&self) -> Oid {
|
||||
match *self {
|
||||
$(Type::$variant => as_expr!($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`.
|
||||
///
|
||||
/// 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 {
|
||||
let key_len = try!(raw.read_i32::<BigEndian>());
|
||||
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) {
|
||||
Ok(key) => key,
|
||||
Err(_) => return Err(Error::BadResponse),
|
||||
@ -575,7 +586,8 @@ impl FromSql for HashMap<String, Option<String>> {
|
||||
None
|
||||
} else {
|
||||
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) {
|
||||
Ok(val) => Some(val),
|
||||
Err(_) => return Err(Error::BadResponse),
|
||||
|
@ -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>(0)); // index offset
|
||||
|
||||
for e in self.0 {
|
||||
let mut inner_buf = vec![];
|
||||
for e in self.0 {
|
||||
match try!(e.to_sql(&member_type, &mut inner_buf)) {
|
||||
IsNull::No => {
|
||||
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)),
|
||||
}
|
||||
inner_buf.clear();
|
||||
}
|
||||
|
||||
Ok(IsNull::No)
|
||||
|
@ -57,7 +57,7 @@ pub struct DbError {
|
||||
constraint: Option<String>,
|
||||
file: String,
|
||||
line: u32,
|
||||
routine: String
|
||||
routine: String,
|
||||
}
|
||||
|
||||
pub fn dberror_new_raw(fields: Vec<(u8, String)>) -> result::Result<DbError, ()> {
|
||||
|
Loading…
Reference in New Issue
Block a user