Rename PostgresResult methods to be more clear
This commit is contained in:
parent
0a361967ce
commit
a17fe648de
10
src/lib.rs
10
src/lib.rs
@ -563,7 +563,7 @@ impl<'self> NormalPostgresStatement<'self> {
|
|||||||
row_limit: row_limit,
|
row_limit: row_limit,
|
||||||
more_rows: true
|
more_rows: true
|
||||||
};
|
};
|
||||||
result.load_rows();
|
result.read_rows();
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
@ -715,7 +715,7 @@ impl<'self> Drop for PostgresResult<'self> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'self> PostgresResult<'self> {
|
impl<'self> PostgresResult<'self> {
|
||||||
fn load_rows(&mut self) {
|
fn read_rows(&mut self) {
|
||||||
loop {
|
loop {
|
||||||
match_read_message_or_fail!(self.stmt.conn, {
|
match_read_message_or_fail!(self.stmt.conn, {
|
||||||
EmptyQueryResponse |
|
EmptyQueryResponse |
|
||||||
@ -733,21 +733,21 @@ impl<'self> PostgresResult<'self> {
|
|||||||
self.stmt.conn.wait_for_ready();
|
self.stmt.conn.wait_for_ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pull_rows(&mut self) {
|
fn execute(&mut self) {
|
||||||
self.stmt.conn.write_messages([
|
self.stmt.conn.write_messages([
|
||||||
&Execute {
|
&Execute {
|
||||||
portal: self.name,
|
portal: self.name,
|
||||||
max_rows: self.row_limit as i32
|
max_rows: self.row_limit as i32
|
||||||
},
|
},
|
||||||
&Sync]);
|
&Sync]);
|
||||||
self.load_rows();
|
self.read_rows();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'self> Iterator<PostgresRow<'self>> for PostgresResult<'self> {
|
impl<'self> Iterator<PostgresRow<'self>> for PostgresResult<'self> {
|
||||||
fn next(&mut self) -> Option<PostgresRow<'self>> {
|
fn next(&mut self) -> Option<PostgresRow<'self>> {
|
||||||
if self.data.is_empty() && self.more_rows {
|
if self.data.is_empty() && self.more_rows {
|
||||||
self.pull_rows();
|
self.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
do self.data.pop_front().map_move |row| {
|
do self.data.pop_front().map_move |row| {
|
||||||
|
42
src/test.rs
42
src/test.rs
@ -11,7 +11,7 @@ use postgres::types::{ToSql, FromSql, PgInt4, PgVarchar};
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_prepare_err() {
|
fn test_prepare_err() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
match conn.try_prepare("invalid sql statment") {
|
match conn.try_prepare("invalid sql statment") {
|
||||||
Err(PostgresDbError { position, code, _ }) => {
|
Err(PostgresDbError { position, code, _ }) => {
|
||||||
assert_eq!(code, ~"42601");
|
assert_eq!(code, ~"42601");
|
||||||
@ -26,7 +26,7 @@ fn test_prepare_err() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transaction_commit() {
|
fn test_transaction_commit() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
conn.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
|
conn.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
|
||||||
|
|
||||||
do conn.in_transaction |trans| {
|
do conn.in_transaction |trans| {
|
||||||
@ -41,7 +41,7 @@ fn test_transaction_commit() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_transaction_rollback() {
|
fn test_transaction_rollback() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
conn.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
|
conn.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
|
||||||
|
|
||||||
conn.update("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]);
|
conn.update("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]);
|
||||||
@ -58,7 +58,7 @@ fn test_transaction_rollback() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_nested_transactions() {
|
fn test_nested_transactions() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
conn.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
|
conn.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
|
||||||
|
|
||||||
conn.update("INSERT INTO foo (id) VALUES (1)", []);
|
conn.update("INSERT INTO foo (id) VALUES (1)", []);
|
||||||
@ -100,7 +100,7 @@ fn test_nested_transactions() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_query() {
|
fn test_query() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
conn.update("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", []);
|
conn.update("CREATE TEMPORARY TABLE foo (id BIGINT PRIMARY KEY)", []);
|
||||||
conn.update("INSERT INTO foo (id) VALUES ($1), ($2)",
|
conn.update("INSERT INTO foo (id) VALUES ($1), ($2)",
|
||||||
[&1i64 as &ToSql, &2i64 as &ToSql]);
|
[&1i64 as &ToSql, &2i64 as &ToSql]);
|
||||||
@ -112,7 +112,7 @@ fn test_query() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_lazy_query() {
|
fn test_lazy_query() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
|
|
||||||
do conn.in_transaction |trans| {
|
do conn.in_transaction |trans| {
|
||||||
trans.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
|
trans.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
|
||||||
@ -132,14 +132,14 @@ fn test_lazy_query() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_param_types() {
|
fn test_param_types() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
let stmt = conn.prepare("SELECT $1::INT, $2::VARCHAR");
|
let stmt = conn.prepare("SELECT $1::INT, $2::VARCHAR");
|
||||||
assert_eq!(stmt.param_types(), [PgInt4, PgVarchar]);
|
assert_eq!(stmt.param_types(), [PgInt4, PgVarchar]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_result_descriptions() {
|
fn test_result_descriptions() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
let stmt = conn.prepare("SELECT 1::INT as a, 'hi'::VARCHAR as b");
|
let stmt = conn.prepare("SELECT 1::INT as a, 'hi'::VARCHAR as b");
|
||||||
assert_eq!(stmt.result_descriptions(),
|
assert_eq!(stmt.result_descriptions(),
|
||||||
[ResultDescription { name: ~"a", ty: PgInt4},
|
[ResultDescription { name: ~"a", ty: PgInt4},
|
||||||
@ -147,7 +147,7 @@ fn test_result_descriptions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn test_type<T: Eq+ToSql+FromSql>(sql_type: &str, values: &[T]) {
|
fn test_type<T: Eq+ToSql+FromSql>(sql_type: &str, values: &[T]) {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
conn.update("CREATE TEMPORARY TABLE foo (
|
conn.update("CREATE TEMPORARY TABLE foo (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
b " + sql_type +
|
b " + sql_type +
|
||||||
@ -218,7 +218,7 @@ fn test_text_params() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_bpchar_params() {
|
fn test_bpchar_params() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
conn.update("CREATE TEMPORARY TABLE foo (
|
conn.update("CREATE TEMPORARY TABLE foo (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
b CHAR(5)
|
b CHAR(5)
|
||||||
@ -252,7 +252,7 @@ fn test_uuid_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 = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
let nan: T = Float::NaN();
|
let nan: T = Float::NaN();
|
||||||
let stmt = conn.prepare("SELECT $1::" + sql_type);
|
let stmt = conn.prepare("SELECT $1::" + sql_type);
|
||||||
let mut result = stmt.query([&nan as &ToSql]);
|
let mut result = stmt.query([&nan as &ToSql]);
|
||||||
@ -273,13 +273,13 @@ fn test_f64_nan_param() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_wrong_param_type() {
|
fn test_wrong_param_type() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
conn.try_update("SELECT $1::VARCHAR", [&1i32 as &ToSql]);
|
conn.try_update("SELECT $1::VARCHAR", [&1i32 as &ToSql]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_find_col_named() {
|
fn test_find_col_named() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
let stmt = conn.prepare("SELECT 1 as my_id, 'hi' as val");
|
let stmt = conn.prepare("SELECT 1 as my_id, 'hi' as val");
|
||||||
assert_eq!(Some(0), stmt.find_col_named("my_id"));
|
assert_eq!(Some(0), stmt.find_col_named("my_id"));
|
||||||
assert_eq!(Some(1), stmt.find_col_named("val"));
|
assert_eq!(Some(1), stmt.find_col_named("val"));
|
||||||
@ -288,7 +288,7 @@ fn test_find_col_named() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_get_named() {
|
fn test_get_named() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
let stmt = conn.prepare("SELECT 10::INT as val");
|
let stmt = conn.prepare("SELECT 10::INT as val");
|
||||||
let result = stmt.query([]);
|
let result = stmt.query([]);
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ fn test_get_named() {
|
|||||||
#[test]
|
#[test]
|
||||||
#[should_fail]
|
#[should_fail]
|
||||||
fn test_get_named_fail() {
|
fn test_get_named_fail() {
|
||||||
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1:5432");
|
let conn = PostgresConnection::connect("postgres://postgres@127.0.0.1");
|
||||||
let stmt = conn.prepare("SELECT 10::INT as id");
|
let stmt = conn.prepare("SELECT 10::INT as id");
|
||||||
let mut result = stmt.query([]);
|
let mut result = stmt.query([]);
|
||||||
|
|
||||||
@ -307,12 +307,12 @@ fn test_get_named_fail() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_plaintext_pass() {
|
fn test_plaintext_pass() {
|
||||||
PostgresConnection::connect("postgres://pass_user:password@127.0.0.1:5432");
|
PostgresConnection::connect("postgres://pass_user:password@127.0.0.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_plaintext_pass_no_pass() {
|
fn test_plaintext_pass_no_pass() {
|
||||||
let ret = PostgresConnection::try_connect("postgres://pass_user@127.0.0.1:5432");
|
let ret = PostgresConnection::try_connect("postgres://pass_user@127.0.0.1");
|
||||||
match ret {
|
match ret {
|
||||||
Err(MissingPassword) => (),
|
Err(MissingPassword) => (),
|
||||||
ret => fail!("Unexpected result %?", ret)
|
ret => fail!("Unexpected result %?", ret)
|
||||||
@ -321,7 +321,7 @@ fn test_plaintext_pass_no_pass() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_plaintext_pass_wrong_pass() {
|
fn test_plaintext_pass_wrong_pass() {
|
||||||
let ret = PostgresConnection::try_connect("postgres://pass_user:asdf@127.0.0.1:5432");
|
let ret = PostgresConnection::try_connect("postgres://pass_user:asdf@127.0.0.1");
|
||||||
match ret {
|
match ret {
|
||||||
Err(DbError(PostgresDbError { code: ~"28P01", _ })) => (),
|
Err(DbError(PostgresDbError { code: ~"28P01", _ })) => (),
|
||||||
ret => fail!("Unexpected result %?", ret)
|
ret => fail!("Unexpected result %?", ret)
|
||||||
@ -330,12 +330,12 @@ fn test_plaintext_pass_wrong_pass() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_md5_pass() {
|
fn test_md5_pass() {
|
||||||
PostgresConnection::connect("postgres://md5_user:password@127.0.0.1:5432");
|
PostgresConnection::connect("postgres://md5_user:password@127.0.0.1");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_md5_pass_no_pass() {
|
fn test_md5_pass_no_pass() {
|
||||||
let ret = PostgresConnection::try_connect("postgres://md5_user@127.0.0.1:5432");
|
let ret = PostgresConnection::try_connect("postgres://md5_user@127.0.0.1");
|
||||||
match ret {
|
match ret {
|
||||||
Err(MissingPassword) => (),
|
Err(MissingPassword) => (),
|
||||||
ret => fail!("Unexpected result %?", ret)
|
ret => fail!("Unexpected result %?", ret)
|
||||||
@ -344,7 +344,7 @@ fn test_md5_pass_no_pass() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_md5_pass_wrong_pass() {
|
fn test_md5_pass_wrong_pass() {
|
||||||
let ret = PostgresConnection::try_connect("postgres://md5_user:asdf@127.0.0.1:5432");
|
let ret = PostgresConnection::try_connect("postgres://md5_user:asdf@127.0.0.1");
|
||||||
match ret {
|
match ret {
|
||||||
Err(DbError(PostgresDbError { code: ~"28P01", _ })) => (),
|
Err(DbError(PostgresDbError { code: ~"28P01", _ })) => (),
|
||||||
ret => fail!("Unexpected result %?", ret)
|
ret => fail!("Unexpected result %?", ret)
|
||||||
|
Loading…
Reference in New Issue
Block a user