From 7a84a16b41d11e8264503fbadc766f3bc81bba7f Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Sat, 30 Aug 2014 10:25:38 +0100 Subject: [PATCH] Get things building again I'm temporarily diabling arrays until I have a chance to look over and make sure the API is sound. This also works around a trait object coercion regression: rust-lang/rust#16861 --- src/types/array.rs | 4 ++-- src/types/mod.rs | 8 ++++++-- src/types/range.rs | 2 +- tests/test.rs | 30 +++++++++++++++--------------- tests/types/mod.rs | 16 ++++++++++------ 5 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/types/array.rs b/src/types/array.rs index 4bfb5764..5d33ff73 100644 --- a/src/types/array.rs +++ b/src/types/array.rs @@ -201,14 +201,14 @@ impl InternalMutableArray for ArrayBase { } } -enum ArrayParent<'parent, T> { +enum ArrayParent<'parent, T:'parent> { SliceParent(&'parent ArraySlice<'static, T>), MutSliceParent(&'parent MutArraySlice<'static, T>), BaseParent(&'parent ArrayBase), } /// An immutable slice of a multi-dimensional array -pub struct ArraySlice<'parent, T> { +pub struct ArraySlice<'parent, T:'parent> { parent: ArrayParent<'parent, T>, idx: uint, } diff --git a/src/types/mod.rs b/src/types/mod.rs index 7e9a4db8..f4eadf26 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -10,10 +10,10 @@ use time::Timespec; use PostgresResult; use error::{PgWrongType, PgStreamError, PgWasNull, PgBadData}; -use types::array::{Array, ArrayBase, DimensionInfo}; +//use types::array::{Array, ArrayBase, DimensionInfo}; use types::range::{RangeBound, Inclusive, Exclusive, Range}; -pub mod array; +//pub mod array; pub mod range; /// A Postgres OID @@ -423,6 +423,7 @@ macro_rules! from_array_impl( ) ) +/* from_array_impl!(PgBoolArray, bool) from_array_impl!(PgByteAArray, Vec) from_array_impl!(PgCharArray, i8) @@ -437,6 +438,7 @@ from_array_impl!(PgFloat8Array, f64) from_array_impl!(PgInt4RangeArray, Range) from_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range) from_array_impl!(PgInt8RangeArray, Range) +*/ impl FromSql for Option>> { fn from_sql(ty: &PostgresType, raw: &Option>) @@ -726,6 +728,7 @@ macro_rules! to_array_impl( ) ) +/* to_array_impl!(PgBoolArray, bool) to_array_impl!(PgByteAArray, Vec) to_array_impl!(PgCharArray, i8) @@ -740,6 +743,7 @@ to_array_impl!(PgInt4RangeArray, Range) to_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range) to_array_impl!(PgInt8RangeArray, Range) to_array_impl!(PgJsonArray, Json) +*/ impl ToSql for HashMap> { fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option>)> { diff --git a/src/types/range.rs b/src/types/range.rs index f71fad44..8546f87c 100644 --- a/src/types/range.rs +++ b/src/types/range.rs @@ -267,7 +267,7 @@ impl RangeBound { } } -struct OptBound<'a, S, T>(Option<&'a RangeBound>); +struct OptBound<'a, S, T:'a>(Option<&'a RangeBound>); impl<'a, S: BoundSided, T: PartialEq> PartialEq for OptBound<'a, S, T> { fn eq(&self, &OptBound(ref other): &OptBound<'a, S, T>) -> bool { diff --git a/tests/test.rs b/tests/test.rs index cf65eb97..483e91dc 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -35,7 +35,7 @@ use postgres::error::{PgConnectDbError, InvalidCatalogName, PgWrongTransaction, CardinalityViolation}; -use postgres::types::{PgInt4, PgVarchar}; +use postgres::types::{PgInt4, PgVarchar, ToSql}; macro_rules! or_fail( ($e:expr) => ( @@ -108,7 +108,7 @@ fn test_transaction_commit() { or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32])); + or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql])); trans.set_commit(); drop(trans); @@ -124,7 +124,7 @@ fn test_transaction_commit_finish() { or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32])); + or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql])); trans.set_commit(); assert!(trans.finish().is_ok()); @@ -140,7 +140,7 @@ fn test_transaction_commit_method() { or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32])); + or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql])); assert!(trans.commit().is_ok()); let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); @@ -154,10 +154,10 @@ fn test_transaction_rollback() { let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); - or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32])); + or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql])); let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32])); + or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32 as &ToSql])); drop(trans); let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); @@ -171,10 +171,10 @@ fn test_transaction_rollback_finish() { let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); - or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32])); + or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql])); let trans = or_fail!(conn.transaction()); - or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32])); + or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32 as &ToSql])); assert!(trans.finish().is_ok()); let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); @@ -373,7 +373,7 @@ fn test_query() { let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", [])); or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1), ($2)", - [&1i64, &2i64])); + [&1i64 as &ToSql, &2i64 as &ToSql])); let stmt = or_fail!(conn.prepare("SELECT * from foo ORDER BY id")); let result = or_fail!(stmt.query([])); @@ -415,7 +415,7 @@ fn test_lazy_query() { let stmt = or_fail!(trans.prepare("INSERT INTO foo (id) VALUES ($1)")); let values = vec!(0i32, 1, 2, 3, 4, 5); for value in values.iter() { - or_fail!(stmt.execute([value])); + or_fail!(stmt.execute([value as &ToSql])); } let stmt = or_fail!(trans.prepare("SELECT id FROM foo ORDER BY id")); let result = or_fail!(trans.lazy_query(&stmt, [], 2)); @@ -440,7 +440,7 @@ fn test_lazy_query_wrong_conn() { fn test_param_types() { let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); let stmt = or_fail!(conn.prepare("SELECT $1::INT, $2::VARCHAR")); - assert_eq!(stmt.param_types(), &[PgInt4, PgVarchar]); + assert_eq!(stmt.param_types(), [PgInt4, PgVarchar].as_slice()); } #[test] @@ -460,7 +460,7 @@ fn test_execute_counts() { b INT )", []))); assert_eq!(3, or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($2)", - [&1i32, &2i32]))); + [&1i32 as &ToSql, &2i32 as &ToSql]))); assert_eq!(2, or_fail!(conn.execute("UPDATE foo SET b = 0 WHERE b = 2", []))); assert_eq!(3, or_fail!(conn.execute("SELECT * FROM foo", []))); } @@ -468,7 +468,7 @@ fn test_execute_counts() { #[test] fn test_wrong_param_type() { let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - match conn.execute("SELECT $1::VARCHAR", [&1i32]) { + match conn.execute("SELECT $1::VARCHAR", [&1i32 as &ToSql]) { Err(PgWrongType(_)) => {} res => fail!("unexpected result {}", res) } @@ -477,7 +477,7 @@ fn test_wrong_param_type() { #[test] fn test_too_few_params() { let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - match conn.execute("SELECT $1::INT, $2::INT", [&1i32]) { + match conn.execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql]) { Err(PgWrongParamCount { expected: 2, actual: 1 }) => {}, res => fail!("unexpected result {}", res) } @@ -486,7 +486,7 @@ fn test_too_few_params() { #[test] fn test_too_many_params() { let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); - match conn.execute("SELECT $1::INT, $2::INT", [&1i32, &2i32, &3i32]) { + match conn.execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql, &2i32 as &ToSql, &3i32 as &ToSql]) { Err(PgWrongParamCount { expected: 2, actual: 3 }) => {}, res => fail!("unexpected result {}", res) } diff --git a/tests/types/mod.rs b/tests/types/mod.rs index 00b32de3..c8724b42 100644 --- a/tests/types/mod.rs +++ b/tests/types/mod.rs @@ -6,10 +6,10 @@ use time; use time::Timespec; use postgres::{PostgresConnection, NoSsl}; -use postgres::types::array::ArrayBase; +//use postgres::types::array::ArrayBase; use postgres::types::{ToSql, FromSql}; -mod array; +//mod array; mod range; fn test_type(sql_type: &str, checks: &[(T, S)]) { @@ -20,7 +20,7 @@ fn test_type(sql_type: &str, checks: &[(T, S assert!(val == &result); let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type).as_slice())); - let result = or_fail!(stmt.query([val])).next().unwrap().get(0u); + let result = or_fail!(stmt.query([val as &ToSql])).next().unwrap().get(0u); assert!(val == &result); } } @@ -99,8 +99,8 @@ fn test_bpchar_params() { b CHAR(5) )", [])); or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($3)", - [&Some("12345"), &Some("123"), - &None::<&'static str>])); + [&Some("12345") as &ToSql, &Some("123") as &ToSql, + &None::<&'static str> as &ToSql])); let stmt = or_fail!(conn.prepare("SELECT b FROM foo ORDER BY id")); let res = or_fail!(stmt.query([])); @@ -205,6 +205,7 @@ macro_rules! test_array_params( }) ) +/* #[test] fn test_boolarray_params() { test_array_params!("BOOL", false, "f", true, "t", true, "t"); @@ -315,6 +316,7 @@ fn test_int8rangearray_params() { range!('[' 10i64, ')'), "\"[10,)\"", range!('(', 10i64 ')'), "\"(,10)\""); } +*/ #[test] fn test_hstore_params() { @@ -343,7 +345,7 @@ fn test_nan_param(sql_type: &str) { let nan: T = Float::nan(); let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type).as_slice())); - let mut result = or_fail!(stmt.query([&nan])); + let mut result = or_fail!(stmt.query([&nan as &ToSql])); let val: T = result.next().unwrap().get(0u); assert!(val.is_nan()) } @@ -358,6 +360,7 @@ fn test_f64_nan_param() { test_nan_param::("DOUBLE PRECISION"); } +/* #[test] fn test_jsonarray_params() { test_array_params!("JSON", @@ -368,6 +371,7 @@ fn test_jsonarray_params() { json::from_str(r#"{"a": [10], "b": true}"#).unwrap(), r#""{\"a\": [10], \"b\": true}""#); } +*/ #[test] fn test_pg_database_datname() {