Rename columns to count

This commit is contained in:
Ivan Ukhov 2018-10-06 10:13:23 +02:00
parent db5ceccf58
commit 8ddb310ed8
3 changed files with 8 additions and 10 deletions

View File

@ -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)));

View File

@ -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.

View File

@ -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));