@@ -35,7 +35,7 @@ use postgres::error::{PgConnectDbError,
35
35
InvalidCatalogName ,
36
36
PgWrongTransaction ,
37
37
CardinalityViolation } ;
38
- use postgres:: types:: { PgInt4 , PgVarchar } ;
38
+ use postgres:: types:: { PgInt4 , PgVarchar , ToSql } ;
39
39
40
40
macro_rules! or_fail(
41
41
( $e: expr) => (
@@ -108,7 +108,7 @@ fn test_transaction_commit() {
108
108
or_fail ! ( conn. execute( "CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)" , [ ] ) ) ;
109
109
110
110
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 ] ) ) ;
112
112
trans. set_commit ( ) ;
113
113
drop ( trans) ;
114
114
@@ -124,7 +124,7 @@ fn test_transaction_commit_finish() {
124
124
or_fail ! ( conn. execute( "CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)" , [ ] ) ) ;
125
125
126
126
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 ] ) ) ;
128
128
trans. set_commit ( ) ;
129
129
assert ! ( trans. finish( ) . is_ok( ) ) ;
130
130
@@ -140,7 +140,7 @@ fn test_transaction_commit_method() {
140
140
or_fail ! ( conn. execute( "CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)" , [ ] ) ) ;
141
141
142
142
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 ] ) ) ;
144
144
assert ! ( trans. commit( ) . is_ok( ) ) ;
145
145
146
146
let stmt = or_fail ! ( conn. prepare( "SELECT * FROM foo" ) ) ;
@@ -154,10 +154,10 @@ fn test_transaction_rollback() {
154
154
let conn = or_fail ! ( PostgresConnection :: connect( "postgres://postgres@localhost" , & NoSsl ) ) ;
155
155
or_fail ! ( conn. execute( "CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)" , [ ] ) ) ;
156
156
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 ] ) ) ;
158
158
159
159
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 ] ) ) ;
161
161
drop ( trans) ;
162
162
163
163
let stmt = or_fail ! ( conn. prepare( "SELECT * FROM foo" ) ) ;
@@ -171,10 +171,10 @@ fn test_transaction_rollback_finish() {
171
171
let conn = or_fail ! ( PostgresConnection :: connect( "postgres://postgres@localhost" , & NoSsl ) ) ;
172
172
or_fail ! ( conn. execute( "CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)" , [ ] ) ) ;
173
173
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 ] ) ) ;
175
175
176
176
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 ] ) ) ;
178
178
assert ! ( trans. finish( ) . is_ok( ) ) ;
179
179
180
180
let stmt = or_fail ! ( conn. prepare( "SELECT * FROM foo" ) ) ;
@@ -373,7 +373,7 @@ fn test_query() {
373
373
let conn = or_fail ! ( PostgresConnection :: connect( "postgres://postgres@localhost" , & NoSsl ) ) ;
374
374
or_fail ! ( conn. execute( "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)" , [ ] ) ) ;
375
375
or_fail ! ( conn. execute( "INSERT INTO foo (id) VALUES ($1), ($2)" ,
376
- [ & 1i64 , & 2i64 ] ) ) ;
376
+ [ & 1i64 as & ToSql , & 2i64 as & ToSql ] ) ) ;
377
377
let stmt = or_fail ! ( conn. prepare( "SELECT * from foo ORDER BY id" ) ) ;
378
378
let result = or_fail ! ( stmt. query( [ ] ) ) ;
379
379
@@ -415,7 +415,7 @@ fn test_lazy_query() {
415
415
let stmt = or_fail ! ( trans. prepare( "INSERT INTO foo (id) VALUES ($1)" ) ) ;
416
416
let values = vec ! ( 0i32 , 1 , 2 , 3 , 4 , 5 ) ;
417
417
for value in values. iter ( ) {
418
- or_fail ! ( stmt. execute( [ value] ) ) ;
418
+ or_fail ! ( stmt. execute( [ value as & ToSql ] ) ) ;
419
419
}
420
420
let stmt = or_fail ! ( trans. prepare( "SELECT id FROM foo ORDER BY id" ) ) ;
421
421
let result = or_fail ! ( trans. lazy_query( & stmt, [ ] , 2 ) ) ;
@@ -440,7 +440,7 @@ fn test_lazy_query_wrong_conn() {
440
440
fn test_param_types ( ) {
441
441
let conn = or_fail ! ( PostgresConnection :: connect( "postgres://postgres@localhost" , & NoSsl ) ) ;
442
442
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 ( ) ) ;
444
444
}
445
445
446
446
#[ test]
@@ -460,15 +460,15 @@ fn test_execute_counts() {
460
460
b INT
461
461
)" , [ ] ) ) ) ;
462
462
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 ] ) ) ) ;
464
464
assert_eq ! ( 2 , or_fail!( conn. execute( "UPDATE foo SET b = 0 WHERE b = 2" , [ ] ) ) ) ;
465
465
assert_eq ! ( 3 , or_fail!( conn. execute( "SELECT * FROM foo" , [ ] ) ) ) ;
466
466
}
467
467
468
468
#[ test]
469
469
fn test_wrong_param_type ( ) {
470
470
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 ] ) {
472
472
Err ( PgWrongType ( _) ) => { }
473
473
res => fail ! ( "unexpected result {}" , res)
474
474
}
@@ -477,7 +477,7 @@ fn test_wrong_param_type() {
477
477
#[ test]
478
478
fn test_too_few_params ( ) {
479
479
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 ] ) {
481
481
Err ( PgWrongParamCount { expected : 2 , actual : 1 } ) => { } ,
482
482
res => fail ! ( "unexpected result {}" , res)
483
483
}
@@ -486,7 +486,7 @@ fn test_too_few_params() {
486
486
#[ test]
487
487
fn test_too_many_params ( ) {
488
488
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 ] ) {
490
490
Err ( PgWrongParamCount { expected : 2 , actual : 3 } ) => { } ,
491
491
res => fail ! ( "unexpected result {}" , res)
492
492
}
0 commit comments