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
This commit is contained in:
Steven Fackler 2014-08-30 10:25:38 +01:00
parent bf2497bf48
commit 7a84a16b41
5 changed files with 34 additions and 26 deletions

View File

@ -201,14 +201,14 @@ impl<T> InternalMutableArray<T> for ArrayBase<T> {
} }
} }
enum ArrayParent<'parent, T> { enum ArrayParent<'parent, T:'parent> {
SliceParent(&'parent ArraySlice<'static, T>), SliceParent(&'parent ArraySlice<'static, T>),
MutSliceParent(&'parent MutArraySlice<'static, T>), MutSliceParent(&'parent MutArraySlice<'static, T>),
BaseParent(&'parent ArrayBase<T>), BaseParent(&'parent ArrayBase<T>),
} }
/// An immutable slice of a multi-dimensional array /// An immutable slice of a multi-dimensional array
pub struct ArraySlice<'parent, T> { pub struct ArraySlice<'parent, T:'parent> {
parent: ArrayParent<'parent, T>, parent: ArrayParent<'parent, T>,
idx: uint, idx: uint,
} }

View File

@ -10,10 +10,10 @@ use time::Timespec;
use PostgresResult; use PostgresResult;
use error::{PgWrongType, PgStreamError, PgWasNull, PgBadData}; 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}; use types::range::{RangeBound, Inclusive, Exclusive, Range};
pub mod array; //pub mod array;
pub mod range; pub mod range;
/// A Postgres OID /// A Postgres OID
@ -423,6 +423,7 @@ macro_rules! from_array_impl(
) )
) )
/*
from_array_impl!(PgBoolArray, bool) from_array_impl!(PgBoolArray, bool)
from_array_impl!(PgByteAArray, Vec<u8>) from_array_impl!(PgByteAArray, Vec<u8>)
from_array_impl!(PgCharArray, i8) from_array_impl!(PgCharArray, i8)
@ -437,6 +438,7 @@ from_array_impl!(PgFloat8Array, f64)
from_array_impl!(PgInt4RangeArray, Range<i32>) from_array_impl!(PgInt4RangeArray, Range<i32>)
from_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>) from_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>)
from_array_impl!(PgInt8RangeArray, Range<i64>) from_array_impl!(PgInt8RangeArray, Range<i64>)
*/
impl FromSql for Option<HashMap<String, Option<String>>> { impl FromSql for Option<HashMap<String, Option<String>>> {
fn from_sql(ty: &PostgresType, raw: &Option<Vec<u8>>) fn from_sql(ty: &PostgresType, raw: &Option<Vec<u8>>)
@ -726,6 +728,7 @@ macro_rules! to_array_impl(
) )
) )
/*
to_array_impl!(PgBoolArray, bool) to_array_impl!(PgBoolArray, bool)
to_array_impl!(PgByteAArray, Vec<u8>) to_array_impl!(PgByteAArray, Vec<u8>)
to_array_impl!(PgCharArray, i8) to_array_impl!(PgCharArray, i8)
@ -740,6 +743,7 @@ to_array_impl!(PgInt4RangeArray, Range<i32>)
to_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>) to_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>)
to_array_impl!(PgInt8RangeArray, Range<i64>) to_array_impl!(PgInt8RangeArray, Range<i64>)
to_array_impl!(PgJsonArray, Json) to_array_impl!(PgJsonArray, Json)
*/
impl ToSql for HashMap<String, Option<String>> { impl ToSql for HashMap<String, Option<String>> {
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> { fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> {

View File

@ -267,7 +267,7 @@ impl<S: BoundSided, T: PartialOrd> RangeBound<S, T> {
} }
} }
struct OptBound<'a, S, T>(Option<&'a RangeBound<S, T>>); struct OptBound<'a, S, T:'a>(Option<&'a RangeBound<S, T>>);
impl<'a, S: BoundSided, T: PartialEq> PartialEq for OptBound<'a, S, T> { impl<'a, S: BoundSided, T: PartialEq> PartialEq for OptBound<'a, S, T> {
fn eq(&self, &OptBound(ref other): &OptBound<'a, S, T>) -> bool { fn eq(&self, &OptBound(ref other): &OptBound<'a, S, T>) -> bool {

View File

@ -35,7 +35,7 @@ use postgres::error::{PgConnectDbError,
InvalidCatalogName, InvalidCatalogName,
PgWrongTransaction, PgWrongTransaction,
CardinalityViolation}; CardinalityViolation};
use postgres::types::{PgInt4, PgVarchar}; use postgres::types::{PgInt4, PgVarchar, ToSql};
macro_rules! or_fail( macro_rules! or_fail(
($e:expr) => ( ($e:expr) => (
@ -108,7 +108,7 @@ fn test_transaction_commit() {
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
let trans = or_fail!(conn.transaction()); 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(); trans.set_commit();
drop(trans); drop(trans);
@ -124,7 +124,7 @@ fn test_transaction_commit_finish() {
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", [])); or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
let trans = or_fail!(conn.transaction()); 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(); trans.set_commit();
assert!(trans.finish().is_ok()); 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)", [])); or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
let trans = or_fail!(conn.transaction()); 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()); assert!(trans.commit().is_ok());
let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); 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)); 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("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()); 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); drop(trans);
let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); 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)); 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("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()); 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()); assert!(trans.finish().is_ok());
let stmt = or_fail!(conn.prepare("SELECT * FROM foo")); 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)); 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("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", []));
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1), ($2)", 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 stmt = or_fail!(conn.prepare("SELECT * from foo ORDER BY id"));
let result = or_fail!(stmt.query([])); 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 stmt = or_fail!(trans.prepare("INSERT INTO foo (id) VALUES ($1)"));
let values = vec!(0i32, 1, 2, 3, 4, 5); let values = vec!(0i32, 1, 2, 3, 4, 5);
for value in values.iter() { 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 stmt = or_fail!(trans.prepare("SELECT id FROM foo ORDER BY id"));
let result = or_fail!(trans.lazy_query(&stmt, [], 2)); let result = or_fail!(trans.lazy_query(&stmt, [], 2));
@ -440,7 +440,7 @@ fn test_lazy_query_wrong_conn() {
fn test_param_types() { fn test_param_types() {
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
let stmt = or_fail!(conn.prepare("SELECT $1::INT, $2::VARCHAR")); 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] #[test]
@ -460,7 +460,7 @@ fn test_execute_counts() {
b INT b INT
)", []))); )", [])));
assert_eq!(3, or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($2)", 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!(2, or_fail!(conn.execute("UPDATE foo SET b = 0 WHERE b = 2", [])));
assert_eq!(3, or_fail!(conn.execute("SELECT * FROM foo", []))); assert_eq!(3, or_fail!(conn.execute("SELECT * FROM foo", [])));
} }
@ -468,7 +468,7 @@ fn test_execute_counts() {
#[test] #[test]
fn test_wrong_param_type() { fn test_wrong_param_type() {
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); 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(_)) => {} Err(PgWrongType(_)) => {}
res => fail!("unexpected result {}", res) res => fail!("unexpected result {}", res)
} }
@ -477,7 +477,7 @@ fn test_wrong_param_type() {
#[test] #[test]
fn test_too_few_params() { fn test_too_few_params() {
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); 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 }) => {}, Err(PgWrongParamCount { expected: 2, actual: 1 }) => {},
res => fail!("unexpected result {}", res) res => fail!("unexpected result {}", res)
} }
@ -486,7 +486,7 @@ fn test_too_few_params() {
#[test] #[test]
fn test_too_many_params() { fn test_too_many_params() {
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl)); 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 }) => {}, Err(PgWrongParamCount { expected: 2, actual: 3 }) => {},
res => fail!("unexpected result {}", res) res => fail!("unexpected result {}", res)
} }

View File

@ -6,10 +6,10 @@ use time;
use time::Timespec; use time::Timespec;
use postgres::{PostgresConnection, NoSsl}; use postgres::{PostgresConnection, NoSsl};
use postgres::types::array::ArrayBase; //use postgres::types::array::ArrayBase;
use postgres::types::{ToSql, FromSql}; use postgres::types::{ToSql, FromSql};
mod array; //mod array;
mod range; mod range;
fn test_type<T: PartialEq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S)]) { fn test_type<T: PartialEq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S)]) {
@ -20,7 +20,7 @@ fn test_type<T: PartialEq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S
assert!(val == &result); assert!(val == &result);
let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type).as_slice())); 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); assert!(val == &result);
} }
} }
@ -99,8 +99,8 @@ fn test_bpchar_params() {
b CHAR(5) b CHAR(5)
)", [])); )", []));
or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($3)", or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($3)",
[&Some("12345"), &Some("123"), [&Some("12345") as &ToSql, &Some("123") as &ToSql,
&None::<&'static str>])); &None::<&'static str> as &ToSql]));
let stmt = or_fail!(conn.prepare("SELECT b FROM foo ORDER BY id")); let stmt = or_fail!(conn.prepare("SELECT b FROM foo ORDER BY id"));
let res = or_fail!(stmt.query([])); let res = or_fail!(stmt.query([]));
@ -205,6 +205,7 @@ macro_rules! test_array_params(
}) })
) )
/*
#[test] #[test]
fn test_boolarray_params() { fn test_boolarray_params() {
test_array_params!("BOOL", false, "f", true, "t", true, "t"); test_array_params!("BOOL", false, "f", true, "t", true, "t");
@ -315,6 +316,7 @@ fn test_int8rangearray_params() {
range!('[' 10i64, ')'), "\"[10,)\"", range!('[' 10i64, ')'), "\"[10,)\"",
range!('(', 10i64 ')'), "\"(,10)\""); range!('(', 10i64 ')'), "\"(,10)\"");
} }
*/
#[test] #[test]
fn test_hstore_params() { fn test_hstore_params() {
@ -343,7 +345,7 @@ fn test_nan_param<T: Float+ToSql+FromSql>(sql_type: &str) {
let nan: T = Float::nan(); let nan: T = Float::nan();
let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type).as_slice())); 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); let val: T = result.next().unwrap().get(0u);
assert!(val.is_nan()) assert!(val.is_nan())
} }
@ -358,6 +360,7 @@ fn test_f64_nan_param() {
test_nan_param::<f64>("DOUBLE PRECISION"); test_nan_param::<f64>("DOUBLE PRECISION");
} }
/*
#[test] #[test]
fn test_jsonarray_params() { fn test_jsonarray_params() {
test_array_params!("JSON", test_array_params!("JSON",
@ -368,6 +371,7 @@ fn test_jsonarray_params() {
json::from_str(r#"{"a": [10], "b": true}"#).unwrap(), json::from_str(r#"{"a": [10], "b": true}"#).unwrap(),
r#""{\"a\": [10], \"b\": true}""#); r#""{\"a\": [10], \"b\": true}""#);
} }
*/
#[test] #[test]
fn test_pg_database_datname() { fn test_pg_database_datname() {