Created
November 15, 2014 12:07
-
-
Save abhijeetbhagat/05fbde29f192409bc5b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn fetchall(&mut self)->Vec<Vec<Option<c_str::CString>>>{ | |
let mut v = Vec::new(); | |
loop{ | |
match self.step(){ //we are not borrowing, hence no &...ref... | |
Some(row) => v.push(row.clone()), //without cloning, all rows will be same | |
_ => break | |
} | |
} | |
return v; | |
} | |
fn step(&mut self)->Option<Vec<Option<c_str::CString>>>{ | |
let mut v = vec![]; | |
unsafe{ | |
match sqlite3_step(self.stmt){ | |
SQLITE_DONE => {println!("done");return None;}, | |
SQLITE_ROW => { | |
for i in range(0i32, 4){ | |
let col_name = sqlite3_column_text(self.stmt, i); | |
if col_name.is_null(){ | |
v.push(None); | |
} | |
let name = c_str::CString::new(col_name, false); | |
v.push(Some(name)); //cant extract &str here since it's lifetime is shorter | |
//than v; | |
} | |
return Some(v); | |
}, | |
_ => return None | |
}//match ends | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment