This commit is contained in:
gwenn 2016-05-20 18:36:44 +02:00
parent 0740620ffe
commit cbc479c484
4 changed files with 19 additions and 11 deletions

View File

@ -109,7 +109,9 @@ impl fmt::Display for Error {
Error::QueryReturnedNoRows => write!(f, "Query returned no rows"), Error::QueryReturnedNoRows => write!(f, "Query returned no rows"),
Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {}", i), Error::InvalidColumnIndex(i) => write!(f, "Invalid column index: {}", i),
Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {}", name), Error::InvalidColumnName(ref name) => write!(f, "Invalid column name: {}", name),
Error::InvalidColumnType(i, t) => write!(f, "Invalid column type {} at index: {}", t, i), Error::InvalidColumnType(i, t) => {
write!(f, "Invalid column type {} at index: {}", t, i)
}
Error::StatementChangedRows(i) => write!(f, "Query changed {} rows", i), Error::StatementChangedRows(i) => write!(f, "Query changed {} rows", i),
Error::StatementFailedToInsertRow => write!(f, "Statement failed to insert new row"), Error::StatementFailedToInsertRow => write!(f, "Statement failed to insert new row"),

View File

@ -88,7 +88,10 @@ pub trait FromSql: Sized {
} }
} }
unsafe fn column_has_expected_typed(stmt: *mut sqlite3_stmt, col: c_int, expected_type: c_int) -> Result<()> { unsafe fn column_has_expected_typed(stmt: *mut sqlite3_stmt,
col: c_int,
expected_type: c_int)
-> Result<()> {
let actual_type = sqlite3_column_type(stmt, col); let actual_type = sqlite3_column_type(stmt, col);
if actual_type == expected_type { if actual_type == expected_type {
Ok(()) Ok(())

View File

@ -47,8 +47,8 @@ impl CSVTab {
fn reader(&self) -> result::Result<csv::Reader<File>, csv::Error> { fn reader(&self) -> result::Result<csv::Reader<File>, csv::Error> {
csv::Reader::from_file(&self.filename).map(|reader| { csv::Reader::from_file(&self.filename).map(|reader| {
reader.has_headers(self.has_headers) reader.has_headers(self.has_headers)
.delimiter(self.delimiter) .delimiter(self.delimiter)
.quote(self.quote) .quote(self.quote)
}) })
} }
} }
@ -228,7 +228,7 @@ impl From<csv::Error> for Error {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use {Connection,Result}; use {Connection, Result};
use vtab::csvtab; use vtab::csvtab;
#[test] #[test]
@ -244,7 +244,8 @@ mod test {
assert_eq!(vec!["rowid", "colA", "colB", "colC"], headers); assert_eq!(vec!["rowid", "colA", "colB", "colC"], headers);
} }
let ids: Result<Vec<i32>> = s.query_map(&[], |row| row.get::<i32, i32>(0)).unwrap().collect(); let ids: Result<Vec<i32>> =
s.query_map(&[], |row| row.get::<i32, i32>(0)).unwrap().collect();
let sum = ids.unwrap().iter().fold(0, |acc, &id| acc + id); let sum = ids.unwrap().iter().fold(0, |acc, &id| acc + id);
assert_eq!(sum, 15); assert_eq!(sum, 15);
} }
@ -258,9 +259,10 @@ mod test {
db.execute_batch("CREATE VIRTUAL TABLE vtab USING csv('test.csv', HAS_HEADERS)").unwrap(); db.execute_batch("CREATE VIRTUAL TABLE vtab USING csv('test.csv', HAS_HEADERS)").unwrap();
{ {
let mut s = db.prepare("SELECT v1.rowid, v1.* FROM vtab v1 NATURAL JOIN vtab v2 \ let mut s =
WHERE v1.rowid < v2.rowid") db.prepare("SELECT v1.rowid, v1.* FROM vtab v1 NATURAL JOIN vtab v2 WHERE \
.unwrap(); v1.rowid < v2.rowid")
.unwrap();
let mut rows = s.query(&[]).unwrap(); let mut rows = s.query(&[]).unwrap();
let row = rows.next().unwrap().unwrap(); let row = rows.next().unwrap().unwrap();

View File

@ -31,8 +31,9 @@ pub fn drop_int_array(conn: &Connection, name: &str) -> Result<()> {
conn.execute_batch(&format!("DROP TABLE temp.\"{0}\"", escape_double_quote(name))) conn.execute_batch(&format!("DROP TABLE temp.\"{0}\"", escape_double_quote(name)))
// http://www.mail-archive.com/sqlite-users%40mailinglists.sqlite.org/msg08423.html // http://www.mail-archive.com/sqlite-users%40mailinglists.sqlite.org/msg08423.html
// "Once a virtual table module has been created, it cannot be modified or destroyed, except by closing the database connection." // "Once a virtual table module has been created, it cannot be modified or destroyed, except by closing the database connection."
/*let aux: Option<()> = None; // let aux: Option<()> = None;
conn.create_module(name, ptr::null() as *const ffi::sqlite3_module, aux)*/ // conn.create_module(name, ptr::null() as *const ffi::sqlite3_module, aux)
} }
init_module!(INT_ARRAY_MODULE, init_module!(INT_ARRAY_MODULE,