mirror of
https://github.com/fluencelabs/sqlite-wasm-connector
synced 2025-03-15 06:20:50 +00:00
Change column_name to &str to avoid double allocation
This commit is contained in:
parent
fce61e13ad
commit
beda4c82c8
@ -57,16 +57,16 @@ impl<'l> Statement<'l> {
|
||||
|
||||
/// Return the name of a column in the statement
|
||||
#[inline]
|
||||
pub fn column_name(&self, i: usize) -> String {
|
||||
pub fn column_name(&self, i: usize) -> &str {
|
||||
unsafe {
|
||||
let ret = ffi::sqlite3_column_name(self.raw.0, i as c_int);
|
||||
c_str_to_string!(ret)
|
||||
c_str_to_str!(ret).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Return column names in the statement
|
||||
#[inline]
|
||||
pub fn column_names(&self) -> Vec<String> {
|
||||
pub fn column_names(&self) -> Vec<&str> {
|
||||
(0..self.columns()).map(|i| self.column_name(i)).collect()
|
||||
}
|
||||
|
||||
|
@ -142,9 +142,11 @@ fn statement_columns() {
|
||||
|
||||
assert_eq!(statement.columns(), 4);
|
||||
|
||||
let column_names = statement.column_names();
|
||||
assert_eq!(column_names, vec!["id", "name", "age", "user_photo"]);
|
||||
assert_eq!("user_photo", statement.column_name(3));
|
||||
{
|
||||
let column_names = statement.column_names();
|
||||
assert_eq!(column_names, vec!["id", "name", "age", "user_photo"]);
|
||||
assert_eq!("user_photo", statement.column_name(3));
|
||||
}
|
||||
|
||||
assert_eq!(ok!(statement.next()), State::Row);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user