From 2c4d4e97eae4b64c685ff36fe04c8a017a97126c Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Fri, 8 Nov 2013 22:15:35 -0800 Subject: [PATCH] Remove find_col_named It's a very simple utility function that won't be used enough to keep it on a trait like PostgresStatement. --- lib.rs | 16 +++++----------- test.rs | 9 --------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/lib.rs b/lib.rs index 4a073e4f..9c06b062 100644 --- a/lib.rs +++ b/lib.rs @@ -926,14 +926,6 @@ pub trait PostgresStatement { Err(err) => fail!("Error executing query:\n{}", err.to_str()) } } - - /// Returns the index of the first result column with the specified name, - /// or `None` if not found. - fn find_col_named(&self, col: &str) -> Option { - do self.result_descriptions().iter().position |desc| { - desc.name.as_slice() == col - } - } } /// A statement prepared outside of a transaction. @@ -1296,9 +1288,11 @@ impl RowIndex for int { impl<'self> RowIndex for &'self str { #[inline] fn idx(&self, stmt: &NormalPostgresStatement) -> uint { - match stmt.find_col_named(*self) { - Some(idx) => idx, - None => fail!("No column with name {}", *self) + for (i, desc) in stmt.result_descriptions().iter().enumerate() { + if desc.name.as_slice() == *self { + return i; + } } + fail!("There is no colnum with name {}", *self); } } diff --git a/test.rs b/test.rs index 2ca94fbb..3adc4ffc 100644 --- a/test.rs +++ b/test.rs @@ -459,15 +459,6 @@ fn test_too_many_params() { &3i32 as &ToSql]); } -#[test] -fn test_find_col_named() { - let conn = PostgresConnection::connect("postgres://postgres@localhost"); - 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")); - assert_eq!(None, stmt.find_col_named("asdf")); -} - #[test] fn test_get_named() { let conn = PostgresConnection::connect("postgres://postgres@localhost");