diff --git a/src/cursor.rs b/src/cursor.rs index 98f0a54..b3eabc9 100644 --- a/src/cursor.rs +++ b/src/cursor.rs @@ -22,8 +22,8 @@ impl<'l> Cursor<'l> { /// Return the number of columns. #[inline] - pub fn columns(&self) -> usize { - self.statement.columns() + pub fn count(&self) -> usize { + self.statement.count() } /// Advance to the next row and read all columns. @@ -58,7 +58,7 @@ impl<'l> Cursor<'l> { values } _ => { - let count = self.statement.columns(); + let count = self.statement.count(); let mut values = Vec::with_capacity(count); for i in 0..count { values.push(try!(self.statement.read(i))); diff --git a/src/statement.rs b/src/statement.rs index a79b4d4..d2995e8 100644 --- a/src/statement.rs +++ b/src/statement.rs @@ -51,14 +51,14 @@ impl<'l> Statement<'l> { /// Return the number of columns. #[inline] - pub fn columns(&self) -> usize { + pub fn count(&self) -> usize { unsafe { ffi::sqlite3_column_count(self.raw.0) as usize } } /// Return the name of a column. #[inline] 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.count(), format!("column position has to be between 0 and {}", self.count() - 1)); unsafe { let ret = ffi::sqlite3_column_name(self.raw.0, i as c_int); c_str_to_str!(ret).unwrap() @@ -68,7 +68,7 @@ impl<'l> Statement<'l> { /// Return column names. #[inline] pub fn names(&self) -> Vec<&str> { - (0..self.columns()).map(|i| self.name(i)).collect() + (0..self.count()).map(|i| self.name(i)).collect() } /// Return the type of a column. diff --git a/tests/lib.rs b/tests/lib.rs index 5501c69..10a00bd 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -135,14 +135,14 @@ fn cursor_workflow() { } #[test] -fn statement_columns() { +fn statement_count() { let connection = setup_users(":memory:"); let statement = "SELECT * FROM users"; let mut statement = ok!(connection.prepare(statement)); assert_eq!(ok!(statement.next()), State::Row); - assert_eq!(statement.columns(), 4); + assert_eq!(statement.count(), 4); } #[test] @@ -151,8 +151,6 @@ fn statement_name() { let statement = "SELECT id, name, age, photo as user_photo FROM users"; let statement = ok!(connection.prepare(statement)); - assert_eq!(statement.columns(), 4); - let names = statement.names(); assert_eq!(names, vec!["id", "name", "age", "user_photo"]); assert_eq!("user_photo", statement.name(3));