mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-04-25 08:42:14 +00:00
Rename name to column_name
This commit is contained in:
parent
f36787e376
commit
949e2e2d2b
@ -55,6 +55,23 @@ impl<'l> Statement<'l> {
|
||||
unsafe { ffi::sqlite3_column_count(self.raw.0) as usize }
|
||||
}
|
||||
|
||||
/// Return the name of a column.
|
||||
#[inline]
|
||||
pub fn column_name(&self, i: usize) -> &str {
|
||||
debug_assert!(i < self.column_count(), "the index is out of range");
|
||||
unsafe {
|
||||
let pointer = ffi::sqlite3_column_name(self.raw.0, i as c_int);
|
||||
debug_assert!(!pointer.is_null());
|
||||
c_str_to_str!(pointer).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return column names.
|
||||
#[inline]
|
||||
pub fn column_names(&self) -> Vec<&str> {
|
||||
(0..self.column_count()).map(|i| self.column_name(i)).collect()
|
||||
}
|
||||
|
||||
/// Return the type of a column.
|
||||
///
|
||||
/// The type becomes available after taking a step.
|
||||
@ -70,23 +87,6 @@ impl<'l> Statement<'l> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the name of a column.
|
||||
#[inline]
|
||||
pub fn name(&self, i: usize) -> &str {
|
||||
debug_assert!(i < self.column_count(), "the index is out of range");
|
||||
unsafe {
|
||||
let pointer = ffi::sqlite3_column_name(self.raw.0, i as c_int);
|
||||
debug_assert!(!pointer.is_null());
|
||||
c_str_to_str!(pointer).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return column names.
|
||||
#[inline]
|
||||
pub fn names(&self) -> Vec<&str> {
|
||||
(0..self.column_count()).map(|i| self.name(i)).collect()
|
||||
}
|
||||
|
||||
/// Advance to the next state.
|
||||
///
|
||||
/// The function should be called multiple times until `State::Done` is
|
||||
|
@ -244,14 +244,14 @@ fn statement_column_count() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn statement_name() {
|
||||
fn statement_column_name() {
|
||||
let connection = setup_users(":memory:");
|
||||
let statement = "SELECT id, name, age, photo AS user_photo FROM users";
|
||||
let statement = ok!(connection.prepare(statement));
|
||||
|
||||
let names = statement.names();
|
||||
let names = statement.column_names();
|
||||
assert_eq!(names, vec!["id", "name", "age", "user_photo"]);
|
||||
assert_eq!("user_photo", statement.name(3));
|
||||
assert_eq!("user_photo", statement.column_name(3));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user