Fix for upstream changes
This commit is contained in:
parent
c99322f263
commit
a8d67a1fe4
37
src/error.rs
37
src/error.rs
@ -4,6 +4,7 @@ use byteorder;
|
||||
use openssl::ssl::error::SslError;
|
||||
use phf;
|
||||
use std::error;
|
||||
use std::convert::From;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
|
||||
@ -13,7 +14,7 @@ use types::Type;
|
||||
include!(concat!(env!("OUT_DIR"), "/sqlstate.rs"));
|
||||
|
||||
/// Reasons a new Postgres connection could fail
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub enum ConnectError {
|
||||
/// The provided URL could not be parsed
|
||||
InvalidUrl(String),
|
||||
@ -73,27 +74,27 @@ impl error::Error for ConnectError {
|
||||
}
|
||||
}
|
||||
|
||||
impl error::FromError<io::Error> for ConnectError {
|
||||
fn from_error(err: io::Error) -> ConnectError {
|
||||
impl From<io::Error> for ConnectError {
|
||||
fn from(err: io::Error) -> ConnectError {
|
||||
ConnectError::IoError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl error::FromError<DbError> for ConnectError {
|
||||
fn from_error(err: DbError) -> ConnectError {
|
||||
impl From<DbError> for ConnectError {
|
||||
fn from(err: DbError) -> ConnectError {
|
||||
ConnectError::DbError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl error::FromError<SslError> for ConnectError {
|
||||
fn from_error(err: SslError) -> ConnectError {
|
||||
impl From<SslError> for ConnectError {
|
||||
fn from(err: SslError) -> ConnectError {
|
||||
ConnectError::SslError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl error::FromError<byteorder::Error> for ConnectError {
|
||||
fn from_error(err: byteorder::Error) -> ConnectError {
|
||||
ConnectError::IoError(error::FromError::from_error(err))
|
||||
impl From<byteorder::Error> for ConnectError {
|
||||
fn from(err: byteorder::Error) -> ConnectError {
|
||||
ConnectError::IoError(From::from(err))
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +113,7 @@ pub enum ErrorPosition {
|
||||
}
|
||||
|
||||
/// An error encountered when communicating with the Postgres server
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// An error reported by the Postgres server
|
||||
DbError(DbError),
|
||||
@ -166,20 +167,20 @@ impl error::Error for Error {
|
||||
}
|
||||
}
|
||||
|
||||
impl error::FromError<DbError> for Error {
|
||||
fn from_error(err: DbError) -> Error {
|
||||
impl From<DbError> for Error {
|
||||
fn from(err: DbError) -> Error {
|
||||
Error::DbError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl error::FromError<io::Error> for Error {
|
||||
fn from_error(err: io::Error) -> Error {
|
||||
impl From<io::Error> for Error {
|
||||
fn from(err: io::Error) -> Error {
|
||||
Error::IoError(err)
|
||||
}
|
||||
}
|
||||
|
||||
impl error::FromError<byteorder::Error> for Error {
|
||||
fn from_error(err: byteorder::Error) -> Error {
|
||||
Error::IoError(error::FromError::from_error(err))
|
||||
impl From<byteorder::Error> for Error {
|
||||
fn from(err: byteorder::Error) -> Error {
|
||||
Error::IoError(From::from(err))
|
||||
}
|
||||
}
|
||||
|
@ -43,8 +43,6 @@
|
||||
//! }
|
||||
//! ```
|
||||
#![doc(html_root_url="https://sfackler.github.io/rust-postgres/doc")]
|
||||
#![feature(io)]
|
||||
#![cfg_attr(feature = "unix_socket", feature(convert))]
|
||||
#![warn(missing_docs)]
|
||||
|
||||
extern crate byteorder;
|
||||
|
@ -4,7 +4,7 @@ macro_rules! try_desync {
|
||||
Ok(ok) => ok,
|
||||
Err(err) => {
|
||||
$s.desynchronized = true;
|
||||
return Err(::std::error::FromError::from_error(err));
|
||||
return Err(::std::convert::From::from(err));
|
||||
}
|
||||
}
|
||||
)
|
||||
|
@ -264,8 +264,7 @@ impl<R: BufRead> ReadCStr for R {
|
||||
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",
|
||||
None))
|
||||
"received a non-utf8 string from server"))
|
||||
}
|
||||
}
|
||||
|
||||
@ -321,14 +320,14 @@ 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()) },
|
||||
ident => {
|
||||
_ => {
|
||||
return Err(io::Error::new(io::ErrorKind::Other,
|
||||
"unexpected message tag",
|
||||
Some(format!("got {}", ident))))
|
||||
"unexpected message tag"))
|
||||
|
||||
}
|
||||
};
|
||||
if rdr.limit() != 0 {
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "didn't read entire message", None));
|
||||
return Err(io::Error::new(io::ErrorKind::Other, "didn't read entire message"));
|
||||
}
|
||||
Ok(ret)
|
||||
}
|
||||
@ -381,10 +380,9 @@ fn read_auth_message<R: Read>(buf: &mut R) -> io::Result<BackendMessage> {
|
||||
6 => AuthenticationSCMCredential,
|
||||
7 => AuthenticationGSS,
|
||||
9 => AuthenticationSSPI,
|
||||
val => {
|
||||
_ => {
|
||||
return Err(io::Error::new(io::ErrorKind::Other,
|
||||
"unexpected authentication tag",
|
||||
Some(format!("got {}", val))));
|
||||
"unexpected authentication tag"));
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -150,7 +150,7 @@ fn decode_inner(c: &str, full_url: bool) -> DecodeResult<String> {
|
||||
}
|
||||
|
||||
fn split_char_first(s: &str, c: char) -> (&str, &str) {
|
||||
let mut iter = s.splitn(1, c);
|
||||
let mut iter = s.splitn(2, c);
|
||||
|
||||
match (iter.next(), iter.next()) {
|
||||
(Some(a), Some(b)) => (a, b),
|
||||
|
@ -22,7 +22,7 @@ pub fn read_all<R: Read>(r: &mut R, mut buf: &mut [u8]) -> io::Result<()> {
|
||||
let mut start = 0;
|
||||
while start != buf.len() {
|
||||
match r.read(&mut buf[start..]) {
|
||||
Ok(0) => return Err(io::Error::new(io::ErrorKind::Other, "unexpected EOF", None)),
|
||||
Ok(0) => return Err(io::Error::new(io::ErrorKind::Other, "unexpected EOF")),
|
||||
Ok(len) => start += len,
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
|
@ -1,5 +1,3 @@
|
||||
#![feature(std_misc, thread_sleep)]
|
||||
|
||||
extern crate postgres;
|
||||
extern crate rustc_serialize as serialize;
|
||||
extern crate url;
|
||||
@ -7,7 +5,6 @@ extern crate openssl;
|
||||
|
||||
use openssl::ssl::SslContext;
|
||||
use openssl::ssl::SslMethod;
|
||||
use std::time::Duration;
|
||||
use std::thread;
|
||||
|
||||
use postgres::{HandleNotice,
|
||||
@ -596,7 +593,7 @@ fn test_notifications_next_block() {
|
||||
|
||||
let _t = thread::spawn(|| {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
thread::sleep(Duration::milliseconds(500));
|
||||
thread::sleep_ms(500);
|
||||
or_panic!(conn.execute("NOTIFY test_notifications_next_block, 'foo'", &[]));
|
||||
});
|
||||
|
||||
@ -657,7 +654,7 @@ fn test_cancel_query() {
|
||||
let cancel_data = conn.cancel_data();
|
||||
|
||||
let _t = thread::spawn(move || {
|
||||
thread::sleep(Duration::milliseconds(500));
|
||||
thread::sleep_ms(500);
|
||||
assert!(postgres::cancel_query("postgres://postgres@localhost", &SslMode::None,
|
||||
cancel_data).is_ok());
|
||||
});
|
||||
@ -764,7 +761,7 @@ fn test_copy_in() {
|
||||
Box::new(format!("{}", i))])
|
||||
});
|
||||
|
||||
assert_eq!(Ok(2), stmt.execute(data));
|
||||
assert_eq!(2, stmt.execute(data).unwrap());
|
||||
|
||||
let stmt = or_panic!(conn.prepare("SELECT id, name FROM foo ORDER BY id"));
|
||||
assert_eq!(vec![(0i32, Some("0".to_string())), (1, Some("1".to_string()))],
|
||||
@ -881,15 +878,15 @@ fn test_prepare_cached() {
|
||||
or_panic!(conn.execute("INSERT INTO foo (id) VALUES (1), (2)", &[]));
|
||||
|
||||
let stmt = or_panic!(conn.prepare_cached("SELECT id FROM foo ORDER BY id"));
|
||||
assert_eq!(&[1, 2][..], or_panic!(stmt.query(&[])).iter().map(|r| r.get(0)).collect::<Vec<i32>>());
|
||||
assert_eq!(vec![1, 2], or_panic!(stmt.query(&[])).iter().map(|r| r.get(0)).collect::<Vec<i32>>());
|
||||
or_panic!(stmt.finish());
|
||||
|
||||
let stmt = or_panic!(conn.prepare_cached("SELECT id FROM foo ORDER BY id"));
|
||||
assert_eq!(&[1, 2][..], or_panic!(stmt.query(&[])).iter().map(|r| r.get(0)).collect::<Vec<i32>>());
|
||||
assert_eq!(vec![1, 2], or_panic!(stmt.query(&[])).iter().map(|r| r.get(0)).collect::<Vec<i32>>());
|
||||
or_panic!(stmt.finish());
|
||||
|
||||
let stmt = or_panic!(conn.prepare_cached("SELECT id FROM foo ORDER BY id DESC"));
|
||||
assert_eq!(&[2, 1][..], or_panic!(stmt.query(&[])).iter().map(|r| r.get(0)).collect::<Vec<i32>>());
|
||||
assert_eq!(vec![2, 1], or_panic!(stmt.query(&[])).iter().map(|r| r.get(0)).collect::<Vec<i32>>());
|
||||
or_panic!(stmt.finish());
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,6 @@ use std::collections::HashMap;
|
||||
use std::f32;
|
||||
use std::f64;
|
||||
use std::fmt;
|
||||
use std::num::Float;
|
||||
|
||||
use postgres::{Connection, SslMode, Slice, Error};
|
||||
use postgres::types::{ToSql, FromSql};
|
||||
@ -154,18 +153,12 @@ fn test_hstore_params() {
|
||||
(None, "NULL")]);
|
||||
}
|
||||
|
||||
fn test_nan_param<T: Float+ToSql+FromSql>(sql_type: &str) {
|
||||
fn test_nan_param<T: PartialEq+ToSql+FromSql>(sql_type: &str) {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare(&*format!("SELECT 'NaN'::{}", sql_type)));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
let val: T = result.iter().next().unwrap().get(0);
|
||||
assert!(val.is_nan());
|
||||
|
||||
let nan: T = Float::nan();
|
||||
let stmt = or_panic!(conn.prepare(&*format!("SELECT $1::{}", sql_type)));
|
||||
let result = or_panic!(stmt.query(&[&nan]));
|
||||
let val: T = result.iter().next().unwrap().get(0);
|
||||
assert!(val.is_nan())
|
||||
assert!(val != val);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -197,7 +190,7 @@ fn test_slice() {
|
||||
|
||||
let stmt = conn.prepare("SELECT f FROM foo WHERE id = ANY($1)").unwrap();
|
||||
let result = stmt.query(&[&Slice(&[1i32, 3, 4])]).unwrap();
|
||||
assert_eq!(&["a".to_string(), "c".to_string(), "d".to_string()][..],
|
||||
assert_eq!(vec!["a".to_string(), "c".to_string(), "d".to_string()],
|
||||
result.iter().map(|r| r.get::<_, String>(0)).collect::<Vec<_>>());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user