Rename PostgresResult methods to be more clear

This commit is contained in:
Steven Fackler 2013-09-05 20:31:23 -07:00
parent 0a361967ce
commit a17fe648de
2 changed files with 26 additions and 26 deletions

View File

@ -563,7 +563,7 @@ impl<'self> NormalPostgresStatement<'self> {
row_limit: row_limit,
more_rows: true
};
result.load_rows();
result.read_rows();
Ok(result)
}
@ -715,7 +715,7 @@ impl<'self> Drop for PostgresResult<'self> {
}
impl<'self> PostgresResult<'self> {
fn load_rows(&mut self) {
fn read_rows(&mut self) {
loop {
match_read_message_or_fail!(self.stmt.conn, {
EmptyQueryResponse |
@ -733,21 +733,21 @@ impl<'self> PostgresResult<'self> {
self.stmt.conn.wait_for_ready();
}
fn pull_rows(&mut self) {
fn execute(&mut self) {
self.stmt.conn.write_messages([
&Execute {
portal: self.name,
max_rows: self.row_limit as i32
},
&Sync]);
self.load_rows();
self.read_rows();
}
}
impl<'self> Iterator<PostgresRow<'self>> for PostgresResult<'self> {
fn next(&mut self) -> Option<PostgresRow<'self>> {
if self.data.is_empty() && self.more_rows {
self.pull_rows();
self.execute();
}
do self.data.pop_front().map_move |row| {

View File

@ -11,7 +11,7 @@ use postgres::types::{ToSql, FromSql, PgInt4, PgVarchar};
#[test]
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") {
Err(PostgresDbError { position, code, _ }) => {
assert_eq!(code, ~"42601");
@ -26,7 +26,7 @@ fn test_prepare_err() {
#[test]
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)", []);
do conn.in_transaction |trans| {
@ -41,7 +41,7 @@ fn test_transaction_commit() {
#[test]
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("INSERT INTO foo (id) VALUES ($1)", [&1i32 as &ToSql]);
@ -58,7 +58,7 @@ fn test_transaction_rollback() {
#[test]
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("INSERT INTO foo (id) VALUES (1)", []);
@ -100,7 +100,7 @@ fn test_nested_transactions() {
#[test]
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("INSERT INTO foo (id) VALUES ($1), ($2)",
[&1i64 as &ToSql, &2i64 as &ToSql]);
@ -112,7 +112,7 @@ fn test_query() {
#[test]
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| {
trans.update("CREATE TEMPORARY TABLE foo (id INT PRIMARY KEY)", []);
@ -132,14 +132,14 @@ fn test_lazy_query() {
#[test]
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");
assert_eq!(stmt.param_types(), [PgInt4, PgVarchar]);
}
#[test]
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");
assert_eq!(stmt.result_descriptions(),
[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]) {
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 SERIAL PRIMARY KEY,
b " + sql_type +
@ -218,7 +218,7 @@ fn test_text_params() {
#[test]
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 (
id SERIAL PRIMARY KEY,
b CHAR(5)
@ -252,7 +252,7 @@ fn test_uuid_params() {
}
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 stmt = conn.prepare("SELECT $1::" + sql_type);
let mut result = stmt.query([&nan as &ToSql]);
@ -273,13 +273,13 @@ fn test_f64_nan_param() {
#[test]
#[should_fail]
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]);
}
#[test]
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");
assert_eq!(Some(0), stmt.find_col_named("my_id"));
assert_eq!(Some(1), stmt.find_col_named("val"));
@ -288,7 +288,7 @@ fn test_find_col_named() {
#[test]
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 result = stmt.query([]);
@ -298,7 +298,7 @@ fn test_get_named() {
#[test]
#[should_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 mut result = stmt.query([]);
@ -307,12 +307,12 @@ fn test_get_named_fail() {
#[test]
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]
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 {
Err(MissingPassword) => (),
ret => fail!("Unexpected result %?", ret)
@ -321,7 +321,7 @@ fn test_plaintext_pass_no_pass() {
#[test]
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 {
Err(DbError(PostgresDbError { code: ~"28P01", _ })) => (),
ret => fail!("Unexpected result %?", ret)
@ -330,12 +330,12 @@ fn test_plaintext_pass_wrong_pass() {
#[test]
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]
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 {
Err(MissingPassword) => (),
ret => fail!("Unexpected result %?", ret)
@ -344,7 +344,7 @@ fn test_md5_pass_no_pass() {
#[test]
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 {
Err(DbError(PostgresDbError { code: ~"28P01", _ })) => (),
ret => fail!("Unexpected result %?", ret)