Rename column_name to name

This commit is contained in:
Ivan Ukhov 2018-10-06 10:11:18 +02:00
parent cf7a3d7500
commit db5ceccf58
2 changed files with 7 additions and 8 deletions

View File

@ -57,7 +57,7 @@ impl<'l> Statement<'l> {
/// Return the name of a column. /// Return the name of a column.
#[inline] #[inline]
pub fn column_name(&self, i: usize) -> &str { pub fn name(&self, i: usize) -> &str {
debug_assert!(i < self.columns(), format!("column position has to be between 0 and {}", self.columns() - 1)); debug_assert!(i < self.columns(), format!("column position has to be between 0 and {}", self.columns() - 1));
unsafe { unsafe {
let ret = ffi::sqlite3_column_name(self.raw.0, i as c_int); let ret = ffi::sqlite3_column_name(self.raw.0, i as c_int);
@ -67,8 +67,8 @@ impl<'l> Statement<'l> {
/// Return column names. /// Return column names.
#[inline] #[inline]
pub fn column_names(&self) -> Vec<&str> { pub fn names(&self) -> Vec<&str> {
(0..self.columns()).map(|i| self.column_name(i)).collect() (0..self.columns()).map(|i| self.name(i)).collect()
} }
/// Return the type of a column. /// Return the type of a column.

View File

@ -146,17 +146,16 @@ fn statement_columns() {
} }
#[test] #[test]
fn statement_column_name() { fn statement_name() {
let connection = setup_users(":memory:"); let connection = setup_users(":memory:");
let statement = "SELECT id, name, age, photo as user_photo FROM users"; let statement = "SELECT id, name, age, photo as user_photo FROM users";
let statement = ok!(connection.prepare(statement)); let statement = ok!(connection.prepare(statement));
assert_eq!(statement.columns(), 4); assert_eq!(statement.columns(), 4);
let column_names = statement.column_names(); let names = statement.names();
assert_eq!(column_names, vec!["id", "name", "age", "user_photo"]); assert_eq!(names, vec!["id", "name", "age", "user_photo"]);
assert_eq!("user_photo", statement.column_name(3)); assert_eq!("user_photo", statement.name(3));
} }
#[test] #[test]