Skip to content

Commit 7a84a16

Browse files
committed
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
1 parent bf2497b commit 7a84a16

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

Diff for: src/types/array.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,14 @@ impl<T> InternalMutableArray<T> for ArrayBase<T> {
201201
}
202202
}
203203

204-
enum ArrayParent<'parent, T> {
204+
enum ArrayParent<'parent, T:'parent> {
205205
SliceParent(&'parent ArraySlice<'static, T>),
206206
MutSliceParent(&'parent MutArraySlice<'static, T>),
207207
BaseParent(&'parent ArrayBase<T>),
208208
}
209209

210210
/// An immutable slice of a multi-dimensional array
211-
pub struct ArraySlice<'parent, T> {
211+
pub struct ArraySlice<'parent, T:'parent> {
212212
parent: ArrayParent<'parent, T>,
213213
idx: uint,
214214
}

Diff for: src/types/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use time::Timespec;
1010

1111
use PostgresResult;
1212
use error::{PgWrongType, PgStreamError, PgWasNull, PgBadData};
13-
use types::array::{Array, ArrayBase, DimensionInfo};
13+
//use types::array::{Array, ArrayBase, DimensionInfo};
1414
use types::range::{RangeBound, Inclusive, Exclusive, Range};
1515

16-
pub mod array;
16+
//pub mod array;
1717
pub mod range;
1818

1919
/// A Postgres OID
@@ -423,6 +423,7 @@ macro_rules! from_array_impl(
423423
)
424424
)
425425

426+
/*
426427
from_array_impl!(PgBoolArray, bool)
427428
from_array_impl!(PgByteAArray, Vec<u8>)
428429
from_array_impl!(PgCharArray, i8)
@@ -437,6 +438,7 @@ from_array_impl!(PgFloat8Array, f64)
437438
from_array_impl!(PgInt4RangeArray, Range<i32>)
438439
from_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>)
439440
from_array_impl!(PgInt8RangeArray, Range<i64>)
441+
*/
440442

441443
impl FromSql for Option<HashMap<String, Option<String>>> {
442444
fn from_sql(ty: &PostgresType, raw: &Option<Vec<u8>>)
@@ -726,6 +728,7 @@ macro_rules! to_array_impl(
726728
)
727729
)
728730

731+
/*
729732
to_array_impl!(PgBoolArray, bool)
730733
to_array_impl!(PgByteAArray, Vec<u8>)
731734
to_array_impl!(PgCharArray, i8)
@@ -740,6 +743,7 @@ to_array_impl!(PgInt4RangeArray, Range<i32>)
740743
to_array_impl!(PgTsRangeArray | PgTstzRangeArray, Range<Timespec>)
741744
to_array_impl!(PgInt8RangeArray, Range<i64>)
742745
to_array_impl!(PgJsonArray, Json)
746+
*/
743747

744748
impl ToSql for HashMap<String, Option<String>> {
745749
fn to_sql(&self, ty: &PostgresType) -> PostgresResult<(Format, Option<Vec<u8>>)> {

Diff for: src/types/range.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl<S: BoundSided, T: PartialOrd> RangeBound<S, T> {
267267
}
268268
}
269269

270-
struct OptBound<'a, S, T>(Option<&'a RangeBound<S, T>>);
270+
struct OptBound<'a, S, T:'a>(Option<&'a RangeBound<S, T>>);
271271

272272
impl<'a, S: BoundSided, T: PartialEq> PartialEq for OptBound<'a, S, T> {
273273
fn eq(&self, &OptBound(ref other): &OptBound<'a, S, T>) -> bool {

Diff for: tests/test.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use postgres::error::{PgConnectDbError,
3535
InvalidCatalogName,
3636
PgWrongTransaction,
3737
CardinalityViolation};
38-
use postgres::types::{PgInt4, PgVarchar};
38+
use postgres::types::{PgInt4, PgVarchar, ToSql};
3939

4040
macro_rules! or_fail(
4141
($e:expr) => (
@@ -108,7 +108,7 @@ fn test_transaction_commit() {
108108
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
109109

110110
let trans = or_fail!(conn.transaction());
111-
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32]));
111+
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]));
112112
trans.set_commit();
113113
drop(trans);
114114

@@ -124,7 +124,7 @@ fn test_transaction_commit_finish() {
124124
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
125125

126126
let trans = or_fail!(conn.transaction());
127-
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32]));
127+
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]));
128128
trans.set_commit();
129129
assert!(trans.finish().is_ok());
130130

@@ -140,7 +140,7 @@ fn test_transaction_commit_method() {
140140
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
141141

142142
let trans = or_fail!(conn.transaction());
143-
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32]));
143+
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]));
144144
assert!(trans.commit().is_ok());
145145

146146
let stmt = or_fail!(conn.prepare("SELECT * FROM foo"));
@@ -154,10 +154,10 @@ fn test_transaction_rollback() {
154154
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
155155
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
156156

157-
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32]));
157+
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]));
158158

159159
let trans = or_fail!(conn.transaction());
160-
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32]));
160+
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32 as &ToSql]));
161161
drop(trans);
162162

163163
let stmt = or_fail!(conn.prepare("SELECT * FROM foo"));
@@ -171,10 +171,10 @@ fn test_transaction_rollback_finish() {
171171
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
172172
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
173173

174-
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32]));
174+
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]));
175175

176176
let trans = or_fail!(conn.transaction());
177-
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32]));
177+
or_fail!(trans.execute("INSERT INTO foo (id) VALUES ($1)", [&2i32 as &ToSql]));
178178
assert!(trans.finish().is_ok());
179179

180180
let stmt = or_fail!(conn.prepare("SELECT * FROM foo"));
@@ -373,7 +373,7 @@ fn test_query() {
373373
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
374374
or_fail!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", []));
375375
or_fail!(conn.execute("INSERT INTO foo (id) VALUES ($1), ($2)",
376-
[&1i64, &2i64]));
376+
[&1i64 as &ToSql, &2i64 as &ToSql]));
377377
let stmt = or_fail!(conn.prepare("SELECT * from foo ORDER BY id"));
378378
let result = or_fail!(stmt.query([]));
379379

@@ -415,7 +415,7 @@ fn test_lazy_query() {
415415
let stmt = or_fail!(trans.prepare("INSERT INTO foo (id) VALUES ($1)"));
416416
let values = vec!(0i32, 1, 2, 3, 4, 5);
417417
for value in values.iter() {
418-
or_fail!(stmt.execute([value]));
418+
or_fail!(stmt.execute([value as &ToSql]));
419419
}
420420
let stmt = or_fail!(trans.prepare("SELECT id FROM foo ORDER BY id"));
421421
let result = or_fail!(trans.lazy_query(&stmt, [], 2));
@@ -440,7 +440,7 @@ fn test_lazy_query_wrong_conn() {
440440
fn test_param_types() {
441441
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
442442
let stmt = or_fail!(conn.prepare("SELECT $1::INT, $2::VARCHAR"));
443-
assert_eq!(stmt.param_types(), &[PgInt4, PgVarchar]);
443+
assert_eq!(stmt.param_types(), [PgInt4, PgVarchar].as_slice());
444444
}
445445

446446
#[test]
@@ -460,15 +460,15 @@ fn test_execute_counts() {
460460
b INT
461461
)", [])));
462462
assert_eq!(3, or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($2)",
463-
[&1i32, &2i32])));
463+
[&1i32 as &ToSql, &2i32 as &ToSql])));
464464
assert_eq!(2, or_fail!(conn.execute("UPDATE foo SET b = 0 WHERE b = 2", [])));
465465
assert_eq!(3, or_fail!(conn.execute("SELECT * FROM foo", [])));
466466
}
467467

468468
#[test]
469469
fn test_wrong_param_type() {
470470
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
471-
match conn.execute("SELECT $1::VARCHAR", [&1i32]) {
471+
match conn.execute("SELECT $1::VARCHAR", [&1i32 as &ToSql]) {
472472
Err(PgWrongType(_)) => {}
473473
res => fail!("unexpected result {}", res)
474474
}
@@ -477,7 +477,7 @@ fn test_wrong_param_type() {
477477
#[test]
478478
fn test_too_few_params() {
479479
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
480-
match conn.execute("SELECT $1::INT, $2::INT", [&1i32]) {
480+
match conn.execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql]) {
481481
Err(PgWrongParamCount { expected: 2, actual: 1 }) => {},
482482
res => fail!("unexpected result {}", res)
483483
}
@@ -486,7 +486,7 @@ fn test_too_few_params() {
486486
#[test]
487487
fn test_too_many_params() {
488488
let conn = or_fail!(PostgresConnection::connect("postgres://postgres@localhost", &NoSsl));
489-
match conn.execute("SELECT $1::INT, $2::INT", [&1i32, &2i32, &3i32]) {
489+
match conn.execute("SELECT $1::INT, $2::INT", [&1i32 as &ToSql, &2i32 as &ToSql, &3i32 as &ToSql]) {
490490
Err(PgWrongParamCount { expected: 2, actual: 3 }) => {},
491491
res => fail!("unexpected result {}", res)
492492
}

Diff for: tests/types/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use time;
66
use time::Timespec;
77

88
use postgres::{PostgresConnection, NoSsl};
9-
use postgres::types::array::ArrayBase;
9+
//use postgres::types::array::ArrayBase;
1010
use postgres::types::{ToSql, FromSql};
1111

12-
mod array;
12+
//mod array;
1313
mod range;
1414

1515
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
2020
assert!(val == &result);
2121

2222
let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type).as_slice()));
23-
let result = or_fail!(stmt.query([val])).next().unwrap().get(0u);
23+
let result = or_fail!(stmt.query([val as &ToSql])).next().unwrap().get(0u);
2424
assert!(val == &result);
2525
}
2626
}
@@ -99,8 +99,8 @@ fn test_bpchar_params() {
9999
b CHAR(5)
100100
)", []));
101101
or_fail!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($3)",
102-
[&Some("12345"), &Some("123"),
103-
&None::<&'static str>]));
102+
[&Some("12345") as &ToSql, &Some("123") as &ToSql,
103+
&None::<&'static str> as &ToSql]));
104104
let stmt = or_fail!(conn.prepare("SELECT b FROM foo ORDER BY id"));
105105
let res = or_fail!(stmt.query([]));
106106

@@ -205,6 +205,7 @@ macro_rules! test_array_params(
205205
})
206206
)
207207

208+
/*
208209
#[test]
209210
fn test_boolarray_params() {
210211
test_array_params!("BOOL", false, "f", true, "t", true, "t");
@@ -315,6 +316,7 @@ fn test_int8rangearray_params() {
315316
range!('[' 10i64, ')'), "\"[10,)\"",
316317
range!('(', 10i64 ')'), "\"(,10)\"");
317318
}
319+
*/
318320

319321
#[test]
320322
fn test_hstore_params() {
@@ -343,7 +345,7 @@ fn test_nan_param<T: Float+ToSql+FromSql>(sql_type: &str) {
343345

344346
let nan: T = Float::nan();
345347
let stmt = or_fail!(conn.prepare(format!("SELECT $1::{}", sql_type).as_slice()));
346-
let mut result = or_fail!(stmt.query([&nan]));
348+
let mut result = or_fail!(stmt.query([&nan as &ToSql]));
347349
let val: T = result.next().unwrap().get(0u);
348350
assert!(val.is_nan())
349351
}
@@ -358,6 +360,7 @@ fn test_f64_nan_param() {
358360
test_nan_param::<f64>("DOUBLE PRECISION");
359361
}
360362

363+
/*
361364
#[test]
362365
fn test_jsonarray_params() {
363366
test_array_params!("JSON",
@@ -368,6 +371,7 @@ fn test_jsonarray_params() {
368371
json::from_str(r#"{"a": [10], "b": true}"#).unwrap(),
369372
r#""{\"a\": [10], \"b\": true}""#);
370373
}
374+
*/
371375

372376
#[test]
373377
fn test_pg_database_datname() {

0 commit comments

Comments
 (0)