More enum namespacing preparation
This commit is contained in:
parent
e17d09a479
commit
e5c2edaf97
@ -21,7 +21,7 @@ extern crate time;
|
|||||||
|
|
||||||
use time::Timespec;
|
use time::Timespec;
|
||||||
|
|
||||||
use postgres::{Connection, NoSsl};
|
use postgres::{Connection, SslMode};
|
||||||
|
|
||||||
struct Person {
|
struct Person {
|
||||||
id: i32,
|
id: i32,
|
||||||
@ -31,7 +31,7 @@ struct Person {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let conn = Connection::connect("postgres://postgres@localhost", &NoSsl)
|
let conn = Connection::connect("postgres://postgres@localhost", &SslMode::None)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
conn.execute("CREATE TABLE person (
|
conn.execute("CREATE TABLE person (
|
||||||
@ -297,8 +297,8 @@ traits.
|
|||||||
### UUID type
|
### UUID type
|
||||||
|
|
||||||
[UUID](http://www.postgresql.org/docs/9.4/static/datatype-uuid.html) support is
|
[UUID](http://www.postgresql.org/docs/9.4/static/datatype-uuid.html) support is
|
||||||
provided optionally by the `uuid` feature. It is enabled by default. To
|
provided optionally by the `uuid` feature. It is enabled by default. To disable
|
||||||
disable `UUID` support, add `default-features = false` to your Cargo manifest:
|
`UUID` support, add `default-features = false` to your Cargo manifest:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[dependencies.postgres]
|
[dependencies.postgres]
|
||||||
|
13
src/io.rs
13
src/io.rs
@ -4,8 +4,7 @@ use std::io::net::tcp;
|
|||||||
use std::io::net::pipe;
|
use std::io::net::pipe;
|
||||||
use std::io::{Stream, IoResult};
|
use std::io::{Stream, IoResult};
|
||||||
|
|
||||||
use {ConnectParams, SslMode, NoSsl, PreferSsl, RequireSsl, ConnectTarget};
|
use {ConnectParams, SslMode, ConnectTarget, ConnectError};
|
||||||
use error::{ConnectError, NoSslSupport, SslError};
|
|
||||||
use message;
|
use message;
|
||||||
use message::{SslRequest, WriteMessage};
|
use message::{SslRequest, WriteMessage};
|
||||||
|
|
||||||
@ -90,9 +89,9 @@ pub fn initialize_stream(params: &ConnectParams, ssl: &SslMode)
|
|||||||
let mut socket = try!(open_socket(params));
|
let mut socket = try!(open_socket(params));
|
||||||
|
|
||||||
let (ssl_required, ctx) = match *ssl {
|
let (ssl_required, ctx) = match *ssl {
|
||||||
NoSsl => return Ok(MaybeSslStream::Normal(socket)),
|
SslMode::None => return Ok(MaybeSslStream::Normal(socket)),
|
||||||
PreferSsl(ref ctx) => (false, ctx),
|
SslMode::Prefer(ref ctx) => (false, ctx),
|
||||||
RequireSsl(ref ctx) => (true, ctx)
|
SslMode::Require(ref ctx) => (true, ctx)
|
||||||
};
|
};
|
||||||
|
|
||||||
try!(socket.write_message(&SslRequest { code: message::SSL_CODE }));
|
try!(socket.write_message(&SslRequest { code: message::SSL_CODE }));
|
||||||
@ -100,7 +99,7 @@ pub fn initialize_stream(params: &ConnectParams, ssl: &SslMode)
|
|||||||
|
|
||||||
if try!(socket.read_u8()) == 'N' as u8 {
|
if try!(socket.read_u8()) == 'N' as u8 {
|
||||||
if ssl_required {
|
if ssl_required {
|
||||||
return Err(NoSslSupport);
|
return Err(ConnectError::NoSslSupport);
|
||||||
} else {
|
} else {
|
||||||
return Ok(MaybeSslStream::Normal(socket));
|
return Ok(MaybeSslStream::Normal(socket));
|
||||||
}
|
}
|
||||||
@ -108,6 +107,6 @@ pub fn initialize_stream(params: &ConnectParams, ssl: &SslMode)
|
|||||||
|
|
||||||
match ssl::SslStream::new(ctx, socket) {
|
match ssl::SslStream::new(ctx, socket) {
|
||||||
Ok(stream) => Ok(MaybeSslStream::Ssl(stream)),
|
Ok(stream) => Ok(MaybeSslStream::Ssl(stream)),
|
||||||
Err(err) => Err(SslError(err))
|
Err(err) => Err(ConnectError::SslError(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
129
src/lib.rs
129
src/lib.rs
@ -8,7 +8,7 @@
|
|||||||
//!
|
//!
|
||||||
//! use time::Timespec;
|
//! use time::Timespec;
|
||||||
//!
|
//!
|
||||||
//! use postgres::{Connection, NoSsl};
|
//! use postgres::{Connection, SslMode};
|
||||||
//!
|
//!
|
||||||
//! struct Person {
|
//! struct Person {
|
||||||
//! id: i32,
|
//! id: i32,
|
||||||
@ -18,7 +18,7 @@
|
|||||||
//! }
|
//! }
|
||||||
//!
|
//!
|
||||||
//! fn main() {
|
//! fn main() {
|
||||||
//! let conn = Connection::connect("postgresql://postgres@localhost", &NoSsl)
|
//! let conn = Connection::connect("postgresql://postgres@localhost", &SslMode::None)
|
||||||
//! .unwrap();
|
//! .unwrap();
|
||||||
//!
|
//!
|
||||||
//! conn.execute("CREATE TABLE person (
|
//! conn.execute("CREATE TABLE person (
|
||||||
@ -75,17 +75,6 @@ use std::mem;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::result;
|
use std::result;
|
||||||
|
|
||||||
use error::{InvalidUrl,
|
|
||||||
MissingPassword,
|
|
||||||
MissingUser,
|
|
||||||
PgConnectBadResponse,
|
|
||||||
PgInvalidColumn,
|
|
||||||
PgStreamDesynchronized,
|
|
||||||
PgWrongParamCount,
|
|
||||||
UnsupportedAuthentication,
|
|
||||||
PgWrongConnection,
|
|
||||||
PgWrongTransaction,
|
|
||||||
PgBadResponse};
|
|
||||||
use io::{MaybeSslStream, InternalStream};
|
use io::{MaybeSslStream, InternalStream};
|
||||||
use message::{FrontendMessage, BackendMessage, RowDescriptionEntry};
|
use message::{FrontendMessage, BackendMessage, RowDescriptionEntry};
|
||||||
use message::FrontendMessage::*;
|
use message::FrontendMessage::*;
|
||||||
@ -163,7 +152,7 @@ impl<'a> IntoConnectParams for &'a str {
|
|||||||
fn into_connect_params(self) -> result::Result<ConnectParams, ConnectError> {
|
fn into_connect_params(self) -> result::Result<ConnectParams, ConnectError> {
|
||||||
match Url::parse(self) {
|
match Url::parse(self) {
|
||||||
Ok(url) => url.into_connect_params(),
|
Ok(url) => url.into_connect_params(),
|
||||||
Err(err) => return Err(InvalidUrl(err)),
|
Err(err) => return Err(ConnectError::InvalidUrl(err)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +167,7 @@ impl IntoConnectParams for Url {
|
|||||||
..
|
..
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let maybe_path = try!(url::decode_component(host[]).map_err(InvalidUrl));
|
let maybe_path = try!(url::decode_component(host[]).map_err(ConnectError::InvalidUrl));
|
||||||
let target = if maybe_path[].starts_with("/") {
|
let target = if maybe_path[].starts_with("/") {
|
||||||
ConnectTarget::Unix(Path::new(maybe_path))
|
ConnectTarget::Unix(Path::new(maybe_path))
|
||||||
} else {
|
} else {
|
||||||
@ -194,7 +183,7 @@ impl IntoConnectParams for Url {
|
|||||||
let (_, path) = path[].slice_shift_char();
|
let (_, path) = path[].slice_shift_char();
|
||||||
Some(path.into_string())
|
Some(path.into_string())
|
||||||
} else {
|
} else {
|
||||||
None
|
Option::None
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(ConnectParams {
|
Ok(ConnectParams {
|
||||||
@ -274,15 +263,15 @@ pub struct CancelData {
|
|||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use postgres::{Connection, NoSsl};
|
/// # use postgres::{Connection, SslMode};
|
||||||
/// # let url = "";
|
/// # let url = "";
|
||||||
/// let conn = Connection::connect(url, &NoSsl).unwrap();
|
/// let conn = Connection::connect(url, &SslMode::None).unwrap();
|
||||||
/// let cancel_data = conn.cancel_data();
|
/// let cancel_data = conn.cancel_data();
|
||||||
/// spawn(proc() {
|
/// spawn(proc() {
|
||||||
/// conn.execute("SOME EXPENSIVE QUERY", []).unwrap();
|
/// conn.execute("SOME EXPENSIVE QUERY", []).unwrap();
|
||||||
/// });
|
/// });
|
||||||
/// # let _ =
|
/// # let _ =
|
||||||
/// postgres::cancel_query(url, &NoSsl, cancel_data);
|
/// postgres::cancel_query(url, &SslMode::None, cancel_data);
|
||||||
/// ```
|
/// ```
|
||||||
pub fn cancel_query<T>(params: T, ssl: &SslMode, data: CancelData)
|
pub fn cancel_query<T>(params: T, ssl: &SslMode, data: CancelData)
|
||||||
-> result::Result<(), ConnectError> where T: IntoConnectParams {
|
-> result::Result<(), ConnectError> where T: IntoConnectParams {
|
||||||
@ -334,7 +323,7 @@ impl InnerConnection {
|
|||||||
..
|
..
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
let user = try!(user.ok_or(MissingUser));
|
let user = try!(user.ok_or(ConnectError::MissingUser));
|
||||||
|
|
||||||
let mut conn = InnerConnection {
|
let mut conn = InnerConnection {
|
||||||
stream: BufferedStream::new(stream),
|
stream: BufferedStream::new(stream),
|
||||||
@ -357,7 +346,7 @@ impl InnerConnection {
|
|||||||
options.push(("user".into_string(), user.user.clone()));
|
options.push(("user".into_string(), user.user.clone()));
|
||||||
match database {
|
match database {
|
||||||
Some(database) => options.push(("database".into_string(), database)),
|
Some(database) => options.push(("database".into_string(), database)),
|
||||||
None => {}
|
Option::None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
try!(conn.write_messages([StartupMessage {
|
try!(conn.write_messages([StartupMessage {
|
||||||
@ -375,7 +364,7 @@ impl InnerConnection {
|
|||||||
}
|
}
|
||||||
ReadyForQuery { .. } => break,
|
ReadyForQuery { .. } => break,
|
||||||
ErrorResponse { fields } => return DbError::new_connect(fields),
|
ErrorResponse { fields } => return DbError::new_connect(fields),
|
||||||
_ => return Err(PgConnectBadResponse),
|
_ => return Err(ConnectError::PgConnectBadResponse),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,13 +407,13 @@ impl InnerConnection {
|
|||||||
match try!(self.read_message()) {
|
match try!(self.read_message()) {
|
||||||
AuthenticationOk => return Ok(()),
|
AuthenticationOk => return Ok(()),
|
||||||
AuthenticationCleartextPassword => {
|
AuthenticationCleartextPassword => {
|
||||||
let pass = try!(user.password.ok_or(MissingPassword));
|
let pass = try!(user.password.ok_or(ConnectError::MissingPassword));
|
||||||
try!(self.write_messages([PasswordMessage {
|
try!(self.write_messages([PasswordMessage {
|
||||||
password: pass[],
|
password: pass[],
|
||||||
}]));
|
}]));
|
||||||
}
|
}
|
||||||
AuthenticationMD5Password { salt } => {
|
AuthenticationMD5Password { salt } => {
|
||||||
let pass = try!(user.password.ok_or(MissingPassword));
|
let pass = try!(user.password.ok_or(ConnectError::MissingPassword));
|
||||||
let hasher = Hasher::new(MD5);
|
let hasher = Hasher::new(MD5);
|
||||||
hasher.update(pass.as_bytes());
|
hasher.update(pass.as_bytes());
|
||||||
hasher.update(user.user.as_bytes());
|
hasher.update(user.user.as_bytes());
|
||||||
@ -440,11 +429,11 @@ impl InnerConnection {
|
|||||||
AuthenticationKerberosV5
|
AuthenticationKerberosV5
|
||||||
| AuthenticationSCMCredential
|
| AuthenticationSCMCredential
|
||||||
| AuthenticationGSS
|
| AuthenticationGSS
|
||||||
| AuthenticationSSPI => return Err(UnsupportedAuthentication),
|
| AuthenticationSSPI => return Err(ConnectError::UnsupportedAuthentication),
|
||||||
ErrorResponse { fields } => return DbError::new_connect(fields),
|
ErrorResponse { fields } => return DbError::new_connect(fields),
|
||||||
_ => {
|
_ => {
|
||||||
self.desynchronized = true;
|
self.desynchronized = true;
|
||||||
return Err(PgConnectBadResponse);
|
return Err(ConnectError::PgConnectBadResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -453,7 +442,7 @@ impl InnerConnection {
|
|||||||
ErrorResponse { fields } => return DbError::new_connect(fields),
|
ErrorResponse { fields } => return DbError::new_connect(fields),
|
||||||
_ => {
|
_ => {
|
||||||
self.desynchronized = true;
|
self.desynchronized = true;
|
||||||
return Err(PgConnectBadResponse);
|
return Err(ConnectError::PgConnectBadResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -679,23 +668,23 @@ impl Connection {
|
|||||||
/// ## Examples
|
/// ## Examples
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use postgres::{Connection, NoSsl};
|
/// # use postgres::{Connection, SslMode};
|
||||||
/// # let _ = || {
|
/// # let _ = || {
|
||||||
/// let url = "postgresql://postgres:hunter2@localhost:2994/foodb";
|
/// let url = "postgresql://postgres:hunter2@localhost:2994/foodb";
|
||||||
/// let conn = try!(Connection::connect(url, &NoSsl));
|
/// let conn = try!(Connection::connect(url, &SslMode::None));
|
||||||
/// # Ok(()) };
|
/// # Ok(()) };
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use postgres::{Connection, NoSsl};
|
/// # use postgres::{Connection, SslMode};
|
||||||
/// # let _ = || {
|
/// # let _ = || {
|
||||||
/// let url = "postgresql://postgres@%2Frun%2Fpostgres";
|
/// let url = "postgresql://postgres@%2Frun%2Fpostgres";
|
||||||
/// let conn = try!(Connection::connect(url, &NoSsl));
|
/// let conn = try!(Connection::connect(url, &SslMode::None));
|
||||||
/// # Ok(()) };
|
/// # Ok(()) };
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use postgres::{Connection, UserInfo, ConnectParams, NoSsl, ConnectTarget};
|
/// # use postgres::{Connection, UserInfo, ConnectParams, SslMode, ConnectTarget};
|
||||||
/// # let _ = || {
|
/// # let _ = || {
|
||||||
/// # let some_crazy_path = Path::new("");
|
/// # let some_crazy_path = Path::new("");
|
||||||
/// let params = ConnectParams {
|
/// let params = ConnectParams {
|
||||||
@ -708,7 +697,7 @@ impl Connection {
|
|||||||
/// database: None,
|
/// database: None,
|
||||||
/// options: vec![],
|
/// options: vec![],
|
||||||
/// };
|
/// };
|
||||||
/// let conn = try!(Connection::connect(params, &NoSsl));
|
/// let conn = try!(Connection::connect(params, &SslMode::None));
|
||||||
/// # Ok(()) };
|
/// # Ok(()) };
|
||||||
/// ```
|
/// ```
|
||||||
pub fn connect<T>(params: T, ssl: &SslMode) -> result::Result<Connection, ConnectError>
|
pub fn connect<T>(params: T, ssl: &SslMode) -> result::Result<Connection, ConnectError>
|
||||||
@ -742,8 +731,8 @@ impl Connection {
|
|||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use postgres::{Connection, NoSsl};
|
/// # use postgres::{Connection, SslMode};
|
||||||
/// # let conn = Connection::connect("", &NoSsl).unwrap();
|
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||||
/// let maybe_stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1");
|
/// let maybe_stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1");
|
||||||
/// let stmt = match maybe_stmt {
|
/// let stmt = match maybe_stmt {
|
||||||
/// Ok(stmt) => stmt,
|
/// Ok(stmt) => stmt,
|
||||||
@ -752,7 +741,7 @@ impl Connection {
|
|||||||
pub fn prepare<'a>(&'a self, query: &str) -> Result<Statement<'a>> {
|
pub fn prepare<'a>(&'a self, query: &str) -> Result<Statement<'a>> {
|
||||||
let mut conn = self.conn.borrow_mut();
|
let mut conn = self.conn.borrow_mut();
|
||||||
if conn.trans_depth != 0 {
|
if conn.trans_depth != 0 {
|
||||||
return Err(PgWrongTransaction);
|
return Err(Error::PgWrongTransaction);
|
||||||
}
|
}
|
||||||
conn.prepare(query, self)
|
conn.prepare(query, self)
|
||||||
}
|
}
|
||||||
@ -765,10 +754,10 @@ impl Connection {
|
|||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use postgres::{Connection, NoSsl};
|
/// # use postgres::{Connection, SslMode};
|
||||||
/// # use postgres::types::ToSql;
|
/// # use postgres::types::ToSql;
|
||||||
/// # let _ = || {
|
/// # let _ = || {
|
||||||
/// # let conn = Connection::connect("", &NoSsl).unwrap();
|
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||||
/// try!(conn.execute("CREATE TABLE foo (
|
/// try!(conn.execute("CREATE TABLE foo (
|
||||||
/// bar INT PRIMARY KEY,
|
/// bar INT PRIMARY KEY,
|
||||||
/// baz VARCHAR
|
/// baz VARCHAR
|
||||||
@ -784,7 +773,7 @@ impl Connection {
|
|||||||
-> Result<CopyInStatement<'a>> {
|
-> Result<CopyInStatement<'a>> {
|
||||||
let mut conn = self.conn.borrow_mut();
|
let mut conn = self.conn.borrow_mut();
|
||||||
if conn.trans_depth != 0 {
|
if conn.trans_depth != 0 {
|
||||||
return Err(PgWrongTransaction);
|
return Err(Error::PgWrongTransaction);
|
||||||
}
|
}
|
||||||
conn.prepare_copy_in(table, rows, self)
|
conn.prepare_copy_in(table, rows, self)
|
||||||
}
|
}
|
||||||
@ -802,9 +791,9 @@ impl Connection {
|
|||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use postgres::{Connection, NoSsl};
|
/// # use postgres::{Connection, SslMode};
|
||||||
/// # fn foo() -> Result<(), postgres::Error> {
|
/// # fn foo() -> Result<(), postgres::Error> {
|
||||||
/// # let conn = Connection::connect("", &NoSsl).unwrap();
|
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||||
/// let trans = try!(conn.transaction());
|
/// let trans = try!(conn.transaction());
|
||||||
/// try!(trans.execute("UPDATE foo SET bar = 10", []));
|
/// try!(trans.execute("UPDATE foo SET bar = 10", []));
|
||||||
/// // ...
|
/// // ...
|
||||||
@ -817,7 +806,7 @@ impl Connection {
|
|||||||
let mut conn = self.conn.borrow_mut();
|
let mut conn = self.conn.borrow_mut();
|
||||||
check_desync!(conn);
|
check_desync!(conn);
|
||||||
if conn.trans_depth != 0 {
|
if conn.trans_depth != 0 {
|
||||||
return Err(PgWrongTransaction);
|
return Err(Error::PgWrongTransaction);
|
||||||
}
|
}
|
||||||
try!(conn.quick_query("BEGIN"));
|
try!(conn.quick_query("BEGIN"));
|
||||||
conn.trans_depth += 1;
|
conn.trans_depth += 1;
|
||||||
@ -877,7 +866,7 @@ impl Connection {
|
|||||||
pub fn batch_execute(&self, query: &str) -> Result<()> {
|
pub fn batch_execute(&self, query: &str) -> Result<()> {
|
||||||
let mut conn = self.conn.borrow_mut();
|
let mut conn = self.conn.borrow_mut();
|
||||||
if conn.trans_depth != 0 {
|
if conn.trans_depth != 0 {
|
||||||
return Err(PgWrongTransaction);
|
return Err(Error::PgWrongTransaction);
|
||||||
}
|
}
|
||||||
conn.quick_query(query).map(|_| ())
|
conn.quick_query(query).map(|_| ())
|
||||||
}
|
}
|
||||||
@ -921,11 +910,11 @@ impl Connection {
|
|||||||
/// Specifies the SSL support requested for a new connection
|
/// Specifies the SSL support requested for a new connection
|
||||||
pub enum SslMode {
|
pub enum SslMode {
|
||||||
/// The connection will not use SSL
|
/// The connection will not use SSL
|
||||||
NoSsl,
|
None,
|
||||||
/// The connection will use SSL if the backend supports it
|
/// The connection will use SSL if the backend supports it
|
||||||
PreferSsl(SslContext),
|
Prefer(SslContext),
|
||||||
/// The connection must use SSL
|
/// The connection must use SSL
|
||||||
RequireSsl(SslContext)
|
Require(SslContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents a transaction on a database connection.
|
/// Represents a transaction on a database connection.
|
||||||
@ -965,7 +954,7 @@ impl<'conn> Transaction<'conn> {
|
|||||||
pub fn prepare<'a>(&'a self, query: &str) -> Result<Statement<'a>> {
|
pub fn prepare<'a>(&'a self, query: &str) -> Result<Statement<'a>> {
|
||||||
let mut conn = self.conn.conn.borrow_mut();
|
let mut conn = self.conn.conn.borrow_mut();
|
||||||
if conn.trans_depth != self.depth {
|
if conn.trans_depth != self.depth {
|
||||||
return Err(PgWrongTransaction);
|
return Err(Error::PgWrongTransaction);
|
||||||
}
|
}
|
||||||
conn.prepare(query, self.conn)
|
conn.prepare(query, self.conn)
|
||||||
}
|
}
|
||||||
@ -975,7 +964,7 @@ impl<'conn> Transaction<'conn> {
|
|||||||
-> Result<CopyInStatement<'a>> {
|
-> Result<CopyInStatement<'a>> {
|
||||||
let mut conn = self.conn.conn.borrow_mut();
|
let mut conn = self.conn.conn.borrow_mut();
|
||||||
if conn.trans_depth != self.depth {
|
if conn.trans_depth != self.depth {
|
||||||
return Err(PgWrongTransaction);
|
return Err(Error::PgWrongTransaction);
|
||||||
}
|
}
|
||||||
conn.prepare_copy_in(table, cols, self.conn)
|
conn.prepare_copy_in(table, cols, self.conn)
|
||||||
}
|
}
|
||||||
@ -989,7 +978,7 @@ impl<'conn> Transaction<'conn> {
|
|||||||
pub fn batch_execute(&self, query: &str) -> Result<()> {
|
pub fn batch_execute(&self, query: &str) -> Result<()> {
|
||||||
let mut conn = self.conn.conn.borrow_mut();
|
let mut conn = self.conn.conn.borrow_mut();
|
||||||
if conn.trans_depth != self.depth {
|
if conn.trans_depth != self.depth {
|
||||||
return Err(PgWrongTransaction);
|
return Err(Error::PgWrongTransaction);
|
||||||
}
|
}
|
||||||
conn.quick_query(query).map(|_| ())
|
conn.quick_query(query).map(|_| ())
|
||||||
}
|
}
|
||||||
@ -999,7 +988,7 @@ impl<'conn> Transaction<'conn> {
|
|||||||
let mut conn = self.conn.conn.borrow_mut();
|
let mut conn = self.conn.conn.borrow_mut();
|
||||||
check_desync!(conn);
|
check_desync!(conn);
|
||||||
if conn.trans_depth != self.depth {
|
if conn.trans_depth != self.depth {
|
||||||
return Err(PgWrongTransaction);
|
return Err(Error::PgWrongTransaction);
|
||||||
}
|
}
|
||||||
try!(conn.quick_query("SAVEPOINT sp"));
|
try!(conn.quick_query("SAVEPOINT sp"));
|
||||||
conn.trans_depth += 1;
|
conn.trans_depth += 1;
|
||||||
@ -1024,7 +1013,7 @@ impl<'conn> Transaction<'conn> {
|
|||||||
row_limit: i32)
|
row_limit: i32)
|
||||||
-> Result<LazyRows<'trans, 'stmt>> {
|
-> Result<LazyRows<'trans, 'stmt>> {
|
||||||
if self.conn as *const _ != stmt.conn as *const _ {
|
if self.conn as *const _ != stmt.conn as *const _ {
|
||||||
return Err(PgWrongConnection);
|
return Err(Error::PgWrongConnection);
|
||||||
}
|
}
|
||||||
check_desync!(self.conn);
|
check_desync!(self.conn);
|
||||||
stmt.lazy_query(row_limit, params).map(|result| {
|
stmt.lazy_query(row_limit, params).map(|result| {
|
||||||
@ -1096,7 +1085,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
-> Result<()> {
|
-> Result<()> {
|
||||||
let mut conn = self.conn.conn.borrow_mut();
|
let mut conn = self.conn.conn.borrow_mut();
|
||||||
if self.param_types.len() != params.len() {
|
if self.param_types.len() != params.len() {
|
||||||
return Err(PgWrongParamCount {
|
return Err(Error::PgWrongParamCount {
|
||||||
expected: self.param_types.len(),
|
expected: self.param_types.len(),
|
||||||
actual: params.len(),
|
actual: params.len(),
|
||||||
});
|
});
|
||||||
@ -1128,7 +1117,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
conn.desynchronized = true;
|
conn.desynchronized = true;
|
||||||
Err(PgBadResponse)
|
Err(Error::PgBadResponse)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1171,8 +1160,8 @@ impl<'conn> Statement<'conn> {
|
|||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use postgres::{Connection, NoSsl};
|
/// # use postgres::{Connection, SslMode};
|
||||||
/// # let conn = Connection::connect("", &NoSsl).unwrap();
|
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||||
/// # let bar = 1i32;
|
/// # let bar = 1i32;
|
||||||
/// # let baz = true;
|
/// # let baz = true;
|
||||||
/// let stmt = conn.prepare("UPDATE foo SET bar = $1 WHERE baz = $2").unwrap();
|
/// let stmt = conn.prepare("UPDATE foo SET bar = $1 WHERE baz = $2").unwrap();
|
||||||
@ -1210,7 +1199,7 @@ impl<'conn> Statement<'conn> {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
conn.desynchronized = true;
|
conn.desynchronized = true;
|
||||||
return Err(PgBadResponse);
|
return Err(Error::PgBadResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1225,8 +1214,8 @@ impl<'conn> Statement<'conn> {
|
|||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use postgres::{Connection, NoSsl};
|
/// # use postgres::{Connection, SslMode};
|
||||||
/// # let conn = Connection::connect("", &NoSsl).unwrap();
|
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||||
/// let stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1").unwrap();
|
/// let stmt = conn.prepare("SELECT foo FROM bar WHERE baz = $1").unwrap();
|
||||||
/// # let baz = true;
|
/// # let baz = true;
|
||||||
/// let mut rows = match stmt.query(&[&baz]) {
|
/// let mut rows = match stmt.query(&[&baz]) {
|
||||||
@ -1332,7 +1321,7 @@ impl<'stmt> Rows<'stmt> {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
conn.desynchronized = true;
|
conn.desynchronized = true;
|
||||||
return Err(PgBadResponse);
|
return Err(Error::PgBadResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1380,7 +1369,7 @@ impl<'stmt> Iterator<Row<'stmt>> for Rows<'stmt> {
|
|||||||
fn size_hint(&self) -> (uint, Option<uint>) {
|
fn size_hint(&self) -> (uint, Option<uint>) {
|
||||||
let lower = self.data.len();
|
let lower = self.data.len();
|
||||||
let upper = if self.more_rows {
|
let upper = if self.more_rows {
|
||||||
None
|
Option::None
|
||||||
} else {
|
} else {
|
||||||
Some(lower)
|
Some(lower)
|
||||||
};
|
};
|
||||||
@ -1409,7 +1398,7 @@ impl<'stmt> Row<'stmt> {
|
|||||||
/// Returns an `Error` value if the index does not reference a column or
|
/// Returns an `Error` value if the index does not reference a column or
|
||||||
/// the return type is not compatible with the Postgres type.
|
/// the return type is not compatible with the Postgres type.
|
||||||
pub fn get_opt<I, T>(&self, idx: I) -> Result<T> where I: RowIndex, T: FromSql {
|
pub fn get_opt<I, T>(&self, idx: I) -> Result<T> where I: RowIndex, T: FromSql {
|
||||||
let idx = try!(idx.idx(self.stmt).ok_or(PgInvalidColumn));
|
let idx = try!(idx.idx(self.stmt).ok_or(Error::PgInvalidColumn));
|
||||||
FromSql::from_sql(&self.stmt.result_desc[idx].ty, &self.data[idx])
|
FromSql::from_sql(&self.stmt.result_desc[idx].ty, &self.data[idx])
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1426,8 +1415,8 @@ impl<'stmt> Row<'stmt> {
|
|||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # use postgres::{Connection, NoSsl};
|
/// # use postgres::{Connection, SslMode};
|
||||||
/// # let conn = Connection::connect("", &NoSsl).unwrap();
|
/// # let conn = Connection::connect("", &SslMode::None).unwrap();
|
||||||
/// # let stmt = conn.prepare("").unwrap();
|
/// # let stmt = conn.prepare("").unwrap();
|
||||||
/// # let mut result = stmt.query([]).unwrap();
|
/// # let mut result = stmt.query([]).unwrap();
|
||||||
/// # let row = result.next().unwrap();
|
/// # let row = result.next().unwrap();
|
||||||
@ -1453,7 +1442,7 @@ impl RowIndex for uint {
|
|||||||
#[inline]
|
#[inline]
|
||||||
fn idx(&self, stmt: &Statement) -> Option<uint> {
|
fn idx(&self, stmt: &Statement) -> Option<uint> {
|
||||||
if *self > stmt.result_desc.len() {
|
if *self > stmt.result_desc.len() {
|
||||||
None
|
Option::None
|
||||||
} else {
|
} else {
|
||||||
Some(*self)
|
Some(*self)
|
||||||
}
|
}
|
||||||
@ -1554,7 +1543,7 @@ impl<'a> CopyInStatement<'a> {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
conn.desynchronized = true;
|
conn.desynchronized = true;
|
||||||
return Err(PgBadResponse);
|
return Err(Error::PgBadResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1562,7 +1551,7 @@ impl<'a> CopyInStatement<'a> {
|
|||||||
CopyInResponse { .. } => {}
|
CopyInResponse { .. } => {}
|
||||||
_ => {
|
_ => {
|
||||||
conn.desynchronized = true;
|
conn.desynchronized = true;
|
||||||
return Err(PgBadResponse);
|
return Err(Error::PgBadResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1579,7 +1568,7 @@ impl<'a> CopyInStatement<'a> {
|
|||||||
match (row.next(), types.next()) {
|
match (row.next(), types.next()) {
|
||||||
(Some(val), Some(ty)) => {
|
(Some(val), Some(ty)) => {
|
||||||
match val.to_sql(ty) {
|
match val.to_sql(ty) {
|
||||||
Ok(None) => {
|
Ok(Option::None) => {
|
||||||
let _ = buf.write_be_i32(-1);
|
let _ = buf.write_be_i32(-1);
|
||||||
}
|
}
|
||||||
Ok(Some(val)) => {
|
Ok(Some(val)) => {
|
||||||
@ -1596,14 +1585,14 @@ impl<'a> CopyInStatement<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Some(_), None) | (None, Some(_)) => {
|
(Some(_), Option::None) | (Option::None, Some(_)) => {
|
||||||
try_desync!(conn, conn.stream.write_message(
|
try_desync!(conn, conn.stream.write_message(
|
||||||
&CopyFail {
|
&CopyFail {
|
||||||
message: "Invalid column count",
|
message: "Invalid column count",
|
||||||
}));
|
}));
|
||||||
break 'l;
|
break 'l;
|
||||||
}
|
}
|
||||||
(None, None) => break
|
(Option::None, Option::None) => break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1632,7 +1621,7 @@ impl<'a> CopyInStatement<'a> {
|
|||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
conn.desynchronized = true;
|
conn.desynchronized = true;
|
||||||
return Err(PgBadResponse);
|
return Err(Error::PgBadResponse);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ macro_rules! check_desync(
|
|||||||
panic!("Connection use after free. See mozilla/rust#13246.");
|
panic!("Connection use after free. See mozilla/rust#13246.");
|
||||||
}
|
}
|
||||||
if $e.is_desynchronized() {
|
if $e.is_desynchronized() {
|
||||||
return Err(PgStreamDesynchronized);
|
return Err(::Error::PgStreamDesynchronized);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -25,6 +25,6 @@ macro_rules! bad_response(
|
|||||||
($s:expr) => ({
|
($s:expr) => ({
|
||||||
debug!("Unexpected response");
|
debug!("Unexpected response");
|
||||||
$s.desynchronized = true;
|
$s.desynchronized = true;
|
||||||
return Err(PgBadResponse);
|
return Err(::Error::PgBadResponse);
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
114
tests/test.rs
114
tests/test.rs
@ -16,9 +16,7 @@ use postgres::{NoticeHandler,
|
|||||||
Connection,
|
Connection,
|
||||||
GenericConnection,
|
GenericConnection,
|
||||||
ResultDescription,
|
ResultDescription,
|
||||||
RequireSsl,
|
SslMode,
|
||||||
PreferSsl,
|
|
||||||
NoSsl,
|
|
||||||
Type,
|
Type,
|
||||||
ToSql,
|
ToSql,
|
||||||
DbError};
|
DbError};
|
||||||
@ -52,17 +50,17 @@ mod types;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_non_default_database() {
|
fn test_non_default_database() {
|
||||||
or_panic!(Connection::connect("postgres://postgres@localhost/postgres", &NoSsl));
|
or_panic!(Connection::connect("postgres://postgres@localhost/postgres", &SslMode::None));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_url_terminating_slash() {
|
fn test_url_terminating_slash() {
|
||||||
or_panic!(Connection::connect("postgres://postgres@localhost/", &NoSsl));
|
or_panic!(Connection::connect("postgres://postgres@localhost/", &SslMode::None));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_prepare_err() {
|
fn test_prepare_err() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
match conn.prepare("invalid sql statment") {
|
match conn.prepare("invalid sql statment") {
|
||||||
Err(PgDbError(DbError { code: SyntaxError, position: Some(Normal(1)), .. })) => (),
|
Err(PgDbError(DbError { code: SyntaxError, position: Some(Normal(1)), .. })) => (),
|
||||||
Err(e) => panic!("Unexpected result {}", e),
|
Err(e) => panic!("Unexpected result {}", e),
|
||||||
@ -72,7 +70,7 @@ fn test_prepare_err() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unknown_database() {
|
fn test_unknown_database() {
|
||||||
match Connection::connect("postgres://postgres@localhost/asdf", &NoSsl) {
|
match Connection::connect("postgres://postgres@localhost/asdf", &SslMode::None) {
|
||||||
Err(PgConnectDbError(DbError { code: InvalidCatalogName, .. })) => {}
|
Err(PgConnectDbError(DbError { code: InvalidCatalogName, .. })) => {}
|
||||||
Err(resp) => panic!("Unexpected result {}", resp),
|
Err(resp) => panic!("Unexpected result {}", resp),
|
||||||
_ => panic!("Unexpected result"),
|
_ => panic!("Unexpected result"),
|
||||||
@ -81,13 +79,13 @@ fn test_unknown_database() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_connection_finish() {
|
fn test_connection_finish() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
assert!(conn.finish().is_ok());
|
assert!(conn.finish().is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_unix_connection() {
|
fn test_unix_connection() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let stmt = or_panic!(conn.prepare("SHOW unix_socket_directories"));
|
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();
|
let unix_socket_directories: String = result.map(|row| row.get(0)).next().unwrap();
|
||||||
@ -100,13 +98,13 @@ fn test_unix_connection() {
|
|||||||
|
|
||||||
let path = url::utf8_percent_encode(unix_socket_directory, url::USERNAME_ENCODE_SET);
|
let path = url::utf8_percent_encode(unix_socket_directory, url::USERNAME_ENCODE_SET);
|
||||||
let url = format!("postgres://postgres@{}", path);
|
let url = format!("postgres://postgres@{}", path);
|
||||||
let conn = or_panic!(Connection::connect(url[], &NoSsl));
|
let conn = or_panic!(Connection::connect(url[], &SslMode::None));
|
||||||
assert!(conn.finish().is_ok());
|
assert!(conn.finish().is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transaction_commit() {
|
fn test_transaction_commit() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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());
|
let trans = or_panic!(conn.transaction());
|
||||||
@ -122,7 +120,7 @@ fn test_transaction_commit() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transaction_commit_finish() {
|
fn test_transaction_commit_finish() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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());
|
let trans = or_panic!(conn.transaction());
|
||||||
@ -138,7 +136,7 @@ fn test_transaction_commit_finish() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transaction_commit_method() {
|
fn test_transaction_commit_method() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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());
|
let trans = or_panic!(conn.transaction());
|
||||||
@ -153,7 +151,7 @@ fn test_transaction_commit_method() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transaction_rollback() {
|
fn test_transaction_rollback() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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]));
|
or_panic!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
|
||||||
@ -170,7 +168,7 @@ fn test_transaction_rollback() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transaction_rollback_finish() {
|
fn test_transaction_rollback_finish() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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]));
|
or_panic!(conn.execute("INSERT INTO foo (id) VALUES ($1)", &[&1i32]));
|
||||||
@ -187,7 +185,7 @@ fn test_transaction_rollback_finish() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_nested_transactions() {
|
fn test_nested_transactions() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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)", []));
|
||||||
@ -233,7 +231,7 @@ fn test_nested_transactions() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_nested_transactions_finish() {
|
fn test_nested_transactions_finish() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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)", []));
|
||||||
@ -288,7 +286,7 @@ fn test_nested_transactions_finish() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_conn_prepare_with_trans() {
|
fn test_conn_prepare_with_trans() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let _trans = or_panic!(conn.transaction());
|
let _trans = or_panic!(conn.transaction());
|
||||||
match conn.prepare("") {
|
match conn.prepare("") {
|
||||||
Err(PgWrongTransaction) => {}
|
Err(PgWrongTransaction) => {}
|
||||||
@ -304,7 +302,7 @@ fn test_conn_prepare_with_trans() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_trans_prepare_with_nested_trans() {
|
fn test_trans_prepare_with_nested_trans() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let trans = or_panic!(conn.transaction());
|
let trans = or_panic!(conn.transaction());
|
||||||
let _trans2 = or_panic!(trans.transaction());
|
let _trans2 = or_panic!(trans.transaction());
|
||||||
match trans.prepare("") {
|
match trans.prepare("") {
|
||||||
@ -321,7 +319,7 @@ fn test_trans_prepare_with_nested_trans() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_stmt_finish() {
|
fn test_stmt_finish() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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 stmt = or_panic!(conn.prepare("SELECT * FROM foo"));
|
||||||
assert!(stmt.finish().is_ok());
|
assert!(stmt.finish().is_ok());
|
||||||
@ -329,7 +327,7 @@ fn test_stmt_finish() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_batch_execute() {
|
fn test_batch_execute() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
|
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
|
||||||
INSERT INTO foo (id) VALUES (10);";
|
INSERT INTO foo (id) VALUES (10);";
|
||||||
or_panic!(conn.batch_execute(query));
|
or_panic!(conn.batch_execute(query));
|
||||||
@ -342,7 +340,7 @@ fn test_batch_execute() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_batch_execute_error() {
|
fn test_batch_execute_error() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
|
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
|
||||||
INSERT INTO foo (id) VALUES (10);
|
INSERT INTO foo (id) VALUES (10);
|
||||||
asdfa;
|
asdfa;
|
||||||
@ -358,7 +356,7 @@ fn test_batch_execute_error() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transaction_batch_execute() {
|
fn test_transaction_batch_execute() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let trans = or_panic!(conn.transaction());
|
let trans = or_panic!(conn.transaction());
|
||||||
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
|
let query = "CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY);
|
||||||
INSERT INTO foo (id) VALUES (10);";
|
INSERT INTO foo (id) VALUES (10);";
|
||||||
@ -372,7 +370,7 @@ fn test_transaction_batch_execute() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_query() {
|
fn test_query() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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)",
|
or_panic!(conn.execute("INSERT INTO foo (id) VALUES ($1), ($2)",
|
||||||
&[&1i64, &2i64]));
|
&[&1i64, &2i64]));
|
||||||
@ -384,7 +382,7 @@ fn test_query() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_error_after_datarow() {
|
fn test_error_after_datarow() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let stmt = or_panic!(conn.prepare("
|
let stmt = or_panic!(conn.prepare("
|
||||||
SELECT
|
SELECT
|
||||||
(SELECT generate_series(1, ss.i))
|
(SELECT generate_series(1, ss.i))
|
||||||
@ -401,7 +399,7 @@ FROM (SELECT gs.i
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_result_finish() {
|
fn test_result_finish() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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 stmt = or_panic!(conn.prepare("SELECT * FROM foo"));
|
||||||
let result = or_panic!(stmt.query([]));
|
let result = or_panic!(stmt.query([]));
|
||||||
@ -410,7 +408,7 @@ fn test_result_finish() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lazy_query() {
|
fn test_lazy_query() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
|
|
||||||
let trans = or_panic!(conn.transaction());
|
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)", []));
|
||||||
@ -426,8 +424,8 @@ fn test_lazy_query() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lazy_query_wrong_conn() {
|
fn test_lazy_query_wrong_conn() {
|
||||||
let conn1 = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn1 = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let conn2 = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn2 = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
|
|
||||||
let trans = or_panic!(conn1.transaction());
|
let trans = or_panic!(conn1.transaction());
|
||||||
let stmt = or_panic!(conn2.prepare("SELECT 1::INT"));
|
let stmt = or_panic!(conn2.prepare("SELECT 1::INT"));
|
||||||
@ -440,14 +438,14 @@ fn test_lazy_query_wrong_conn() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_param_types() {
|
fn test_param_types() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let stmt = or_panic!(conn.prepare("SELECT $1::INT, $2::VARCHAR"));
|
let stmt = or_panic!(conn.prepare("SELECT $1::INT, $2::VARCHAR"));
|
||||||
assert_eq!(stmt.param_types(), [Type::Int4, Type::Varchar][]);
|
assert_eq!(stmt.param_types(), [Type::Int4, Type::Varchar][]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_result_descriptions() {
|
fn test_result_descriptions() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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 stmt = or_panic!(conn.prepare("SELECT 1::INT as a, 'hi'::VARCHAR as b"));
|
||||||
assert!(stmt.result_descriptions() ==
|
assert!(stmt.result_descriptions() ==
|
||||||
[ResultDescription { name: "a".to_string(), ty: Type::Int4},
|
[ResultDescription { name: "a".to_string(), ty: Type::Int4},
|
||||||
@ -456,7 +454,7 @@ fn test_result_descriptions() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_execute_counts() {
|
fn test_execute_counts() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
assert_eq!(0, or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (
|
assert_eq!(0, or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
b INT
|
b INT
|
||||||
@ -469,7 +467,7 @@ fn test_execute_counts() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_wrong_param_type() {
|
fn test_wrong_param_type() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
match conn.execute("SELECT $1::VARCHAR", &[&1i32]) {
|
match conn.execute("SELECT $1::VARCHAR", &[&1i32]) {
|
||||||
Err(PgWrongType(_)) => {}
|
Err(PgWrongType(_)) => {}
|
||||||
res => panic!("unexpected result {}", res)
|
res => panic!("unexpected result {}", res)
|
||||||
@ -478,7 +476,7 @@ fn test_wrong_param_type() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_too_few_params() {
|
fn test_too_few_params() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
match conn.execute("SELECT $1::INT, $2::INT", &[&1i32]) {
|
match conn.execute("SELECT $1::INT, $2::INT", &[&1i32]) {
|
||||||
Err(PgWrongParamCount { expected: 2, actual: 1 }) => {},
|
Err(PgWrongParamCount { expected: 2, actual: 1 }) => {},
|
||||||
res => panic!("unexpected result {}", res)
|
res => panic!("unexpected result {}", res)
|
||||||
@ -487,7 +485,7 @@ fn test_too_few_params() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_too_many_params() {
|
fn test_too_many_params() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
match conn.execute("SELECT $1::INT, $2::INT", &[&1i32, &2i32, &3i32]) {
|
match conn.execute("SELECT $1::INT, $2::INT", &[&1i32, &2i32, &3i32]) {
|
||||||
Err(PgWrongParamCount { expected: 2, actual: 3 }) => {},
|
Err(PgWrongParamCount { expected: 2, actual: 3 }) => {},
|
||||||
res => panic!("unexpected result {}", res)
|
res => panic!("unexpected result {}", res)
|
||||||
@ -496,7 +494,7 @@ fn test_too_many_params() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_index_named() {
|
fn test_index_named() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let stmt = or_panic!(conn.prepare("SELECT 10::INT as val"));
|
let stmt = or_panic!(conn.prepare("SELECT 10::INT as val"));
|
||||||
let result = or_panic!(stmt.query([]));
|
let result = or_panic!(stmt.query([]));
|
||||||
|
|
||||||
@ -506,7 +504,7 @@ fn test_index_named() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_index_named_fail() {
|
fn test_index_named_fail() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let stmt = or_panic!(conn.prepare("SELECT 10::INT as id"));
|
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([]));
|
||||||
|
|
||||||
@ -515,7 +513,7 @@ fn test_index_named_fail() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_named_err() {
|
fn test_get_named_err() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let stmt = or_panic!(conn.prepare("SELECT 10::INT as id"));
|
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([]));
|
||||||
|
|
||||||
@ -527,7 +525,7 @@ fn test_get_named_err() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_was_null() {
|
fn test_get_was_null() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let stmt = or_panic!(conn.prepare("SELECT NULL::INT as id"));
|
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([]));
|
||||||
|
|
||||||
@ -550,7 +548,7 @@ fn test_custom_notice_handler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let conn = or_panic!(Connection::connect(
|
let conn = or_panic!(Connection::connect(
|
||||||
"postgres://postgres@localhost?client_min_messages=NOTICE", &NoSsl));
|
"postgres://postgres@localhost?client_min_messages=NOTICE", &SslMode::None));
|
||||||
conn.set_notice_handler(box Handler);
|
conn.set_notice_handler(box Handler);
|
||||||
or_panic!(conn.execute("CREATE FUNCTION pg_temp.note() RETURNS INT AS $$
|
or_panic!(conn.execute("CREATE FUNCTION pg_temp.note() RETURNS INT AS $$
|
||||||
BEGIN
|
BEGIN
|
||||||
@ -564,7 +562,7 @@ fn test_custom_notice_handler() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_notification_iterator_none() {
|
fn test_notification_iterator_none() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
assert!(conn.notifications().next().is_none());
|
assert!(conn.notifications().next().is_none());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -581,7 +579,7 @@ fn test_notification_iterator_some() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let mut it = conn.notifications();
|
let mut it = conn.notifications();
|
||||||
or_panic!(conn.execute("LISTEN test_notification_iterator_one_channel", []));
|
or_panic!(conn.execute("LISTEN test_notification_iterator_one_channel", []));
|
||||||
or_panic!(conn.execute("LISTEN test_notification_iterator_one_channel2", []));
|
or_panic!(conn.execute("LISTEN test_notification_iterator_one_channel2", []));
|
||||||
@ -612,12 +610,12 @@ fn test_notification_iterator_some() {
|
|||||||
#[test]
|
#[test]
|
||||||
// This test is pretty sad, but I don't think there's a better way :(
|
// This test is pretty sad, but I don't think there's a better way :(
|
||||||
fn test_cancel_query() {
|
fn test_cancel_query() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let cancel_data = conn.cancel_data();
|
let cancel_data = conn.cancel_data();
|
||||||
|
|
||||||
spawn(proc() {
|
spawn(proc() {
|
||||||
timer::sleep(Duration::milliseconds(500));
|
timer::sleep(Duration::milliseconds(500));
|
||||||
assert!(postgres::cancel_query("postgres://postgres@localhost", &NoSsl,
|
assert!(postgres::cancel_query("postgres://postgres@localhost", &SslMode::None,
|
||||||
cancel_data).is_ok());
|
cancel_data).is_ok());
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -632,7 +630,7 @@ fn test_cancel_query() {
|
|||||||
fn test_require_ssl_conn() {
|
fn test_require_ssl_conn() {
|
||||||
let ctx = SslContext::new(Sslv3).unwrap();
|
let ctx = SslContext::new(Sslv3).unwrap();
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
|
||||||
&RequireSsl(ctx)));
|
&SslMode::Require(ctx)));
|
||||||
or_panic!(conn.execute("SELECT 1::VARCHAR", []));
|
or_panic!(conn.execute("SELECT 1::VARCHAR", []));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -640,18 +638,18 @@ fn test_require_ssl_conn() {
|
|||||||
fn test_prefer_ssl_conn() {
|
fn test_prefer_ssl_conn() {
|
||||||
let ctx = SslContext::new(Sslv3).unwrap();
|
let ctx = SslContext::new(Sslv3).unwrap();
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost",
|
||||||
&PreferSsl(ctx)));
|
&SslMode::Prefer(ctx)));
|
||||||
or_panic!(conn.execute("SELECT 1::VARCHAR", []));
|
or_panic!(conn.execute("SELECT 1::VARCHAR", []));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_plaintext_pass() {
|
fn test_plaintext_pass() {
|
||||||
or_panic!(Connection::connect("postgres://pass_user:password@localhost/postgres", &NoSsl));
|
or_panic!(Connection::connect("postgres://pass_user:password@localhost/postgres", &SslMode::None));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_plaintext_pass_no_pass() {
|
fn test_plaintext_pass_no_pass() {
|
||||||
let ret = Connection::connect("postgres://pass_user@localhost/postgres", &NoSsl);
|
let ret = Connection::connect("postgres://pass_user@localhost/postgres", &SslMode::None);
|
||||||
match ret {
|
match ret {
|
||||||
Err(MissingPassword) => (),
|
Err(MissingPassword) => (),
|
||||||
Err(err) => panic!("Unexpected error {}", err),
|
Err(err) => panic!("Unexpected error {}", err),
|
||||||
@ -661,7 +659,7 @@ fn test_plaintext_pass_no_pass() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_plaintext_pass_wrong_pass() {
|
fn test_plaintext_pass_wrong_pass() {
|
||||||
let ret = Connection::connect("postgres://pass_user:asdf@localhost/postgres", &NoSsl);
|
let ret = Connection::connect("postgres://pass_user:asdf@localhost/postgres", &SslMode::None);
|
||||||
match ret {
|
match ret {
|
||||||
Err(PgConnectDbError(DbError { code: InvalidPassword, .. })) => (),
|
Err(PgConnectDbError(DbError { code: InvalidPassword, .. })) => (),
|
||||||
Err(err) => panic!("Unexpected error {}", err),
|
Err(err) => panic!("Unexpected error {}", err),
|
||||||
@ -671,12 +669,12 @@ fn test_plaintext_pass_wrong_pass() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_md5_pass() {
|
fn test_md5_pass() {
|
||||||
or_panic!(Connection::connect("postgres://md5_user:password@localhost/postgres", &NoSsl));
|
or_panic!(Connection::connect("postgres://md5_user:password@localhost/postgres", &SslMode::None));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_md5_pass_no_pass() {
|
fn test_md5_pass_no_pass() {
|
||||||
let ret = Connection::connect("postgres://md5_user@localhost/postgres", &NoSsl);
|
let ret = Connection::connect("postgres://md5_user@localhost/postgres", &SslMode::None);
|
||||||
match ret {
|
match ret {
|
||||||
Err(MissingPassword) => (),
|
Err(MissingPassword) => (),
|
||||||
Err(err) => panic!("Unexpected error {}", err),
|
Err(err) => panic!("Unexpected error {}", err),
|
||||||
@ -686,7 +684,7 @@ fn test_md5_pass_no_pass() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_md5_pass_wrong_pass() {
|
fn test_md5_pass_wrong_pass() {
|
||||||
let ret = Connection::connect("postgres://md5_user:asdf@localhost/postgres", &NoSsl);
|
let ret = Connection::connect("postgres://md5_user:asdf@localhost/postgres", &SslMode::None);
|
||||||
match ret {
|
match ret {
|
||||||
Err(PgConnectDbError(DbError { code: InvalidPassword, .. })) => (),
|
Err(PgConnectDbError(DbError { code: InvalidPassword, .. })) => (),
|
||||||
Err(err) => panic!("Unexpected error {}", err),
|
Err(err) => panic!("Unexpected error {}", err),
|
||||||
@ -696,7 +694,7 @@ fn test_md5_pass_wrong_pass() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_execute_copy_from_err() {
|
fn test_execute_copy_from_err() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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"));
|
let stmt = or_panic!(conn.prepare("COPY foo (id) FROM STDIN"));
|
||||||
match stmt.execute([]) {
|
match stmt.execute([]) {
|
||||||
@ -713,7 +711,7 @@ fn test_execute_copy_from_err() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_copy_in() {
|
fn test_copy_in() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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"]));
|
||||||
@ -728,7 +726,7 @@ fn test_copy_in() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_copy_in_bad_column_count() {
|
fn test_copy_in_bad_column_count() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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"]));
|
||||||
@ -755,7 +753,7 @@ fn test_copy_in_bad_column_count() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_copy_in_bad_type() {
|
fn test_copy_in_bad_type() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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"]));
|
||||||
@ -773,7 +771,7 @@ fn test_copy_in_bad_type() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_batch_execute_copy_from_err() {
|
fn test_batch_execute_copy_from_err() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
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") {
|
match conn.batch_execute("COPY foo (id) FROM STDIN") {
|
||||||
Err(PgDbError(ref err)) if err.message[].contains("COPY") => {}
|
Err(PgDbError(ref err)) if err.message[].contains("COPY") => {}
|
||||||
@ -789,7 +787,7 @@ fn test_generic_connection() {
|
|||||||
or_panic!(t.execute("SELECT 1", []));
|
or_panic!(t.execute("SELECT 1", []));
|
||||||
}
|
}
|
||||||
|
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
f(&conn);
|
f(&conn);
|
||||||
let trans = or_panic!(conn.transaction());
|
let trans = or_panic!(conn.transaction());
|
||||||
f(&trans);
|
f(&trans);
|
||||||
|
@ -6,7 +6,7 @@ use time;
|
|||||||
use time::Timespec;
|
use time::Timespec;
|
||||||
use std::num::Float;
|
use std::num::Float;
|
||||||
|
|
||||||
use postgres::{Connection, NoSsl};
|
use postgres::{Connection, SslMode};
|
||||||
use postgres::types::array::ArrayBase;
|
use postgres::types::array::ArrayBase;
|
||||||
use postgres::types::{ToSql, FromSql};
|
use postgres::types::{ToSql, FromSql};
|
||||||
|
|
||||||
@ -31,7 +31,7 @@ mod range;
|
|||||||
mod uuid;
|
mod uuid;
|
||||||
|
|
||||||
fn test_type<T: PartialEq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S)]) {
|
fn test_type<T: PartialEq+FromSql+ToSql, S: Str>(sql_type: &str, checks: &[(T, S)]) {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
for &(ref val, ref repr) in checks.iter() {
|
for &(ref val, ref repr) in checks.iter() {
|
||||||
let stmt = or_panic!(conn.prepare(format!("SELECT {:s}::{}", *repr, sql_type)[]));
|
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);
|
||||||
@ -111,7 +111,7 @@ fn test_text_params() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bpchar_params() {
|
fn test_bpchar_params() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (
|
or_panic!(conn.execute("CREATE TEMPORARY TABLE foo (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
b CHAR(5)
|
b CHAR(5)
|
||||||
@ -337,7 +337,7 @@ fn test_hstore_params() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_nan_param<T: Float+ToSql+FromSql>(sql_type: &str) {
|
fn test_nan_param<T: Float+ToSql+FromSql>(sql_type: &str) {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let stmt = or_panic!(conn.prepare(format!("SELECT 'NaN'::{}", sql_type)[]));
|
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);
|
let val: T = result.next().unwrap().get(0u);
|
||||||
@ -373,7 +373,7 @@ fn test_jsonarray_params() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_pg_database_datname() {
|
fn test_pg_database_datname() {
|
||||||
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &NoSsl));
|
let conn = or_panic!(Connection::connect("postgres://postgres@localhost", &SslMode::None));
|
||||||
let stmt = or_panic!(conn.prepare("SELECT datname FROM pg_database"));
|
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([]));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user