Change negotiate_ssl back to taking &self
It's not clear that &mut is necessary and it makes connection calls a bit nicer looking.
This commit is contained in:
parent
f957f10b19
commit
26e55ff2bc
@ -23,6 +23,5 @@ pub trait NegotiateSsl {
|
||||
///
|
||||
/// The host portion of the connection parameters is provided for hostname
|
||||
/// verification.
|
||||
fn negotiate_ssl(&mut self, host: &str, stream: Stream)
|
||||
-> Result<Box<StreamWrapper>, Box<Error>>;
|
||||
fn negotiate_ssl(&self, host: &str, stream: Stream) -> Result<Box<StreamWrapper>, Box<Error>>;
|
||||
}
|
||||
|
@ -16,8 +16,7 @@ impl StreamWrapper for SslStream<Stream> {
|
||||
}
|
||||
|
||||
impl NegotiateSsl for SslContext {
|
||||
fn negotiate_ssl(&mut self, _: &str, stream: Stream)
|
||||
-> Result<Box<StreamWrapper>, Box<Error>> {
|
||||
fn negotiate_ssl(&self, _: &str, stream: Stream) -> Result<Box<StreamWrapper>, Box<Error>> {
|
||||
let stream = try!(SslStream::new(self, stream));
|
||||
Ok(Box::new(stream))
|
||||
}
|
||||
|
30
src/lib.rs
30
src/lib.rs
@ -15,7 +15,7 @@
|
||||
//! }
|
||||
//!
|
||||
//! fn main() {
|
||||
//! let conn = Connection::connect("postgresql://postgres@localhost", &mut SslMode::None)
|
||||
//! let conn = Connection::connect("postgresql://postgres@localhost", &SslMode::None)
|
||||
//! .unwrap();
|
||||
//!
|
||||
//! conn.execute("CREATE TABLE person (
|
||||
@ -379,15 +379,15 @@ pub struct CancelData {
|
||||
/// # use postgres::{Connection, SslMode};
|
||||
/// # use std::thread;
|
||||
/// # let url = "";
|
||||
/// let conn = Connection::connect(url, &mut SslMode::None).unwrap();
|
||||
/// let conn = Connection::connect(url, &SslMode::None).unwrap();
|
||||
/// let cancel_data = conn.cancel_data();
|
||||
/// thread::spawn(move || {
|
||||
/// conn.execute("SOME EXPENSIVE QUERY", &[]).unwrap();
|
||||
/// });
|
||||
/// # let _ =
|
||||
/// postgres::cancel_query(url, &mut SslMode::None, cancel_data);
|
||||
/// postgres::cancel_query(url, &SslMode::None, cancel_data);
|
||||
/// ```
|
||||
pub fn cancel_query<T>(params: T, ssl: &mut SslMode, data: CancelData)
|
||||
pub fn cancel_query<T>(params: T, ssl: &SslMode, data: CancelData)
|
||||
-> result::Result<(), ConnectError>
|
||||
where T: IntoConnectParams {
|
||||
let params = try!(params.into_connect_params());
|
||||
@ -497,7 +497,7 @@ impl Drop for InnerConnection {
|
||||
}
|
||||
|
||||
impl InnerConnection {
|
||||
fn connect<T>(params: T, ssl: &mut SslMode) -> result::Result<InnerConnection, ConnectError>
|
||||
fn connect<T>(params: T, ssl: &SslMode) -> result::Result<InnerConnection, ConnectError>
|
||||
where T: IntoConnectParams {
|
||||
let params = try!(params.into_connect_params());
|
||||
let stream = try!(priv_io::initialize_stream(¶ms, ssl));
|
||||
@ -986,7 +986,7 @@ impl Connection {
|
||||
/// # use postgres::{Connection, SslMode, ConnectError};
|
||||
/// # fn f() -> Result<(), ConnectError> {
|
||||
/// let url = "postgresql://postgres:hunter2@localhost:2994/foodb";
|
||||
/// let conn = try!(Connection::connect(url, &mut SslMode::None));
|
||||
/// let conn = try!(Connection::connect(url, &SslMode::None));
|
||||
/// # Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
@ -994,7 +994,7 @@ impl Connection {
|
||||
/// # use postgres::{Connection, SslMode, ConnectError};
|
||||
/// # fn f() -> Result<(), ConnectError> {
|
||||
/// let url = "postgresql://postgres@%2Frun%2Fpostgres";
|
||||
/// let conn = try!(Connection::connect(url, &mut SslMode::None));
|
||||
/// let conn = try!(Connection::connect(url, &SslMode::None));
|
||||
/// # Ok(()) };
|
||||
/// ```
|
||||
///
|
||||
@ -1014,10 +1014,10 @@ impl Connection {
|
||||
/// database: None,
|
||||
/// options: vec![],
|
||||
/// };
|
||||
/// let conn = try!(Connection::connect(params, &mut SslMode::None));
|
||||
/// let conn = try!(Connection::connect(params, &SslMode::None));
|
||||
/// # Ok(()) };
|
||||
/// ```
|
||||
pub fn connect<T>(params: T, ssl: &mut SslMode) -> result::Result<Connection, ConnectError>
|
||||
pub fn connect<T>(params: T, ssl: &SslMode) -> result::Result<Connection, ConnectError>
|
||||
where T: IntoConnectParams {
|
||||
InnerConnection::connect(params, ssl).map(|conn| {
|
||||
Connection { conn: RefCell::new(conn) }
|
||||
@ -1049,7 +1049,7 @@ impl Connection {
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{Connection, SslMode};
|
||||
/// # let conn = Connection::connect("", &mut SslMode::None).unwrap();
|
||||
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||
/// let maybe_stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1");
|
||||
/// let stmt = match maybe_stmt {
|
||||
/// Ok(stmt) => stmt,
|
||||
@ -1072,7 +1072,7 @@ impl Connection {
|
||||
/// # use postgres::{Connection, SslMode};
|
||||
/// # fn f() -> postgres::Result<()> {
|
||||
/// # let x = 10i32;
|
||||
/// # let conn = Connection::connect("", &mut SslMode::None).unwrap();
|
||||
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||
/// let stmt = try!(conn.prepare_cached("SELECT foo FROM bar WHERE baz = $1"));
|
||||
/// for row in try!(stmt.query(&[&x])) {
|
||||
/// println!("foo: {}", row.get::<_, String>(0));
|
||||
@ -1111,7 +1111,7 @@ impl Connection {
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{Connection, SslMode};
|
||||
/// # fn foo() -> Result<(), postgres::Error> {
|
||||
/// # let conn = Connection::connect("", &mut SslMode::None).unwrap();
|
||||
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||
/// let trans = try!(conn.transaction());
|
||||
/// try!(trans.execute("UPDATE foo SET bar = 10", &[]));
|
||||
/// // ...
|
||||
@ -1499,7 +1499,7 @@ impl<'conn> Statement<'conn> {
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{Connection, SslMode};
|
||||
/// # let conn = Connection::connect("", &mut SslMode::None).unwrap();
|
||||
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||
/// # let bar = 1i32;
|
||||
/// # let baz = true;
|
||||
/// let stmt = conn.prepare("UPDATE foo SET bar = $1 WHERE baz = $2").unwrap();
|
||||
@ -1558,7 +1558,7 @@ impl<'conn> Statement<'conn> {
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{Connection, SslMode};
|
||||
/// # let conn = Connection::connect("", &mut SslMode::None).unwrap();
|
||||
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||
/// let stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1").unwrap();
|
||||
/// # let baz = true;
|
||||
/// let rows = match stmt.query(&[&baz]) {
|
||||
@ -1872,7 +1872,7 @@ impl<'a> Row<'a> {
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # use postgres::{Connection, SslMode};
|
||||
/// # let conn = Connection::connect("", &mut SslMode::None).unwrap();
|
||||
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||
/// # let stmt = conn.prepare("").unwrap();
|
||||
/// # let mut result = stmt.query(&[]).unwrap();
|
||||
/// # let row = result.iter().next().unwrap();
|
||||
|
@ -118,14 +118,14 @@ fn open_socket(params: &ConnectParams) -> Result<InternalStream, ConnectError> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initialize_stream(params: &ConnectParams, ssl: &mut SslMode)
|
||||
pub fn initialize_stream(params: &ConnectParams, ssl: &SslMode)
|
||||
-> Result<Box<StreamWrapper>, ConnectError> {
|
||||
let mut socket = Stream(try!(open_socket(params)));
|
||||
|
||||
let (ssl_required, negotiator) = match *ssl {
|
||||
SslMode::None => return Ok(Box::new(socket)),
|
||||
SslMode::Prefer(ref mut negotiator) => (false, negotiator),
|
||||
SslMode::Require(ref mut negotiator) => (true, negotiator),
|
||||
SslMode::Prefer(ref negotiator) => (false, negotiator),
|
||||
SslMode::Require(ref negotiator) => (true, negotiator),
|
||||
};
|
||||
|
||||
try!(socket.write_message(&SslRequest { code: message::SSL_CODE }));
|
||||
|
@ -16,7 +16,7 @@ use types::IsNull;
|
||||
/// ```rust,no_run
|
||||
/// # fn foo() -> postgres::Result<()> {
|
||||
/// # use postgres::{Connection, SslMode, Slice};
|
||||
/// # let conn = Connection::connect("", &mut SslMode::None).unwrap();
|
||||
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||
/// let values = &[1i32, 2, 3, 4, 5, 6];
|
||||
/// let stmt = try!(conn.prepare("SELECT * FROM foo WHERE id = ANY($1)"));
|
||||
/// for row in &try!(stmt.query(&[&Slice(values)])) {
|
||||
|
136
tests/test.rs
136
tests/test.rs
@ -42,17 +42,17 @@ mod types;
|
||||
|
||||
#[test]
|
||||
fn test_non_default_database() {
|
||||
or_panic!(Connection::connect("postgres://postgres@localhost/postgres", &mut SslMode::None));
|
||||
or_panic!(Connection::connect("postgres://postgres@localhost/postgres", &SslMode::None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_url_terminating_slash() {
|
||||
or_panic!(Connection::connect("postgres://postgres@localhost/", &mut SslMode::None));
|
||||
or_panic!(Connection::connect("postgres://postgres@localhost/", &SslMode::None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_prepare_err() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = conn.prepare("invalid sql database");
|
||||
match stmt {
|
||||
Err(Error::DbError(ref e)) if e.code() == &SyntaxError && e.position() == Some(&Normal(1)) => {}
|
||||
@ -63,7 +63,7 @@ fn test_prepare_err() {
|
||||
|
||||
#[test]
|
||||
fn test_unknown_database() {
|
||||
match Connection::connect("postgres://postgres@localhost/asdf", &mut SslMode::None) {
|
||||
match Connection::connect("postgres://postgres@localhost/asdf", &SslMode::None) {
|
||||
Err(ConnectError::DbError(ref e)) if e.code() == &InvalidCatalogName => {}
|
||||
Err(resp) => panic!("Unexpected result {:?}", resp),
|
||||
_ => panic!("Unexpected result"),
|
||||
@ -72,14 +72,14 @@ fn test_unknown_database() {
|
||||
|
||||
#[test]
|
||||
fn test_connection_finish() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
assert!(conn.finish().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg_attr(not(feature = "unix_socket"), ignore)]
|
||||
fn test_unix_connection() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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 unix_socket_directories: String = result.iter().map(|row| row.get(0)).next().unwrap();
|
||||
@ -93,13 +93,13 @@ fn test_unix_connection() {
|
||||
let path = url::percent_encoding::utf8_percent_encode(
|
||||
unix_socket_directory, url::percent_encoding::USERNAME_ENCODE_SET);
|
||||
let url = format!("postgres://postgres@{}", path);
|
||||
let conn = or_panic!(Connection::connect(&url[..], &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect(&url[..], &SslMode::None));
|
||||
assert!(conn.finish().is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transaction_commit() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
|
||||
let trans = or_panic!(conn.transaction());
|
||||
@ -115,7 +115,7 @@ fn test_transaction_commit() {
|
||||
|
||||
#[test]
|
||||
fn test_transaction_commit_finish() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
|
||||
let trans = or_panic!(conn.transaction());
|
||||
@ -131,7 +131,7 @@ fn test_transaction_commit_finish() {
|
||||
|
||||
#[test]
|
||||
fn test_transaction_commit_method() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", &[]));
|
||||
|
||||
let trans = or_panic!(conn.transaction());
|
||||
@ -146,7 +146,7 @@ fn test_transaction_commit_method() {
|
||||
|
||||
#[test]
|
||||
fn test_transaction_rollback() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
|
||||
@ -163,7 +163,7 @@ fn test_transaction_rollback() {
|
||||
|
||||
#[test]
|
||||
fn test_transaction_rollback_finish() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
|
||||
@ -180,7 +180,7 @@ fn test_transaction_rollback_finish() {
|
||||
|
||||
#[test]
|
||||
fn test_nested_transactions() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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("INSERT INTO foo (id) VALUES (1)", &[]));
|
||||
@ -226,7 +226,7 @@ fn test_nested_transactions() {
|
||||
|
||||
#[test]
|
||||
fn test_nested_transactions_finish() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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("INSERT INTO foo (id) VALUES (1)", &[]));
|
||||
@ -282,7 +282,7 @@ fn test_nested_transactions_finish() {
|
||||
#[test]
|
||||
#[should_panic(expected = "active transaction")]
|
||||
fn test_conn_trans_when_nested() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let _trans = or_panic!(conn.transaction());
|
||||
conn.transaction().unwrap();
|
||||
}
|
||||
@ -290,7 +290,7 @@ fn test_conn_trans_when_nested() {
|
||||
#[test]
|
||||
#[should_panic(expected = "active transaction")]
|
||||
fn test_trans_with_nested_trans() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let trans = or_panic!(conn.transaction());
|
||||
let _trans2 = or_panic!(trans.transaction());
|
||||
trans.transaction().unwrap();
|
||||
@ -298,7 +298,7 @@ fn test_trans_with_nested_trans() {
|
||||
|
||||
#[test]
|
||||
fn test_stmt_execute_after_transaction() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let trans = or_panic!(conn.transaction());
|
||||
let stmt = or_panic!(trans.prepare("SELECT 1"));
|
||||
or_panic!(trans.finish());
|
||||
@ -308,7 +308,7 @@ fn test_stmt_execute_after_transaction() {
|
||||
|
||||
#[test]
|
||||
fn test_stmt_finish() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
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());
|
||||
@ -316,7 +316,7 @@ fn test_stmt_finish() {
|
||||
|
||||
#[test]
|
||||
fn test_batch_execute() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
|
||||
INSERT INTO foo (id) VALUES (10);";
|
||||
or_panic!(conn.batch_execute(query));
|
||||
@ -329,7 +329,7 @@ fn test_batch_execute() {
|
||||
|
||||
#[test]
|
||||
fn test_batch_execute_error() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
|
||||
INSERT INTO foo (id) VALUES (10);
|
||||
asdfa;
|
||||
@ -346,7 +346,7 @@ fn test_batch_execute_error() {
|
||||
|
||||
#[test]
|
||||
fn test_transaction_batch_execute() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let trans = or_panic!(conn.transaction());
|
||||
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
|
||||
INSERT INTO foo (id) VALUES (10);";
|
||||
@ -360,7 +360,7 @@ fn test_transaction_batch_execute() {
|
||||
|
||||
#[test]
|
||||
fn test_query() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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("INSERT INTO foo (id) VALUES ($1), ($2)",
|
||||
&[&1i64, &2i64]));
|
||||
@ -372,7 +372,7 @@ fn test_query() {
|
||||
|
||||
#[test]
|
||||
fn test_error_after_datarow() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("
|
||||
SELECT
|
||||
(SELECT generate_series(1, ss.i))
|
||||
@ -389,7 +389,7 @@ FROM (SELECT gs.i
|
||||
|
||||
#[test]
|
||||
fn test_lazy_query() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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)", &[]));
|
||||
@ -406,8 +406,8 @@ fn test_lazy_query() {
|
||||
#[test]
|
||||
#[should_panic(expected = "same `Connection` as")]
|
||||
fn test_lazy_query_wrong_conn() {
|
||||
let conn1 = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn2 = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn1 = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let conn2 = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
|
||||
let trans = or_panic!(conn1.transaction());
|
||||
let stmt = or_panic!(conn2.prepare("SELECT 1::INT"));
|
||||
@ -416,14 +416,14 @@ fn test_lazy_query_wrong_conn() {
|
||||
|
||||
#[test]
|
||||
fn test_param_types() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT $1::INT, $2::VARCHAR"));
|
||||
assert_eq!(stmt.param_types(), &[Type::Int4, Type::Varchar][..]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_columns() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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"));
|
||||
let cols = stmt.columns();
|
||||
assert_eq!(2, cols.len());
|
||||
@ -435,7 +435,7 @@ fn test_columns() {
|
||||
|
||||
#[test]
|
||||
fn test_execute_counts() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
assert_eq!(0, or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (
|
||||
id SERIAL PRIMARY KEY,
|
||||
b INT
|
||||
@ -448,7 +448,7 @@ fn test_execute_counts() {
|
||||
|
||||
#[test]
|
||||
fn test_wrong_param_type() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
match conn.execute("SELECT $1::VARCHAR", &[&1i32]) {
|
||||
Err(Error::WrongType(_)) => {}
|
||||
res => panic!("unexpected result {:?}", res)
|
||||
@ -458,20 +458,20 @@ fn test_wrong_param_type() {
|
||||
#[test]
|
||||
#[should_panic(expected = "expected 2 parameters but got 1")]
|
||||
fn test_too_few_params() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let _ = conn.execute("SELECT $1::INT, $2::INT", &[&1i32]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "expected 2 parameters but got 3")]
|
||||
fn test_too_many_params() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let _ = conn.execute("SELECT $1::INT, $2::INT", &[&1i32, &2i32, &3i32]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_index_named() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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(&[]));
|
||||
|
||||
@ -481,7 +481,7 @@ fn test_index_named() {
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn test_index_named_fail() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT 10::INT as id"));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
@ -490,7 +490,7 @@ fn test_index_named_fail() {
|
||||
|
||||
#[test]
|
||||
fn test_get_named_err() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT 10::INT as id"));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
@ -502,7 +502,7 @@ fn test_get_named_err() {
|
||||
|
||||
#[test]
|
||||
fn test_get_was_null() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT NULL::INT as id"));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
@ -514,7 +514,7 @@ fn test_get_was_null() {
|
||||
|
||||
#[test]
|
||||
fn test_get_off_by_one() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT 10::INT as id"));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
@ -537,7 +537,7 @@ fn test_custom_notice_handler() {
|
||||
}
|
||||
|
||||
let conn = or_panic!(Connection::connect(
|
||||
"postgres://postgres@localhost?client_min_messages=NOTICE", &mut SslMode::None));
|
||||
"postgres://postgres@localhost?client_min_messages=NOTICE", &SslMode::None));
|
||||
conn.set_notice_handler(Box::new(Handler));
|
||||
or_panic!(conn.execute("CREATE FUNCTION pg_temp.note() RETURNS INT AS $$
|
||||
BEGIN
|
||||
@ -551,7 +551,7 @@ fn test_custom_notice_handler() {
|
||||
|
||||
#[test]
|
||||
fn test_notification_iterator_none() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
assert!(conn.notifications().next().is_none());
|
||||
}
|
||||
|
||||
@ -562,7 +562,7 @@ fn check_notification(expected: Notification, actual: Notification) {
|
||||
|
||||
#[test]
|
||||
fn test_notification_iterator_some() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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", &[]));
|
||||
@ -592,11 +592,11 @@ fn test_notification_iterator_some() {
|
||||
|
||||
#[test]
|
||||
fn test_notifications_next_block() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("LISTEN test_notifications_next_block", &[]));
|
||||
|
||||
let _t = thread::spawn(|| {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
thread::sleep_ms(500);
|
||||
or_panic!(conn.execute("NOTIFY test_notifications_next_block, 'foo'", &[]));
|
||||
});
|
||||
@ -612,11 +612,11 @@ fn test_notifications_next_block() {
|
||||
/*
|
||||
#[test]
|
||||
fn test_notifications_next_block_for() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("LISTEN test_notifications_next_block_for", &[]));
|
||||
|
||||
let _t = thread::spawn(|| {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
timer::sleep(Duration::milliseconds(500));
|
||||
or_panic!(conn.execute("NOTIFY test_notifications_next_block_for, 'foo'", &[]));
|
||||
});
|
||||
@ -631,11 +631,11 @@ fn test_notifications_next_block_for() {
|
||||
|
||||
#[test]
|
||||
fn test_notifications_next_block_for_timeout() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("LISTEN test_notifications_next_block_for_timeout", &[]));
|
||||
|
||||
let _t = thread::spawn(|| {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
timer::sleep(Duration::seconds(2));
|
||||
or_panic!(conn.execute("NOTIFY test_notifications_next_block_for_timeout, 'foo'", &[]));
|
||||
});
|
||||
@ -654,12 +654,12 @@ fn test_notifications_next_block_for_timeout() {
|
||||
#[test]
|
||||
// This test is pretty sad, but I don't think there's a better way :(
|
||||
fn test_cancel_query() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let cancel_data = conn.cancel_data();
|
||||
|
||||
let _t = thread::spawn(move || {
|
||||
thread::sleep_ms(500);
|
||||
assert!(postgres::cancel_query("postgres://postgres@localhost", &mut SslMode::None,
|
||||
assert!(postgres::cancel_query("postgres://postgres@localhost", &SslMode::None,
|
||||
cancel_data).is_ok());
|
||||
});
|
||||
|
||||
@ -690,12 +690,12 @@ fn test_prefer_ssl_conn() {
|
||||
|
||||
#[test]
|
||||
fn test_plaintext_pass() {
|
||||
or_panic!(Connection::connect("postgres://pass_user:password@localhost/postgres", &mut SslMode::None));
|
||||
or_panic!(Connection::connect("postgres://pass_user:password@localhost/postgres", &SslMode::None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_plaintext_pass_no_pass() {
|
||||
let ret = Connection::connect("postgres://pass_user@localhost/postgres", &mut SslMode::None);
|
||||
let ret = Connection::connect("postgres://pass_user@localhost/postgres", &SslMode::None);
|
||||
match ret {
|
||||
Err(ConnectError::MissingPassword) => (),
|
||||
Err(err) => panic!("Unexpected error {:?}", err),
|
||||
@ -705,7 +705,7 @@ fn test_plaintext_pass_no_pass() {
|
||||
|
||||
#[test]
|
||||
fn test_plaintext_pass_wrong_pass() {
|
||||
let ret = Connection::connect("postgres://pass_user:asdf@localhost/postgres", &mut SslMode::None);
|
||||
let ret = Connection::connect("postgres://pass_user:asdf@localhost/postgres", &SslMode::None);
|
||||
match ret {
|
||||
Err(ConnectError::DbError(ref e)) if e.code() == &InvalidPassword => {}
|
||||
Err(err) => panic!("Unexpected error {:?}", err),
|
||||
@ -715,12 +715,12 @@ fn test_plaintext_pass_wrong_pass() {
|
||||
|
||||
#[test]
|
||||
fn test_md5_pass() {
|
||||
or_panic!(Connection::connect("postgres://md5_user:password@localhost/postgres", &mut SslMode::None));
|
||||
or_panic!(Connection::connect("postgres://md5_user:password@localhost/postgres", &SslMode::None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_md5_pass_no_pass() {
|
||||
let ret = Connection::connect("postgres://md5_user@localhost/postgres", &mut SslMode::None);
|
||||
let ret = Connection::connect("postgres://md5_user@localhost/postgres", &SslMode::None);
|
||||
match ret {
|
||||
Err(ConnectError::MissingPassword) => (),
|
||||
Err(err) => panic!("Unexpected error {:?}", err),
|
||||
@ -730,7 +730,7 @@ fn test_md5_pass_no_pass() {
|
||||
|
||||
#[test]
|
||||
fn test_md5_pass_wrong_pass() {
|
||||
let ret = Connection::connect("postgres://md5_user:asdf@localhost/postgres", &mut SslMode::None);
|
||||
let ret = Connection::connect("postgres://md5_user:asdf@localhost/postgres", &SslMode::None);
|
||||
match ret {
|
||||
Err(ConnectError::DbError(ref e)) if e.code() == &InvalidPassword => {}
|
||||
Err(err) => panic!("Unexpected error {:?}", err),
|
||||
@ -740,7 +740,7 @@ fn test_md5_pass_wrong_pass() {
|
||||
|
||||
#[test]
|
||||
fn test_execute_copy_from_err() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[]));
|
||||
let stmt = or_panic!(conn.prepare("COPY foo (id) FROM STDIN"));
|
||||
match stmt.execute(&[]) {
|
||||
@ -757,7 +757,7 @@ fn test_execute_copy_from_err() {
|
||||
|
||||
#[test]
|
||||
fn test_copy_in() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", &[]));
|
||||
|
||||
let stmt = or_panic!(conn.prepare_copy_in("foo", &["id", "name"]));
|
||||
@ -776,7 +776,7 @@ fn test_copy_in() {
|
||||
|
||||
#[test]
|
||||
fn test_copy_in_bad_column_count() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", &[]));
|
||||
|
||||
let stmt = or_panic!(conn.prepare_copy_in("foo", &["id", "name"]));
|
||||
@ -813,7 +813,7 @@ fn test_copy_in_bad_column_count() {
|
||||
|
||||
#[test]
|
||||
fn test_copy_in_bad_type() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT, name VARCHAR)", &[]));
|
||||
|
||||
let stmt = or_panic!(conn.prepare_copy_in("foo", &["id", "name"]));
|
||||
@ -837,7 +837,7 @@ fn test_copy_in_bad_type() {
|
||||
|
||||
#[test]
|
||||
fn test_copy_in_weird_names() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute(r#"CREATE TEMPORARY TABLE "na""me" (U&" \\\+01F4A9" VARCHAR)"#, &[]));
|
||||
let stmt = or_panic!(conn.prepare_copy_in("na\"me", &[" \\💩"]));
|
||||
assert_eq!(&Type::Varchar, &stmt.column_types()[0]);
|
||||
@ -845,7 +845,7 @@ fn test_copy_in_weird_names() {
|
||||
|
||||
#[test]
|
||||
fn test_batch_execute_copy_from_err() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (id INT)", &[]));
|
||||
match conn.batch_execute("COPY foo (id) FROM STDIN") {
|
||||
Err(Error::DbError(ref err)) if err.message().contains("COPY") => {}
|
||||
@ -861,7 +861,7 @@ fn test_generic_connection() {
|
||||
or_panic!(t.execute("SELECT 1", &[]));
|
||||
}
|
||||
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
f(&conn);
|
||||
let trans = or_panic!(conn.transaction());
|
||||
f(&trans);
|
||||
@ -869,7 +869,7 @@ fn test_generic_connection() {
|
||||
|
||||
#[test]
|
||||
fn test_custom_range_element_type() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let trans = or_panic!(conn.transaction());
|
||||
or_panic!(trans.execute("CREATE TYPE floatrange AS RANGE (
|
||||
subtype = float8,
|
||||
@ -887,7 +887,7 @@ fn test_custom_range_element_type() {
|
||||
|
||||
#[test]
|
||||
fn test_prepare_cached() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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("INSERT INTO foo (id) VALUES (1), (2)", &[]));
|
||||
|
||||
@ -906,7 +906,7 @@ fn test_prepare_cached() {
|
||||
|
||||
#[test]
|
||||
fn test_is_active() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
assert!(conn.is_active());
|
||||
let trans = or_panic!(conn.transaction());
|
||||
assert!(!conn.is_active());
|
||||
@ -926,14 +926,14 @@ fn test_is_active() {
|
||||
|
||||
#[test]
|
||||
fn test_parameter() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
assert_eq!(Some("UTF8".to_string()), conn.parameter("client_encoding"));
|
||||
assert_eq!(None, conn.parameter("asdf"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_bytes() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT '\\x00010203'::BYTEA"));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
assert_eq!(b"\x00\x01\x02\x03", result.iter().next().unwrap().get_bytes(0).unwrap());
|
||||
@ -941,7 +941,7 @@ fn test_get_bytes() {
|
||||
|
||||
#[test]
|
||||
fn test_get_opt_wrong_type() {
|
||||
let conn = Connection::connect("postgres://postgres@localhost", &mut SslMode::None).unwrap();
|
||||
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
|
||||
let stmt = conn.prepare("SELECT 1::INT").unwrap();
|
||||
let res = stmt.query(&[]).unwrap();
|
||||
match res.iter().next().unwrap().get_opt::<_, String>(0) {
|
||||
@ -960,7 +960,7 @@ fn url_encoded_password() {
|
||||
|
||||
#[test]
|
||||
fn test_transaction_isolation_level() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
assert_eq!(IsolationLevel::ReadCommitted, or_panic!(conn.transaction_isolation()));
|
||||
or_panic!(conn.set_transaction_isolation(IsolationLevel::ReadUncommitted));
|
||||
assert_eq!(IsolationLevel::ReadUncommitted, or_panic!(conn.transaction_isolation()));
|
||||
|
@ -16,7 +16,7 @@ mod rustc_serialize;
|
||||
mod serde;
|
||||
|
||||
fn test_type<T: PartialEq+FromSql+ToSql, S: fmt::Display>(sql_type: &str, checks: &[(T, S)]) {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
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 {}::{}", *repr, sql_type)));
|
||||
let result = or_panic!(stmt.query(&[])).iter().next().unwrap().get(0);
|
||||
@ -102,7 +102,7 @@ fn test_text_params() {
|
||||
|
||||
#[test]
|
||||
fn test_bpchar_params() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (
|
||||
id SERIAL PRIMARY KEY,
|
||||
b CHAR(5)
|
||||
@ -118,7 +118,7 @@ fn test_bpchar_params() {
|
||||
|
||||
#[test]
|
||||
fn test_citext_params() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (
|
||||
id SERIAL PRIMARY KEY,
|
||||
b CITEXT
|
||||
@ -156,7 +156,7 @@ fn test_hstore_params() {
|
||||
}
|
||||
|
||||
fn test_nan_param<T: PartialEq+ToSql+FromSql>(sql_type: &str) {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare(&*format!("SELECT 'NaN'::{}", sql_type)));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
let val: T = result.iter().next().unwrap().get(0);
|
||||
@ -175,7 +175,7 @@ fn test_f64_nan_param() {
|
||||
|
||||
#[test]
|
||||
fn test_pg_database_datname() {
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &mut SslMode::None));
|
||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||
let stmt = or_panic!(conn.prepare("SELECT datname FROM pg_database"));
|
||||
let result = or_panic!(stmt.query(&[]));
|
||||
|
||||
@ -186,7 +186,7 @@ fn test_pg_database_datname() {
|
||||
|
||||
#[test]
|
||||
fn test_slice() {
|
||||
let conn = Connection::connect("postgres://postgres@localhost", &mut SslMode::None).unwrap();
|
||||
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
|
||||
conn.batch_execute("CREATE TEMPORARY TABLE foo (id SERIAL PRIMARY KEY, f VARCHAR);
|
||||
INSERT INTO foo (f) VALUES ('a'), ('b'), ('c'), ('d');").unwrap();
|
||||
|
||||
@ -198,7 +198,7 @@ fn test_slice() {
|
||||
|
||||
#[test]
|
||||
fn test_slice_wrong_type() {
|
||||
let conn = Connection::connect("postgres://postgres@localhost", &mut SslMode::None).unwrap();
|
||||
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
|
||||
conn.batch_execute("CREATE TEMPORARY TABLE foo (id SERIAL PRIMARY KEY)").unwrap();
|
||||
|
||||
let stmt = conn.prepare("SELECT * FROM foo WHERE id = ANY($1)").unwrap();
|
||||
@ -211,7 +211,7 @@ fn test_slice_wrong_type() {
|
||||
|
||||
#[test]
|
||||
fn test_slice_range() {
|
||||
let conn = Connection::connect("postgres://postgres@localhost", &mut SslMode::None).unwrap();
|
||||
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None).unwrap();
|
||||
|
||||
let stmt = conn.prepare("SELECT $1::INT8RANGE").unwrap();
|
||||
match stmt.query(&[&Slice(&[1i64])]) {
|
||||
|
Loading…
Reference in New Issue
Block a user