commit
3a0f189727
63
src/lib.rs
63
src/lib.rs
@ -181,13 +181,8 @@ impl IntoConnectParams for Url {
|
||||
UserInfo { user: user, password: pass }
|
||||
});
|
||||
|
||||
let database = if !path.is_empty() {
|
||||
// path contains the leading /
|
||||
let (_, path) = path[].slice_shift_char();
|
||||
Some(path.into_string())
|
||||
} else {
|
||||
Option::None
|
||||
};
|
||||
// path contains the leading /
|
||||
let database = path.slice_shift_char().map(|(_, path)| path.into_string());
|
||||
|
||||
Ok(ConnectParams {
|
||||
target: target,
|
||||
@ -271,7 +266,7 @@ pub struct CancelData {
|
||||
/// let conn = Connection::connect(url, &SslMode::None).unwrap();
|
||||
/// let cancel_data = conn.cancel_data();
|
||||
/// spawn(proc() {
|
||||
/// conn.execute("SOME EXPENSIVE QUERY", []).unwrap();
|
||||
/// conn.execute("SOME EXPENSIVE QUERY", &[]).unwrap();
|
||||
/// });
|
||||
/// # let _ =
|
||||
/// postgres::cancel_query(url, &SslMode::None, cancel_data);
|
||||
@ -351,7 +346,7 @@ impl InnerConnection {
|
||||
Option::None => {}
|
||||
}
|
||||
|
||||
try!(conn.write_messages([StartupMessage {
|
||||
try!(conn.write_messages(&[StartupMessage {
|
||||
version: message::PROTOCOL_VERSION,
|
||||
parameters: options[]
|
||||
}]));
|
||||
@ -410,7 +405,7 @@ impl InnerConnection {
|
||||
AuthenticationOk => return Ok(()),
|
||||
AuthenticationCleartextPassword => {
|
||||
let pass = try!(user.password.ok_or(ConnectError::MissingPassword));
|
||||
try!(self.write_messages([PasswordMessage {
|
||||
try!(self.write_messages(&[PasswordMessage {
|
||||
password: pass[],
|
||||
}]));
|
||||
}
|
||||
@ -422,9 +417,9 @@ impl InnerConnection {
|
||||
let output = hasher.finalize()[].to_hex();
|
||||
let hasher = Hasher::new(MD5);
|
||||
hasher.update(output.as_bytes());
|
||||
hasher.update(salt);
|
||||
hasher.update(&salt);
|
||||
let output = format!("md5{}", hasher.finalize()[].to_hex());
|
||||
try!(self.write_messages([PasswordMessage {
|
||||
try!(self.write_messages(&[PasswordMessage {
|
||||
password: output[]
|
||||
}]));
|
||||
}
|
||||
@ -458,11 +453,11 @@ impl InnerConnection {
|
||||
let stmt_name = format!("s{}", self.next_stmt_id);
|
||||
self.next_stmt_id += 1;
|
||||
|
||||
try!(self.write_messages([
|
||||
try!(self.write_messages(&[
|
||||
Parse {
|
||||
name: stmt_name[],
|
||||
query: query,
|
||||
param_types: []
|
||||
param_types: &[]
|
||||
},
|
||||
Describe {
|
||||
variant: b'S',
|
||||
@ -548,7 +543,7 @@ impl InnerConnection {
|
||||
}
|
||||
|
||||
fn close_statement(&mut self, stmt_name: &str) -> Result<()> {
|
||||
try!(self.write_messages([
|
||||
try!(self.write_messages(&[
|
||||
Close {
|
||||
variant: b'S',
|
||||
name: stmt_name,
|
||||
@ -605,7 +600,7 @@ impl InnerConnection {
|
||||
|
||||
fn quick_query(&mut self, query: &str) -> Result<Vec<Vec<Option<String>>>> {
|
||||
check_desync!(self);
|
||||
try!(self.write_messages([Query { query: query }]));
|
||||
try!(self.write_messages(&[Query { query: query }]));
|
||||
|
||||
let mut result = vec![];
|
||||
loop {
|
||||
@ -617,7 +612,7 @@ impl InnerConnection {
|
||||
}).collect());
|
||||
}
|
||||
CopyInResponse { .. } => {
|
||||
try!(self.write_messages([
|
||||
try!(self.write_messages(&[
|
||||
CopyFail {
|
||||
message: "COPY queries cannot be directly executed",
|
||||
},
|
||||
@ -636,7 +631,7 @@ impl InnerConnection {
|
||||
fn finish_inner(&mut self) -> Result<()> {
|
||||
check_desync!(self);
|
||||
self.canary = 0;
|
||||
try!(self.write_messages([Terminate]));
|
||||
try!(self.write_messages(&[Terminate]));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@ -762,9 +757,9 @@ impl Connection {
|
||||
/// try!(conn.execute("CREATE TABLE foo (
|
||||
/// bar INT PRIMARY KEY,
|
||||
/// baz VARCHAR
|
||||
/// )", []));
|
||||
/// )", &[]));
|
||||
///
|
||||
/// let stmt = try!(conn.prepare_copy_in("foo", ["bar", "baz"]));
|
||||
/// let stmt = try!(conn.prepare_copy_in("foo", &["bar", "baz"]));
|
||||
/// let data: &[&[&ToSql]] = &[&[&0i32, &"blah".into_string()],
|
||||
/// &[&1i32, &None::<String>]];
|
||||
/// try!(stmt.execute(data.iter().map(|r| r.iter().map(|&e| e))));
|
||||
@ -796,7 +791,7 @@ impl Connection {
|
||||
/// # fn foo() -> Result<(), postgres::Error> {
|
||||
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||
/// let trans = try!(conn.transaction());
|
||||
/// try!(trans.execute("UPDATE foo SET bar = 10", []));
|
||||
/// try!(trans.execute("UPDATE foo SET bar = 10", &[]));
|
||||
/// // ...
|
||||
///
|
||||
/// try!(trans.commit());
|
||||
@ -1095,13 +1090,13 @@ impl<'conn> Statement<'conn> {
|
||||
values.push(try!(param.to_sql(ty)));
|
||||
};
|
||||
|
||||
try!(conn.write_messages([
|
||||
try!(conn.write_messages(&[
|
||||
Bind {
|
||||
portal: portal_name,
|
||||
statement: self.name[],
|
||||
formats: [1],
|
||||
formats: &[1],
|
||||
values: values[],
|
||||
result_formats: [1]
|
||||
result_formats: &[1]
|
||||
},
|
||||
Execute {
|
||||
portal: portal_name,
|
||||
@ -1190,7 +1185,7 @@ impl<'conn> Statement<'conn> {
|
||||
break;
|
||||
}
|
||||
CopyInResponse { .. } => {
|
||||
try!(conn.write_messages([
|
||||
try!(conn.write_messages(&[
|
||||
CopyFail {
|
||||
message: "COPY queries cannot be directly executed",
|
||||
},
|
||||
@ -1273,7 +1268,7 @@ impl<'stmt> Rows<'stmt> {
|
||||
fn finish_inner(&mut self) -> Result<()> {
|
||||
let mut conn = self.stmt.conn.conn.borrow_mut();
|
||||
check_desync!(conn);
|
||||
try!(conn.write_messages([
|
||||
try!(conn.write_messages(&[
|
||||
Close {
|
||||
variant: b'P',
|
||||
name: self.name[]
|
||||
@ -1312,7 +1307,7 @@ impl<'stmt> Rows<'stmt> {
|
||||
return DbError::new(fields);
|
||||
}
|
||||
CopyInResponse { .. } => {
|
||||
try!(conn.write_messages([
|
||||
try!(conn.write_messages(&[
|
||||
CopyFail {
|
||||
message: "COPY queries cannot be directly executed",
|
||||
},
|
||||
@ -1328,7 +1323,7 @@ impl<'stmt> Rows<'stmt> {
|
||||
}
|
||||
|
||||
fn execute(&mut self) -> Result<()> {
|
||||
try!(self.stmt.conn.write_messages([
|
||||
try!(self.stmt.conn.write_messages(&[
|
||||
Execute {
|
||||
portal: self.name[],
|
||||
max_rows: self.row_limit
|
||||
@ -1417,7 +1412,7 @@ impl<'stmt> Row<'stmt> {
|
||||
/// # use postgres::{Connection, SslMode};
|
||||
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||
/// # let stmt = conn.prepare("").unwrap();
|
||||
/// # let mut result = stmt.query([]).unwrap();
|
||||
/// # let mut result = stmt.query(&[]).unwrap();
|
||||
/// # let row = result.next().unwrap();
|
||||
/// let foo: i32 = row.get(0u);
|
||||
/// let bar: String = row.get("bar");
|
||||
@ -1520,13 +1515,13 @@ impl<'a> CopyInStatement<'a> {
|
||||
where I: Iterator<J>, J: Iterator<&'b ToSql + 'b> {
|
||||
let mut conn = self.conn.conn.borrow_mut();
|
||||
|
||||
try!(conn.write_messages([
|
||||
try!(conn.write_messages(&[
|
||||
Bind {
|
||||
portal: "",
|
||||
statement: self.name[],
|
||||
formats: [],
|
||||
values: [],
|
||||
result_formats: []
|
||||
formats: &[],
|
||||
values: &[],
|
||||
result_formats: &[]
|
||||
},
|
||||
Execute {
|
||||
portal: "",
|
||||
@ -1605,7 +1600,7 @@ impl<'a> CopyInStatement<'a> {
|
||||
}
|
||||
|
||||
let _ = buf.write_be_i16(-1);
|
||||
try!(conn.write_messages([
|
||||
try!(conn.write_messages(&[
|
||||
CopyData {
|
||||
data: buf.unwrap()[],
|
||||
},
|
||||
|
@ -373,7 +373,7 @@ fn read_auth_message(buf: &mut MemReader) -> IoResult<BackendMessage> {
|
||||
3 => AuthenticationCleartextPassword,
|
||||
5 => {
|
||||
let mut salt = [0, ..4];
|
||||
try!(buf.read_at_least(salt.len(), salt));
|
||||
try!(buf.read_at_least(salt.len(), &mut salt));
|
||||
AuthenticationMD5Password { salt: salt }
|
||||
},
|
||||
6 => AuthenticationSCMCredential,
|
||||
|
@ -159,7 +159,7 @@ fn decode_inner<T: BytesContainer>(c: T, full_url: bool) -> DecodeResult<String>
|
||||
};
|
||||
|
||||
// Only decode some characters if full_url:
|
||||
match num::from_str_radix::<uint>(str::from_utf8(bytes).unwrap(), 16u).unwrap() as u8 as char {
|
||||
match num::from_str_radix::<uint>(str::from_utf8(&bytes).unwrap(), 16u).unwrap() as u8 as char {
|
||||
// gen-delims:
|
||||
':' | '/' | '?' | '#' | '[' | ']' | '@' |
|
||||
|
||||
@ -463,8 +463,8 @@ fn get_query_fragment(rawurl: &str) -> DecodeResult<(Query, Option<String>)> {
|
||||
};
|
||||
|
||||
match before_fragment.slice_shift_char() {
|
||||
(Some('?'), rest) => Ok((try!(query_from_str(rest)), fragment)),
|
||||
(None, "") => Ok((vec!(), fragment)),
|
||||
Some(('?', rest)) => Ok((try!(query_from_str(rest)), fragment)),
|
||||
None => Ok((vec!(), fragment)),
|
||||
_ => Err(format!("Query didn't start with '?': '{}..'", before_fragment)),
|
||||
}
|
||||
}
|
||||
|
144
tests/test.rs
144
tests/test.rs
@ -86,7 +86,7 @@ fn test_connection_finish() {
|
||||
fn test_unix_connection() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SHOW unix_socket_directories"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
let unix_socket_directories: String = result.map(|row| row.get(0)).next().unwrap();
|
||||
|
||||
if unix_socket_directories.is_empty() {
|
||||
@ -104,7 +104,7 @@ fn test_unix_connection() {
|
||||
#[test]
|
||||
fn test_transaction_commit() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
|
||||
let trans = or_panic!(conn.transaction());
|
||||
or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
|
||||
@ -112,7 +112,7 @@ fn test_transaction_commit() {
|
||||
drop(trans);
|
||||
|
||||
let stmt = or_panic!(conn.prepare("SELECT * FROM foo"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -120,7 +120,7 @@ fn test_transaction_commit() {
|
||||
#[test]
|
||||
fn test_transaction_commit_finish() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
|
||||
let trans = or_panic!(conn.transaction());
|
||||
or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
|
||||
@ -128,7 +128,7 @@ fn test_transaction_commit_finish() {
|
||||
assert!(trans.finish().is_ok());
|
||||
|
||||
let stmt = or_panic!(conn.prepare("SELECT * FROM foo"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -136,14 +136,14 @@ fn test_transaction_commit_finish() {
|
||||
#[test]
|
||||
fn test_transaction_commit_method() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
|
||||
let trans = or_panic!(conn.transaction());
|
||||
or_panic!(trans.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
|
||||
assert!(trans.commit().is_ok());
|
||||
|
||||
let stmt = or_panic!(conn.prepare("SELECT * FROM foo"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -151,7 +151,7 @@ fn test_transaction_commit_method() {
|
||||
#[test]
|
||||
fn test_transaction_rollback() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
|
||||
or_panic!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
|
||||
|
||||
@ -160,7 +160,7 @@ fn test_transaction_rollback() {
|
||||
drop(trans);
|
||||
|
||||
let stmt = or_panic!(conn.prepare("SELECT * FROM foo"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -168,7 +168,7 @@ fn test_transaction_rollback() {
|
||||
#[test]
|
||||
fn test_transaction_rollback_finish() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
|
||||
or_panic!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
|
||||
|
||||
@ -177,7 +177,7 @@ fn test_transaction_rollback_finish() {
|
||||
assert!(trans.finish().is_ok());
|
||||
|
||||
let stmt = or_panic!(conn.prepare("SELECT * FROM foo"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -185,31 +185,31 @@ fn test_transaction_rollback_finish() {
|
||||
#[test]
|
||||
fn test_nested_transactions() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
|
||||
or_panic!(conn.execute("INSERT INTO foo (id) VALUES (1)", []));
|
||||
or_panic!(conn.execute("INSERT INTO foo (id) VALUES (1)", &[]));
|
||||
|
||||
{
|
||||
let trans1 = or_panic!(conn.transaction());
|
||||
or_panic!(trans1.execute("INSERT INTO foo (id) VALUES (2)", []));
|
||||
or_panic!(trans1.execute("INSERT INTO foo (id) VALUES (2)", &[]));
|
||||
|
||||
{
|
||||
let trans2 = or_panic!(trans1.transaction());
|
||||
or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (3)", []));
|
||||
or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (3)", &[]));
|
||||
}
|
||||
|
||||
{
|
||||
let trans2 = or_panic!(trans1.transaction());
|
||||
or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (4)", []));
|
||||
or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (4)", &[]));
|
||||
|
||||
{
|
||||
let trans3 = or_panic!(trans2.transaction());
|
||||
or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (5)", []));
|
||||
or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (5)", &[]));
|
||||
}
|
||||
|
||||
{
|
||||
let trans3 = or_panic!(trans2.transaction());
|
||||
or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (6)", []));
|
||||
or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (6)", &[]));
|
||||
assert!(trans3.commit().is_ok());
|
||||
}
|
||||
|
||||
@ -217,13 +217,13 @@ fn test_nested_transactions() {
|
||||
}
|
||||
|
||||
let stmt = or_panic!(trans1.prepare("SELECT * FROM foo ORDER BY id"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![1i32, 2, 4, 6], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
|
||||
let stmt = or_panic!(conn.prepare("SELECT * FROM foo ORDER BY id"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -231,33 +231,33 @@ fn test_nested_transactions() {
|
||||
#[test]
|
||||
fn test_nested_transactions_finish() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
|
||||
or_panic!(conn.execute("INSERT INTO foo (id) VALUES (1)", []));
|
||||
or_panic!(conn.execute("INSERT INTO foo (id) VALUES (1)", &[]));
|
||||
|
||||
{
|
||||
let trans1 = or_panic!(conn.transaction());
|
||||
or_panic!(trans1.execute("INSERT INTO foo (id) VALUES (2)", []));
|
||||
or_panic!(trans1.execute("INSERT INTO foo (id) VALUES (2)", &[]));
|
||||
|
||||
{
|
||||
let trans2 = or_panic!(trans1.transaction());
|
||||
or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (3)", []));
|
||||
or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (3)", &[]));
|
||||
assert!(trans2.finish().is_ok());
|
||||
}
|
||||
|
||||
{
|
||||
let trans2 = or_panic!(trans1.transaction());
|
||||
or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (4)", []));
|
||||
or_panic!(trans2.execute("INSERT INTO foo (id) VALUES (4)", &[]));
|
||||
|
||||
{
|
||||
let trans3 = or_panic!(trans2.transaction());
|
||||
or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (5)", []));
|
||||
or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (5)", &[]));
|
||||
assert!(trans3.finish().is_ok());
|
||||
}
|
||||
|
||||
{
|
||||
let trans3 = or_panic!(trans2.transaction());
|
||||
or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (6)", []));
|
||||
or_panic!(trans3.execute("INSERT INTO foo (id) VALUES (6)", &[]));
|
||||
trans3.set_commit();
|
||||
assert!(trans3.finish().is_ok());
|
||||
}
|
||||
@ -269,7 +269,7 @@ fn test_nested_transactions_finish() {
|
||||
// in a block to unborrow trans1 for the finish call
|
||||
{
|
||||
let stmt = or_panic!(trans1.prepare("SELECT * FROM foo ORDER BY id"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![1i32, 2, 4, 6], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -278,7 +278,7 @@ fn test_nested_transactions_finish() {
|
||||
}
|
||||
|
||||
let stmt = or_panic!(conn.prepare("SELECT * FROM foo ORDER BY id"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![1i32], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -319,7 +319,7 @@ fn test_trans_prepare_with_nested_trans() {
|
||||
#[test]
|
||||
fn test_stmt_finish() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", &[]));
|
||||
let stmt = or_panic!(conn.prepare("SELECT * FROM foo"));
|
||||
assert!(stmt.finish().is_ok());
|
||||
}
|
||||
@ -332,7 +332,7 @@ fn test_batch_execute() {
|
||||
or_panic!(conn.batch_execute(query));
|
||||
|
||||
let stmt = or_panic!(conn.prepare("SELECT * from foo ORDER BY id"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![10i64], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -362,7 +362,7 @@ fn test_transaction_batch_execute() {
|
||||
or_panic!(trans.batch_execute(query));
|
||||
|
||||
let stmt = or_panic!(trans.prepare("SELECT * from foo ORDER BY id"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![10i64], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -370,11 +370,11 @@ fn test_transaction_batch_execute() {
|
||||
#[test]
|
||||
fn test_query() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", &[]));
|
||||
or_panic!(conn.execute("INSERT INTO foo (id) VALUES ($1), ($2)",
|
||||
&[&1i64, &2i64]));
|
||||
let stmt = or_panic!(conn.prepare("SELECT * from foo ORDER BY id"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![1i64, 2], result.map(|row| row.get(0)).collect());
|
||||
}
|
||||
@ -389,7 +389,7 @@ FROM (SELECT gs.i
|
||||
FROM generate_series(1, 2) gs(i)
|
||||
ORDER BY gs.i
|
||||
LIMIT 2) ss"));
|
||||
match stmt.query([]) {
|
||||
match stmt.query(&[]) {
|
||||
Err(PgDbError(DbError { code: CardinalityViolation, .. })) => {}
|
||||
Err(err) => panic!("Unexpected error {}", err),
|
||||
Ok(_) => panic!("Expected failure"),
|
||||
@ -399,9 +399,9 @@ FROM (SELECT gs.i
|
||||
#[test]
|
||||
fn test_result_finish() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", &[]));
|
||||
let stmt = or_panic!(conn.prepare("SELECT * FROM foo"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
assert!(result.finish().is_ok());
|
||||
}
|
||||
|
||||
@ -410,14 +410,14 @@ fn test_lazy_query() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
|
||||
let trans = or_panic!(conn.transaction());
|
||||
or_panic!(trans.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []));
|
||||
or_panic!(trans.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
let stmt = or_panic!(trans.prepare("INSERT INTO foo (id) VALUES ($1)"));
|
||||
let values = vec!(0i32, 1, 2, 3, 4, 5);
|
||||
for value in values.iter() {
|
||||
or_panic!(stmt.execute(&[value]));
|
||||
}
|
||||
let stmt = or_panic!(trans.prepare("SELECT id FROM foo ORDER BY id"));
|
||||
let result = or_panic!(trans.lazy_query(&stmt, [], 2));
|
||||
let result = or_panic!(trans.lazy_query(&stmt, &[], 2));
|
||||
assert_eq!(values, result.map(|row| row.unwrap().get(0)).collect());
|
||||
}
|
||||
|
||||
@ -428,7 +428,7 @@ fn test_lazy_query_wrong_conn() {
|
||||
|
||||
let trans = or_panic!(conn1.transaction());
|
||||
let stmt = or_panic!(conn2.prepare("SELECT 1::INT"));
|
||||
match trans.lazy_query(&stmt, [], 1) {
|
||||
match trans.lazy_query(&stmt, &[], 1) {
|
||||
Err(PgWrongConnection) => {}
|
||||
Err(err) => panic!("Unexpected error {}", err),
|
||||
Ok(_) => panic!("Expected failure")
|
||||
@ -447,7 +447,7 @@ fn test_result_descriptions() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT 1::INT as a, 'hi'::VARCHAR as b"));
|
||||
assert!(stmt.result_descriptions() ==
|
||||
[ResultDescription { name: "a".to_string(), ty: Type::Int4},
|
||||
&[ResultDescription { name: "a".to_string(), ty: Type::Int4},
|
||||
ResultDescription { name: "b".to_string(), ty: Type::Varchar}]);
|
||||
}
|
||||
|
||||
@ -457,11 +457,11 @@ fn test_execute_counts() {
|
||||
assert_eq!(0, or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (
|
||||
id SERIAL PRIMARY KEY,
|
||||
b INT
|
||||
)", [])));
|
||||
)", &[])));
|
||||
assert_eq!(3, or_panic!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($2)",
|
||||
&[&1i32, &2i32])));
|
||||
assert_eq!(2, or_panic!(conn.execute("UPDATE foo SET b = 0 WHERE b = 2", [])));
|
||||
assert_eq!(3, or_panic!(conn.execute("SELECT * FROM foo", [])));
|
||||
assert_eq!(2, or_panic!(conn.execute("UPDATE foo SET b = 0 WHERE b = 2", &[])));
|
||||
assert_eq!(3, or_panic!(conn.execute("SELECT * FROM foo", &[])));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -495,7 +495,7 @@ fn test_too_many_params() {
|
||||
fn test_index_named() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT 10::INT as val"));
|
||||
let result = or_panic!(stmt.query([]));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec![10i32], result.map(|row| row.get("val")).collect());
|
||||
}
|
||||
@ -505,7 +505,7 @@ fn test_index_named() {
|
||||
fn test_index_named_fail() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT 10::INT as id"));
|
||||
let mut result = or_panic!(stmt.query([]));
|
||||
let mut result = or_panic!(stmt.query(&[]));
|
||||
|
||||
let _: i32 = result.next().unwrap().get("asdf");
|
||||
}
|
||||
@ -514,7 +514,7 @@ fn test_index_named_fail() {
|
||||
fn test_get_named_err() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT 10::INT as id"));
|
||||
let mut result = or_panic!(stmt.query([]));
|
||||
let mut result = or_panic!(stmt.query(&[]));
|
||||
|
||||
match result.next().unwrap().get_opt::<&str, i32>("asdf") {
|
||||
Err(PgInvalidColumn) => {}
|
||||
@ -526,7 +526,7 @@ fn test_get_named_err() {
|
||||
fn test_get_was_null() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT NULL::INT as id"));
|
||||
let mut result = or_panic!(stmt.query([]));
|
||||
let mut result = or_panic!(stmt.query(&[]));
|
||||
|
||||
match result.next().unwrap().get_opt::<uint, i32>(0) {
|
||||
Err(PgWasNull) => {}
|
||||
@ -553,8 +553,8 @@ fn test_custom_notice_handler() {
|
||||
BEGIN
|
||||
RAISE NOTICE 'note';
|
||||
RETURN 1;
|
||||
END; $$ LANGUAGE plpgsql", []));
|
||||
or_panic!(conn.execute("SELECT pg_temp.note()", []));
|
||||
END; $$ LANGUAGE plpgsql", &[]));
|
||||
or_panic!(conn.execute("SELECT pg_temp.note()", &[]));
|
||||
|
||||
assert_eq!(unsafe { count }, 1);
|
||||
}
|
||||
@ -580,10 +580,10 @@ fn test_notification_iterator_some() {
|
||||
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let mut it = conn.notifications();
|
||||
or_panic!(conn.execute("LISTEN test_notification_iterator_one_channel", []));
|
||||
or_panic!(conn.execute("LISTEN test_notification_iterator_one_channel2", []));
|
||||
or_panic!(conn.execute("NOTIFY test_notification_iterator_one_channel, 'hello'", []));
|
||||
or_panic!(conn.execute("NOTIFY test_notification_iterator_one_channel2, 'world'", []));
|
||||
or_panic!(conn.execute("LISTEN test_notification_iterator_one_channel", &[]));
|
||||
or_panic!(conn.execute("LISTEN test_notification_iterator_one_channel2", &[]));
|
||||
or_panic!(conn.execute("NOTIFY test_notification_iterator_one_channel, 'hello'", &[]));
|
||||
or_panic!(conn.execute("NOTIFY test_notification_iterator_one_channel2, 'world'", &[]));
|
||||
|
||||
check_notification(Notification {
|
||||
pid: 0,
|
||||
@ -597,7 +597,7 @@ fn test_notification_iterator_some() {
|
||||
}, it.next());
|
||||
assert!(it.next().is_none());
|
||||
|
||||
or_panic!(conn.execute("NOTIFY test_notification_iterator_one_channel, '!'", []));
|
||||
or_panic!(conn.execute("NOTIFY test_notification_iterator_one_channel, '!'", &[]));
|
||||
check_notification(Notification {
|
||||
pid: 0,
|
||||
channel: "test_notification_iterator_one_channel".to_string(),
|
||||
@ -618,7 +618,7 @@ fn test_cancel_query() {
|
||||
cancel_data).is_ok());
|
||||
});
|
||||
|
||||
match conn.execute("SELECT pg_sleep(10)", []) {
|
||||
match conn.execute("SELECT pg_sleep(10)", &[]) {
|
||||
Err(PgDbError(DbError { code: QueryCanceled, .. })) => {}
|
||||
Err(res) => panic!("Unexpected result {}", res),
|
||||
_ => panic!("Unexpected result"),
|
||||
@ -630,7 +630,7 @@ fn test_require_ssl_conn() {
|
||||
let ctx = SslContext::new(Sslv3).unwrap();
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
|
||||
&SslMode::Require(ctx)));
|
||||
or_panic!(conn.execute("SELECT 1::VARCHAR", []));
|
||||
or_panic!(conn.execute("SELECT 1::VARCHAR", &[]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -638,7 +638,7 @@ fn test_prefer_ssl_conn() {
|
||||
let ctx = SslContext::new(Sslv3).unwrap();
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
|
||||
&SslMode::Prefer(ctx)));
|
||||
or_panic!(conn.execute("SELECT 1::VARCHAR", []));
|
||||
or_panic!(conn.execute("SELECT 1::VARCHAR", &[]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -694,14 +694,14 @@ fn test_md5_pass_wrong_pass() {
|
||||
#[test]
|
||||
fn test_execute_copy_from_err() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[]));
|
||||
let stmt = or_panic!(conn.prepare("COPY foo (id) FROM STDIN"));
|
||||
match stmt.execute([]) {
|
||||
match stmt.execute(&[]) {
|
||||
Err(PgDbError(ref err)) if err.message[].contains("COPY") => {}
|
||||
Err(err) => panic!("Unexptected error {}", err),
|
||||
_ => panic!("Expected error"),
|
||||
}
|
||||
match stmt.query([]) {
|
||||
match stmt.query(&[]) {
|
||||
Err(PgDbError(ref err)) if err.message[].contains("COPY") => {}
|
||||
Err(err) => panic!("Unexptected error {}", err),
|
||||
_ => panic!("Expected error"),
|
||||
@ -711,24 +711,24 @@ fn test_execute_copy_from_err() {
|
||||
#[test]
|
||||
fn test_copy_in() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", &[]));
|
||||
|
||||
let stmt = or_panic!(conn.prepare_copy_in("foo", ["id", "name"]));
|
||||
let stmt = or_panic!(conn.prepare_copy_in("foo", &["id", "name"]));
|
||||
let data: &[&[&ToSql]] = &[&[&0i32, &"Steven".to_string()], &[&1i32, &None::<String>]];
|
||||
|
||||
assert_eq!(Ok(2), stmt.execute(data.iter().map(|r| r.iter().map(|&e| e))));
|
||||
|
||||
let stmt = or_panic!(conn.prepare("SELECT id, name FROM foo ORDER BY id"));
|
||||
assert_eq!(vec![(0i32, Some("Steven".to_string())), (1, None)],
|
||||
or_panic!(stmt.query([])).map(|r| (r.get(0), r.get(1))).collect());
|
||||
or_panic!(stmt.query(&[])).map(|r| (r.get(0), r.get(1))).collect());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_copy_in_bad_column_count() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", &[]));
|
||||
|
||||
let stmt = or_panic!(conn.prepare_copy_in("foo", ["id", "name"]));
|
||||
let stmt = or_panic!(conn.prepare_copy_in("foo", &["id", "name"]));
|
||||
let data: &[&[&ToSql]] = &[&[&0i32, &"Steven".to_string()], &[&1i32]];
|
||||
|
||||
let res = stmt.execute(data.iter().map(|r| r.iter().map(|&e| e)));
|
||||
@ -747,15 +747,15 @@ fn test_copy_in_bad_column_count() {
|
||||
_ => panic!("Expected error"),
|
||||
}
|
||||
|
||||
or_panic!(conn.execute("SELECT 1", []));
|
||||
or_panic!(conn.execute("SELECT 1", &[]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_copy_in_bad_type() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", &[]));
|
||||
|
||||
let stmt = or_panic!(conn.prepare_copy_in("foo", ["id", "name"]));
|
||||
let stmt = or_panic!(conn.prepare_copy_in("foo", &["id", "name"]));
|
||||
let data: &[&[&ToSql]] = &[&[&0i32, &"Steven".to_string()], &[&1i32, &2i32]];
|
||||
|
||||
let res = stmt.execute(data.iter().map(|r| r.iter().map(|&e| e)));
|
||||
@ -765,13 +765,13 @@ fn test_copy_in_bad_type() {
|
||||
_ => panic!("Expected error"),
|
||||
}
|
||||
|
||||
or_panic!(conn.execute("SELECT 1", []));
|
||||
or_panic!(conn.execute("SELECT 1", &[]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_batch_execute_copy_from_err() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", []));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[]));
|
||||
match conn.batch_execute("COPY foo (id) FROM STDIN") {
|
||||
Err(PgDbError(ref err)) if err.message[].contains("COPY") => {}
|
||||
Err(err) => panic!("Unexptected error {}", err),
|
||||
@ -783,7 +783,7 @@ fn test_batch_execute_copy_from_err() {
|
||||
// Just make sure the impls don't infinite loop
|
||||
fn test_generic_connection() {
|
||||
fn f<T>(t: &T) where T: GenericConnection {
|
||||
or_panic!(t.execute("SELECT 1", []));
|
||||
or_panic!(t.execute("SELECT 1", &[]));
|
||||
}
|
||||
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
|
@ -12,14 +12,14 @@ macro_rules! test_array_params(
|
||||
use postgres::types::array::ArrayBase;
|
||||
use types::test_type;
|
||||
|
||||
let tests = [(Some(ArrayBase::from_vec(vec!(Some($v1), Some($v2), None), 1)),
|
||||
let tests = &[(Some(ArrayBase::from_vec(vec!(Some($v1), Some($v2), None), 1)),
|
||||
format!("'{{{},{},NULL}}'", $s1, $s2).into_string()),
|
||||
(None, "NULL".to_string())];
|
||||
test_type(format!("{}[]", $name)[], tests);
|
||||
let mut a = ArrayBase::from_vec(vec!(Some($v1), Some($v2)), 0);
|
||||
a.wrap(-1);
|
||||
a.push_move(ArrayBase::from_vec(vec!(None, Some($v3)), 0));
|
||||
let tests = [(Some(a), format!("'[-1:0][0:1]={{{{{},{}}},{{NULL,{}}}}}'",
|
||||
let tests = &[(Some(a), format!("'[-1:0][0:1]={{{{{},{}}},{{NULL,{}}}}}'",
|
||||
$s1, $s2, $s3).into_string())];
|
||||
test_type(format!("{}[][]", $name)[], tests);
|
||||
})
|
||||
@ -27,7 +27,7 @@ macro_rules! test_array_params(
|
||||
|
||||
macro_rules! test_range(
|
||||
($name:expr, $t:ty, $low:expr, $low_str:expr, $high:expr, $high_str:expr) => ({
|
||||
let tests = [(Some(range!('(', ')')), "'(,)'".to_string()),
|
||||
let tests = &[(Some(range!('(', ')')), "'(,)'".to_string()),
|
||||
(Some(range!('[' $low, ')')), format!("'[{},)'", $low_str)),
|
||||
(Some(range!('(' $low, ')')), format!("'({},)'", $low_str)),
|
||||
(Some(range!('(', $high ']')), format!("'(,{}]'", $high_str)),
|
||||
@ -57,7 +57,7 @@ fn test_type<T: PartialEq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
for &(ref val, ref repr) in checks.iter() {
|
||||
let stmt = or_panic!(conn.prepare(format!("SELECT {:s}::{}", *repr, sql_type)[]));
|
||||
let result = or_panic!(stmt.query([])).next().unwrap().get(0u);
|
||||
let result = or_panic!(stmt.query(&[])).next().unwrap().get(0u);
|
||||
assert!(val == &result);
|
||||
|
||||
let stmt = or_panic!(conn.prepare(format!("SELECT $1::{}", sql_type)[]));
|
||||
@ -68,51 +68,51 @@ fn test_type<T: PartialEq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S
|
||||
|
||||
#[test]
|
||||
fn test_bool_params() {
|
||||
test_type("BOOL", [(Some(true), "'t'"), (Some(false), "'f'"),
|
||||
test_type("BOOL", &[(Some(true), "'t'"), (Some(false), "'f'"),
|
||||
(None, "NULL")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i8_params() {
|
||||
test_type("\"char\"", [(Some('a' as i8), "'a'"), (None, "NULL")]);
|
||||
test_type("\"char\"", &[(Some('a' as i8), "'a'"), (None, "NULL")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_name_params() {
|
||||
test_type("NAME", [(Some("hello world".to_string()), "'hello world'"),
|
||||
test_type("NAME", &[(Some("hello world".to_string()), "'hello world'"),
|
||||
(Some("イロハニホヘト チリヌルヲ".to_string()), "'イロハニホヘト チリヌルヲ'"),
|
||||
(None, "NULL")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i16_params() {
|
||||
test_type("SMALLINT", [(Some(15001i16), "15001"),
|
||||
test_type("SMALLINT", &[(Some(15001i16), "15001"),
|
||||
(Some(-15001i16), "-15001"), (None, "NULL")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i32_params() {
|
||||
test_type("INT", [(Some(2147483548i32), "2147483548"),
|
||||
test_type("INT", &[(Some(2147483548i32), "2147483548"),
|
||||
(Some(-2147483548i32), "-2147483548"), (None, "NULL")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_i64_params() {
|
||||
test_type("BIGINT", [(Some(9223372036854775708i64), "9223372036854775708"),
|
||||
test_type("BIGINT", &[(Some(9223372036854775708i64), "9223372036854775708"),
|
||||
(Some(-9223372036854775708i64), "-9223372036854775708"),
|
||||
(None, "NULL")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_f32_params() {
|
||||
test_type("REAL", [(Some(f32::INFINITY), "'infinity'"),
|
||||
test_type("REAL", &[(Some(f32::INFINITY), "'infinity'"),
|
||||
(Some(f32::NEG_INFINITY), "'-infinity'"),
|
||||
(Some(1000.55), "1000.55"), (None, "NULL")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_f64_params() {
|
||||
test_type("DOUBLE PRECISION", [(Some(f64::INFINITY), "'infinity'"),
|
||||
test_type("DOUBLE PRECISION", &[(Some(f64::INFINITY), "'infinity'"),
|
||||
(Some(f64::NEG_INFINITY), "'-infinity'"),
|
||||
(Some(10000.55), "10000.55"),
|
||||
(None, "NULL")]);
|
||||
@ -120,14 +120,14 @@ fn test_f64_params() {
|
||||
|
||||
#[test]
|
||||
fn test_varchar_params() {
|
||||
test_type("VARCHAR", [(Some("hello world".to_string()), "'hello world'"),
|
||||
test_type("VARCHAR", &[(Some("hello world".to_string()), "'hello world'"),
|
||||
(Some("イロハニホヘト チリヌルヲ".to_string()), "'イロハニホヘト チリヌルヲ'"),
|
||||
(None, "NULL")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_text_params() {
|
||||
test_type("TEXT", [(Some("hello world".to_string()), "'hello world'"),
|
||||
test_type("TEXT", &[(Some("hello world".to_string()), "'hello world'"),
|
||||
(Some("イロハニホヘト チリヌルヲ".to_string()), "'イロハニホヘト チリヌルヲ'"),
|
||||
(None, "NULL")]);
|
||||
}
|
||||
@ -138,11 +138,11 @@ fn test_bpchar_params() {
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (
|
||||
id SERIAL PRIMARY KEY,
|
||||
b CHAR(5)
|
||||
)", []));
|
||||
)", &[]));
|
||||
or_panic!(conn.execute("INSERT INTO foo (b) VALUES ($1), ($2), ($3)",
|
||||
&[&Some("12345"), &Some("123"), &None::<&'static str>]));
|
||||
let stmt = or_panic!(conn.prepare("SELECT b FROM foo ORDER BY id"));
|
||||
let res = or_panic!(stmt.query([]));
|
||||
let res = or_panic!(stmt.query(&[]));
|
||||
|
||||
assert_eq!(vec!(Some("12345".to_string()), Some("123 ".to_string()), None),
|
||||
res.map(|row| row.get(0u)).collect());
|
||||
@ -150,13 +150,13 @@ fn test_bpchar_params() {
|
||||
|
||||
#[test]
|
||||
fn test_bytea_params() {
|
||||
test_type("BYTEA", [(Some(vec!(0u8, 1, 2, 3, 254, 255)), "'\\x00010203feff'"),
|
||||
test_type("BYTEA", &[(Some(vec!(0u8, 1, 2, 3, 254, 255)), "'\\x00010203feff'"),
|
||||
(None, "NULL")]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_json_params() {
|
||||
test_type("JSON", [(Some(json::from_str("[10, 11, 12]").unwrap()),
|
||||
test_type("JSON", &[(Some(json::from_str("[10, 11, 12]").unwrap()),
|
||||
"'[10, 11, 12]'"),
|
||||
(Some(json::from_str("{\"f\": \"asd\"}").unwrap()),
|
||||
"'{\"f\": \"asd\"}'"),
|
||||
@ -265,7 +265,7 @@ fn test_hstore_params() {
|
||||
})
|
||||
)
|
||||
test_type("hstore",
|
||||
[(Some(make_map!("a".to_string() => Some("1".to_string()))), "'a=>1'"),
|
||||
&[(Some(make_map!("a".to_string() => Some("1".to_string()))), "'a=>1'"),
|
||||
(Some(make_map!("hello".to_string() => Some("world!".to_string()),
|
||||
"hola".to_string() => Some("mundo!".to_string()),
|
||||
"what".to_string() => None)),
|
||||
@ -276,7 +276,7 @@ fn test_hstore_params() {
|
||||
fn test_nan_param<T: Float+ToSql+FromSql>(sql_type: &str) {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare(format!("SELECT 'NaN'::{}", sql_type)[]));
|
||||
let mut result = or_panic!(stmt.query([]));
|
||||
let mut result = or_panic!(stmt.query(&[]));
|
||||
let val: T = result.next().unwrap().get(0u);
|
||||
assert!(val.is_nan());
|
||||
|
||||
@ -312,7 +312,7 @@ fn test_jsonarray_params() {
|
||||
fn test_pg_database_datname() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT datname FROM pg_database"));
|
||||
let mut result = or_panic!(stmt.query([]));
|
||||
let mut result = or_panic!(stmt.query(&[]));
|
||||
|
||||
let next = result.next().unwrap();
|
||||
or_panic!(next.get_opt::<uint, String>(0));
|
||||
|
@ -9,12 +9,12 @@ fn test_tm_params() {
|
||||
(Some(time::strptime(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap().to_timespec()), time)
|
||||
}
|
||||
test_type("TIMESTAMP",
|
||||
[make_check("'1970-01-01 00:00:00.01'"),
|
||||
&[make_check("'1970-01-01 00:00:00.01'"),
|
||||
make_check("'1965-09-25 11:19:33.100314'"),
|
||||
make_check("'2010-02-09 23:11:45.1202'"),
|
||||
(None, "NULL")]);
|
||||
test_type("TIMESTAMP WITH TIME ZONE",
|
||||
[make_check("'1970-01-01 00:00:00.01'"),
|
||||
&[make_check("'1970-01-01 00:00:00.01'"),
|
||||
make_check("'1965-09-25 11:19:33.100314'"),
|
||||
make_check("'2010-02-09 23:11:45.1202'"),
|
||||
(None, "NULL")]);
|
||||
|
@ -4,7 +4,7 @@ use types::test_type;
|
||||
|
||||
#[test]
|
||||
fn test_uuid_params() {
|
||||
test_type("UUID", [(Some(uuid::Uuid::parse_str("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11").unwrap()),
|
||||
test_type("UUID", &[(Some(uuid::Uuid::parse_str("a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11").unwrap()),
|
||||
"'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11'"),
|
||||
(None, "NULL")])
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user