From 438312c132230946269e0d61b397fcfb845b56c4 Mon Sep 17 00:00:00 2001 From: gwenn Date: Sun, 14 Aug 2016 09:44:37 +0200 Subject: [PATCH] Change signature of VTab::best_index --- src/vtab/csvtab.rs | 4 +++- src/vtab/int_array.rs | 4 +++- src/vtab/mod.rs | 23 +++++++++++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/vtab/csvtab.rs b/src/vtab/csvtab.rs index e49048f..cabbfc1 100644 --- a/src/vtab/csvtab.rs +++ b/src/vtab/csvtab.rs @@ -131,7 +131,9 @@ impl VTab for CSVTab { Ok(vtab) } - fn best_index(&self, _info: &mut IndexInfo) {} + fn best_index(&self, _info: &mut IndexInfo) -> Result<()> { + Ok(()) + } fn open(&self) -> Result { Ok(CSVTabCursor::new(try!(self.reader()))) diff --git a/src/vtab/int_array.rs b/src/vtab/int_array.rs index a298324..a4183aa 100644 --- a/src/vtab/int_array.rs +++ b/src/vtab/int_array.rs @@ -71,7 +71,9 @@ impl VTab for IntArrayVTab { Ok(vtab) } - fn best_index(&self, _info: &mut IndexInfo) {} + fn best_index(&self, _info: &mut IndexInfo) -> Result<()> { + Ok(()) + } fn open(&self) -> Result { Ok(IntArrayVTabCursor::new()) diff --git a/src/vtab/mod.rs b/src/vtab/mod.rs index 1662ac4..190c857 100644 --- a/src/vtab/mod.rs +++ b/src/vtab/mod.rs @@ -46,7 +46,7 @@ pub trait VTab>: Sized { /// The `db` parameter is a pointer to the SQLite database connection that is executing the CREATE VIRTUAL TABLE statement. fn create(db: *mut ffi::sqlite3, aux: *mut libc::c_void, args: &[&[u8]]) -> Result; /// Determine the best way to access the virtual table. - fn best_index(&self, info: &mut IndexInfo); + fn best_index(&self, info: &mut IndexInfo) -> Result<()>; /// Create a new cursor used for accessing a virtual table. fn open(&self) -> Result; } @@ -248,10 +248,25 @@ unsafe extern "C" fn $create(db: *mut ffi::sqlite3, unsafe extern "C" fn $best_index(vtab: *mut ffi::sqlite3_vtab, info: *mut ffi::sqlite3_index_info) -> libc::c_int { - let vtab = vtab as *mut $vtab; + use std::error::Error as StdError; + use vtab::set_err_msg; + let vt = vtab as *mut $vtab; let mut idx_info = IndexInfo(info); - (*vtab).best_index(&mut idx_info); - ffi::SQLITE_OK + match (*vt).best_index(&mut idx_info) { + Ok(_) => ffi::SQLITE_OK, + Err(Error::SqliteFailure(err, s)) => { + if let Some(err_msg) = s { + set_err_msg(vtab, &err_msg); + } + err.extended_code + }, + Err(err) => { + set_err_msg(vtab, err.description()); + ffi::SQLITE_ERROR + } + + } + } unsafe extern "C" fn $destroy(vtab: *mut ffi::sqlite3_vtab) -> libc::c_int { let vtab = vtab as *mut $vtab;