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.
This commit is contained in:
parent
d9a8e261f7
commit
2c4d4e97ea
16
lib.rs
16
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<uint> {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
9
test.rs
9
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");
|
||||
|
Loading…
Reference in New Issue
Block a user