Update for API changes

Lots of stuff this time!
This commit is contained in:
Steven Fackler 2014-01-30 23:44:44 -05:00
parent 832316967b
commit 2c55ae5669
4 changed files with 34 additions and 33 deletions

@ -1 +1 @@
Subproject commit 3491ce3add5a93db2decf61d160daf3424f6cf3d
Subproject commit d752241bf21e60575bf89f24c4359b34aef20d9c

View File

@ -41,18 +41,18 @@ fn test_pool() {
let (stream1, stream2) = DuplexStream::<(), ()>::new();
let pool1 = pool.clone();
let mut fut1 = do Future::spawn {
let mut fut1 = Future::spawn(proc() {
let _conn = pool1.get_connection();
stream1.send(());
stream1.recv();
};
});
let pool2 = pool.clone();
let mut fut2 = do Future::spawn {
let mut fut2 = Future::spawn(proc() {
let _conn = pool2.get_connection();
stream2.send(());
stream2.recv();
};
});
fut1.get();
fut2.get();
@ -581,23 +581,23 @@ fn test_f64_nan_param() {
#[should_fail]
fn test_wrong_param_type() {
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
conn.try_execute("SELECT $1::VARCHAR", [&1i32 as &ToSql]);
let _ = conn.try_execute("SELECT $1::VARCHAR", [&1i32 as &ToSql]);
}
#[test]
#[should_fail]
fn test_too_few_params() {
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
conn.try_execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql]);
let _ = conn.try_execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql]);
}
#[test]
#[should_fail]
fn test_too_many_params() {
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
conn.try_execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql,
&2i32 as &ToSql,
&3i32 as &ToSql]);
let _ = conn.try_execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql,
&2i32 as &ToSql,
&3i32 as &ToSql]);
}
#[test]
@ -695,11 +695,11 @@ fn test_cancel_query() {
let conn = PostgresConnection::connect("postgres://postgres@localhost", &NoSsl);
let cancel_data = conn.cancel_data();
do spawn {
spawn(proc() {
timer::sleep(500);
assert!(super::cancel_query("postgres://postgres@localhost", &NoSsl,
cancel_data).is_ok());
}
});
match conn.try_execute("SELECT pg_sleep(10)", []) {
Err(PostgresDbError { code: QueryCanceled, .. }) => {}

View File

@ -545,15 +545,15 @@ macro_rules! to_range_impl(
if self.is_empty() {
tag |= RANGE_EMPTY;
} else {
match *self.lower() {
match self.lower() {
None => tag |= RANGE_LOWER_UNBOUNDED,
Some(RangeBound { type_: Inclusive, .. }) =>
Some(&RangeBound { type_: Inclusive, .. }) =>
tag |= RANGE_LOWER_INCLUSIVE,
_ => {}
}
match *self.upper() {
match self.upper() {
None => tag |= RANGE_UPPER_UNBOUNDED,
Some(RangeBound { type_: Inclusive, .. }) =>
Some(&RangeBound { type_: Inclusive, .. }) =>
tag |= RANGE_UPPER_INCLUSIVE,
_ => {}
}
@ -561,8 +561,8 @@ macro_rules! to_range_impl(
buf.write_i8(tag);
match *self.lower() {
Some(ref bound) => {
match self.lower() {
Some(bound) => {
let mut inner_buf = MemWriter::new();
bound.value.raw_to_sql(&mut inner_buf);
let inner_buf = inner_buf.unwrap();
@ -571,8 +571,8 @@ macro_rules! to_range_impl(
}
None => {}
}
match *self.upper() {
Some(ref bound) => {
match self.upper() {
Some(bound) => {
let mut inner_buf = MemWriter::new();
bound.value.raw_to_sql(&mut inner_buf);
let inner_buf = inner_buf.unwrap();

View File

@ -207,15 +207,15 @@ impl<S: BoundSided, T: Ord> RangeBound<S, T> {
}
}
struct OptBound<'a, S, T>(&'a Option<RangeBound<S, T>>);
struct OptBound<'a, S, T>(Option<&'a RangeBound<S, T>>);
impl<'a, S: BoundSided, T: Ord> Ord for OptBound<'a, S, T> {
fn lt(&self, other: &OptBound<'a, S, T>) -> bool {
match (*self, *other) {
(OptBound(&None), OptBound(&None)) => false,
(OptBound(&None), _) => BoundSided::side(None::<S>) == Lower,
(_, OptBound(&None)) => BoundSided::side(None::<S>) == Upper,
(OptBound(&Some(ref a)), OptBound(&Some(ref b))) => a < b
(OptBound(None), OptBound(None)) => false,
(OptBound(None), _) => BoundSided::side(None::<S>) == Lower,
(_, OptBound(None)) => BoundSided::side(None::<S>) == Upper,
(OptBound(Some(a)), OptBound(Some(b))) => a < b
}
}
}
@ -267,18 +267,18 @@ impl<T: Ord+Normalizable> Range<T> {
}
/// Returns the lower bound if it exists.
pub fn lower<'a>(&'a self) -> &'a Option<RangeBound<LowerBound, T>> {
pub fn lower<'a>(&'a self) -> Option<&'a RangeBound<LowerBound, T>> {
match *self {
Empty => &None,
Normal(ref lower, _) => lower
Normal(Some(ref lower), _) => Some(lower),
_ => None
}
}
/// Returns the upper bound if it exists.
pub fn upper<'a>(&'a self) -> &'a Option<RangeBound<UpperBound, T>> {
pub fn upper<'a>(&'a self) -> Option<&'a RangeBound<UpperBound, T>> {
match *self {
Empty => &None,
Normal(_, ref upper) => upper
Normal(_, Some(ref upper)) => Some(upper),
_ => None
}
}
@ -320,7 +320,7 @@ impl<T: Ord+Normalizable+Clone> Range<T> {
let OptBound(upper) = cmp::min(OptBound(self.upper()),
OptBound(other.upper()));
Range::new(lower.clone(), upper.clone())
Range::new(lower.map(|v| v.clone()), upper.map(|v| v.clone()))
}
}
@ -467,7 +467,8 @@ mod test {
assert_eq!(r1, (range!('(', ')')).intersect(&r1));
let r2 = range!('(' 10i32, ')');
let exp = Range::new(r2.lower().clone(), r1.upper().clone());
let exp = Range::new(r2.lower().map(|v| v.clone()),
r1.upper().map(|v| v.clone()));
assert_eq!(exp, r1.intersect(&r2));
assert_eq!(exp, r2.intersect(&r1));