mirror of
				https://github.com/isar/rusqlite.git
				synced 2025-11-04 08:08:55 +08:00 
			
		
		
		
	Replace try! by ?
				
					
				
			This commit is contained in:
		@@ -23,8 +23,8 @@
 | 
			
		||||
//!     dst: P,
 | 
			
		||||
//!     progress: fn(backup::Progress),
 | 
			
		||||
//! ) -> Result<()> {
 | 
			
		||||
//!     let mut dst = try!(Connection::open(dst));
 | 
			
		||||
//!     let backup = try!(backup::Backup::new(src, &mut dst));
 | 
			
		||||
//!     let mut dst = Connection::open(dst)?;
 | 
			
		||||
//!     let backup = backup::Backup::new(src, &mut dst)?;
 | 
			
		||||
//!     backup.run_to_completion(5, time::Duration::from_millis(250), Some(progress))
 | 
			
		||||
//! }
 | 
			
		||||
//! ```
 | 
			
		||||
@@ -62,17 +62,12 @@ impl Connection {
 | 
			
		||||
        progress: Option<fn(Progress)>,
 | 
			
		||||
    ) -> Result<()> {
 | 
			
		||||
        use self::StepResult::{Busy, Done, Locked, More};
 | 
			
		||||
        let mut dst = try!(Connection::open(dst_path));
 | 
			
		||||
        let backup = try!(Backup::new_with_names(
 | 
			
		||||
            self,
 | 
			
		||||
            name,
 | 
			
		||||
            &mut dst,
 | 
			
		||||
            DatabaseName::Main
 | 
			
		||||
        ));
 | 
			
		||||
        let mut dst = Connection::open(dst_path)?;
 | 
			
		||||
        let backup = Backup::new_with_names(self, name, &mut dst, DatabaseName::Main)?;
 | 
			
		||||
 | 
			
		||||
        let mut r = More;
 | 
			
		||||
        while r == More {
 | 
			
		||||
            r = try!(backup.step(100));
 | 
			
		||||
            r = backup.step(100)?;
 | 
			
		||||
            if let Some(f) = progress {
 | 
			
		||||
                f(backup.progress());
 | 
			
		||||
            }
 | 
			
		||||
@@ -105,13 +100,13 @@ impl Connection {
 | 
			
		||||
        progress: Option<F>,
 | 
			
		||||
    ) -> Result<()> {
 | 
			
		||||
        use self::StepResult::{Busy, Done, Locked, More};
 | 
			
		||||
        let src = try!(Connection::open(src_path));
 | 
			
		||||
        let restore = try!(Backup::new_with_names(&src, DatabaseName::Main, self, name));
 | 
			
		||||
        let src = Connection::open(src_path)?;
 | 
			
		||||
        let restore = Backup::new_with_names(&src, DatabaseName::Main, self, name)?;
 | 
			
		||||
 | 
			
		||||
        let mut r = More;
 | 
			
		||||
        let mut busy_count = 0i32;
 | 
			
		||||
        'restore_loop: while r == More || r == Busy {
 | 
			
		||||
            r = try!(restore.step(100));
 | 
			
		||||
            r = restore.step(100)?;
 | 
			
		||||
            if let Some(ref f) = progress {
 | 
			
		||||
                f(restore.progress());
 | 
			
		||||
            }
 | 
			
		||||
@@ -201,8 +196,8 @@ impl<'a, 'b> Backup<'a, 'b> {
 | 
			
		||||
        to: &'b mut Connection,
 | 
			
		||||
        to_name: DatabaseName,
 | 
			
		||||
    ) -> Result<Backup<'a, 'b>> {
 | 
			
		||||
        let to_name = try!(to_name.to_cstring());
 | 
			
		||||
        let from_name = try!(from_name.to_cstring());
 | 
			
		||||
        let to_name = to_name.to_cstring()?;
 | 
			
		||||
        let from_name = from_name.to_cstring()?;
 | 
			
		||||
 | 
			
		||||
        let to_db = to.db.borrow_mut().db;
 | 
			
		||||
 | 
			
		||||
@@ -287,7 +282,7 @@ impl<'a, 'b> Backup<'a, 'b> {
 | 
			
		||||
        assert!(pages_per_step > 0, "pages_per_step must be positive");
 | 
			
		||||
 | 
			
		||||
        loop {
 | 
			
		||||
            let r = try!(self.step(pages_per_step));
 | 
			
		||||
            let r = self.step(pages_per_step)?;
 | 
			
		||||
            if let Some(progress) = progress {
 | 
			
		||||
                progress(self.progress())
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										10
									
								
								src/blob.rs
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/blob.rs
									
									
									
									
									
								
							@@ -92,9 +92,9 @@ impl Connection {
 | 
			
		||||
    ) -> Result<Blob<'a>> {
 | 
			
		||||
        let mut c = self.db.borrow_mut();
 | 
			
		||||
        let mut blob = ptr::null_mut();
 | 
			
		||||
        let db = try!(db.to_cstring());
 | 
			
		||||
        let table = try!(super::str_to_cstring(table));
 | 
			
		||||
        let column = try!(super::str_to_cstring(column));
 | 
			
		||||
        let db = db.to_cstring()?;
 | 
			
		||||
        let table = super::str_to_cstring(table)?;
 | 
			
		||||
        let column = super::str_to_cstring(column)?;
 | 
			
		||||
        let rc = unsafe {
 | 
			
		||||
            ffi::sqlite3_blob_open(
 | 
			
		||||
                c.db(),
 | 
			
		||||
@@ -266,12 +266,12 @@ mod test {
 | 
			
		||||
    use {Connection, DatabaseName, Result};
 | 
			
		||||
 | 
			
		||||
    fn db_with_test_blob() -> Result<(Connection, i64)> {
 | 
			
		||||
        let db = try!(Connection::open_in_memory());
 | 
			
		||||
        let db = Connection::open_in_memory()?;
 | 
			
		||||
        let sql = "BEGIN;
 | 
			
		||||
                   CREATE TABLE test (content BLOB);
 | 
			
		||||
                   INSERT INTO test VALUES (ZEROBLOB(10));
 | 
			
		||||
                   END;";
 | 
			
		||||
        try!(db.execute_batch(sql));
 | 
			
		||||
        db.execute_batch(sql)?;
 | 
			
		||||
        let rowid = db.last_insert_rowid();
 | 
			
		||||
        Ok((db, rowid))
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -16,14 +16,14 @@ impl Connection {
 | 
			
		||||
    /// # use rusqlite::{Connection, Result};
 | 
			
		||||
    /// fn insert_new_people(conn: &Connection) -> Result<()> {
 | 
			
		||||
    ///     {
 | 
			
		||||
    ///         let mut stmt = try!(conn.prepare_cached("INSERT INTO People (name) VALUES (?)"));
 | 
			
		||||
    ///         try!(stmt.execute(&["Joe Smith"]));
 | 
			
		||||
    ///         let mut stmt = conn.prepare_cached("INSERT INTO People (name) VALUES (?)")?;
 | 
			
		||||
    ///         stmt.execute(&["Joe Smith"])?;
 | 
			
		||||
    ///     }
 | 
			
		||||
    ///     {
 | 
			
		||||
    ///         // This will return the same underlying SQLite statement handle without
 | 
			
		||||
    ///         // having to prepare it again.
 | 
			
		||||
    ///         let mut stmt = try!(conn.prepare_cached("INSERT INTO People (name) VALUES (?)"));
 | 
			
		||||
    ///         try!(stmt.execute(&["Bob Jones"]));
 | 
			
		||||
    ///         let mut stmt = conn.prepare_cached("INSERT INTO People (name) VALUES (?)")?;
 | 
			
		||||
    ///         stmt.execute(&["Bob Jones"])?;
 | 
			
		||||
    ///     }
 | 
			
		||||
    ///     Ok(())
 | 
			
		||||
    /// }
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@
 | 
			
		||||
//! fn add_regexp_function(db: &Connection) -> Result<()> {
 | 
			
		||||
//!     let mut cached_regexes = HashMap::new();
 | 
			
		||||
//!     db.create_scalar_function("regexp", 2, true, move |ctx| {
 | 
			
		||||
//!         let regex_s = try!(ctx.get::<String>(0));
 | 
			
		||||
//!         let regex_s = ctx.get::<String>(0)?;
 | 
			
		||||
//!         let entry = cached_regexes.entry(regex_s.clone());
 | 
			
		||||
//!         let regex = {
 | 
			
		||||
//!             use std::collections::hash_map::Entry::{Occupied, Vacant};
 | 
			
		||||
@@ -33,7 +33,7 @@
 | 
			
		||||
//!             }
 | 
			
		||||
//!         };
 | 
			
		||||
//!
 | 
			
		||||
//!         let text = try!(ctx.get::<String>(1));
 | 
			
		||||
//!         let text = ctx.get::<String>(1)?;
 | 
			
		||||
//!         Ok(regex.is_match(&text))
 | 
			
		||||
//!     })
 | 
			
		||||
//! }
 | 
			
		||||
@@ -224,12 +224,12 @@ impl Connection {
 | 
			
		||||
    /// ```rust
 | 
			
		||||
    /// # use rusqlite::{Connection, Result, NO_PARAMS};
 | 
			
		||||
    /// fn scalar_function_example(db: Connection) -> Result<()> {
 | 
			
		||||
    ///     try!(db.create_scalar_function("halve", 1, true, |ctx| {
 | 
			
		||||
    ///         let value = try!(ctx.get::<f64>(0));
 | 
			
		||||
    ///     db.create_scalar_function("halve", 1, true, |ctx| {
 | 
			
		||||
    ///         let value = ctx.get::<f64>(0)?;
 | 
			
		||||
    ///         Ok(value / 2f64)
 | 
			
		||||
    ///     }));
 | 
			
		||||
    ///     })?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     let six_halved: f64 = try!(db.query_row("SELECT halve(6)", NO_PARAMS, |r| r.get(0)));
 | 
			
		||||
    ///     let six_halved: f64 = db.query_row("SELECT halve(6)", NO_PARAMS, |r| r.get(0))?;
 | 
			
		||||
    ///     assert_eq!(six_halved, 3f64);
 | 
			
		||||
    ///     Ok(())
 | 
			
		||||
    /// }
 | 
			
		||||
@@ -326,7 +326,7 @@ impl InnerConnection {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let boxed_f: *mut F = Box::into_raw(Box::new(x_func));
 | 
			
		||||
        let c_name = try!(str_to_cstring(fn_name));
 | 
			
		||||
        let c_name = str_to_cstring(fn_name)?;
 | 
			
		||||
        let mut flags = ffi::SQLITE_UTF8;
 | 
			
		||||
        if deterministic {
 | 
			
		||||
            flags |= ffi::SQLITE_DETERMINISTIC;
 | 
			
		||||
@@ -441,7 +441,7 @@ impl InnerConnection {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        let boxed_aggr: *mut D = Box::into_raw(Box::new(aggr));
 | 
			
		||||
        let c_name = try!(str_to_cstring(fn_name));
 | 
			
		||||
        let c_name = str_to_cstring(fn_name)?;
 | 
			
		||||
        let mut flags = ffi::SQLITE_UTF8;
 | 
			
		||||
        if deterministic {
 | 
			
		||||
            flags |= ffi::SQLITE_DETERMINISTIC;
 | 
			
		||||
@@ -463,7 +463,7 @@ impl InnerConnection {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn remove_function(&mut self, fn_name: &str, n_arg: c_int) -> Result<()> {
 | 
			
		||||
        let c_name = try!(str_to_cstring(fn_name));
 | 
			
		||||
        let c_name = str_to_cstring(fn_name)?;
 | 
			
		||||
        let r = unsafe {
 | 
			
		||||
            ffi::sqlite3_create_function_v2(
 | 
			
		||||
                self.db(),
 | 
			
		||||
@@ -495,7 +495,7 @@ mod test {
 | 
			
		||||
 | 
			
		||||
    fn half(ctx: &Context) -> Result<c_double> {
 | 
			
		||||
        assert!(ctx.len() == 1, "called with unexpected number of arguments");
 | 
			
		||||
        let value = try!(ctx.get::<c_double>(0));
 | 
			
		||||
        let value = ctx.get::<c_double>(0)?;
 | 
			
		||||
        Ok(value / 2f64)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -529,7 +529,7 @@ mod test {
 | 
			
		||||
        let saved_re: Option<&Regex> = unsafe { ctx.get_aux(0) };
 | 
			
		||||
        let new_re = match saved_re {
 | 
			
		||||
            None => {
 | 
			
		||||
                let s = try!(ctx.get::<String>(0));
 | 
			
		||||
                let s = ctx.get::<String>(0)?;
 | 
			
		||||
                match Regex::new(&s) {
 | 
			
		||||
                    Ok(r) => Some(r),
 | 
			
		||||
                    Err(err) => return Err(Error::UserFunctionError(Box::new(err))),
 | 
			
		||||
@@ -607,7 +607,7 @@ mod test {
 | 
			
		||||
        db.create_scalar_function("regexp", 2, true, move |ctx| {
 | 
			
		||||
            assert!(ctx.len() == 2, "called with unexpected number of arguments");
 | 
			
		||||
 | 
			
		||||
            let regex_s = try!(ctx.get::<String>(0));
 | 
			
		||||
            let regex_s = ctx.get::<String>(0)?;
 | 
			
		||||
            let entry = cached_regexes.entry(regex_s.clone());
 | 
			
		||||
            let regex = {
 | 
			
		||||
                use std::collections::hash_map::Entry::{Occupied, Vacant};
 | 
			
		||||
@@ -620,7 +620,7 @@ mod test {
 | 
			
		||||
                }
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            let text = try!(ctx.get::<String>(1));
 | 
			
		||||
            let text = ctx.get::<String>(1)?;
 | 
			
		||||
            Ok(regex.is_match(&text))
 | 
			
		||||
        })
 | 
			
		||||
        .unwrap();
 | 
			
		||||
@@ -648,7 +648,7 @@ mod test {
 | 
			
		||||
            let mut ret = String::new();
 | 
			
		||||
 | 
			
		||||
            for idx in 0..ctx.len() {
 | 
			
		||||
                let s = try!(ctx.get::<String>(idx));
 | 
			
		||||
                let s = ctx.get::<String>(idx)?;
 | 
			
		||||
                ret.push_str(&s);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -675,7 +675,7 @@ mod test {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        fn step(&self, ctx: &mut Context, sum: &mut i64) -> Result<()> {
 | 
			
		||||
            *sum += try!(ctx.get::<i64>(0));
 | 
			
		||||
            *sum += ctx.get::<i64>(0)?;
 | 
			
		||||
            Ok(())
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										38
									
								
								src/lib.rs
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								src/lib.rs
									
									
									
									
									
								
							@@ -153,11 +153,11 @@ unsafe fn errmsg_to_string(errmsg: *const c_char) -> String {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn str_to_cstring(s: &str) -> Result<CString> {
 | 
			
		||||
    Ok(try!(CString::new(s)))
 | 
			
		||||
    Ok(CString::new(s)?)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fn path_to_cstring(p: &Path) -> Result<CString> {
 | 
			
		||||
    let s = try!(p.to_str().ok_or_else(|| Error::InvalidPath(p.to_owned())));
 | 
			
		||||
    let s = p.to_str().ok_or_else(|| Error::InvalidPath(p.to_owned()))?;
 | 
			
		||||
    str_to_cstring(s)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -240,7 +240,7 @@ impl Connection {
 | 
			
		||||
    /// Will return `Err` if `path` cannot be converted to a C-compatible
 | 
			
		||||
    /// string or if the underlying SQLite open call fails.
 | 
			
		||||
    pub fn open_with_flags<P: AsRef<Path>>(path: P, flags: OpenFlags) -> Result<Connection> {
 | 
			
		||||
        let c_path = try!(path_to_cstring(path.as_ref()));
 | 
			
		||||
        let c_path = path_to_cstring(path.as_ref())?;
 | 
			
		||||
        InnerConnection::open_with_flags(&c_path, flags).map(|db| Connection {
 | 
			
		||||
            db: RefCell::new(db),
 | 
			
		||||
            cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
 | 
			
		||||
@@ -257,7 +257,7 @@ impl Connection {
 | 
			
		||||
    ///
 | 
			
		||||
    /// Will return `Err` if the underlying SQLite open call fails.
 | 
			
		||||
    pub fn open_in_memory_with_flags(flags: OpenFlags) -> Result<Connection> {
 | 
			
		||||
        let c_memory = try!(str_to_cstring(":memory:"));
 | 
			
		||||
        let c_memory = str_to_cstring(":memory:")?;
 | 
			
		||||
        InnerConnection::open_with_flags(&c_memory, flags).map(|db| Connection {
 | 
			
		||||
            db: RefCell::new(db),
 | 
			
		||||
            cache: StatementCache::with_capacity(STATEMENT_CACHE_DEFAULT_CAPACITY),
 | 
			
		||||
@@ -385,7 +385,7 @@ impl Connection {
 | 
			
		||||
        P::Item: ToSql,
 | 
			
		||||
        F: FnOnce(&Row) -> T,
 | 
			
		||||
    {
 | 
			
		||||
        let mut stmt = try!(self.prepare(sql));
 | 
			
		||||
        let mut stmt = self.prepare(sql)?;
 | 
			
		||||
        stmt.query_row(params, f)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -403,8 +403,8 @@ impl Connection {
 | 
			
		||||
    where
 | 
			
		||||
        F: FnOnce(&Row) -> T,
 | 
			
		||||
    {
 | 
			
		||||
        let mut stmt = try!(self.prepare(sql));
 | 
			
		||||
        let mut rows = try!(stmt.query_named(params));
 | 
			
		||||
        let mut stmt = self.prepare(sql)?;
 | 
			
		||||
        let mut rows = stmt.query_named(params)?;
 | 
			
		||||
 | 
			
		||||
        rows.get_expected_row().map(|r| f(&r))
 | 
			
		||||
    }
 | 
			
		||||
@@ -441,8 +441,8 @@ impl Connection {
 | 
			
		||||
        F: FnOnce(&Row) -> result::Result<T, E>,
 | 
			
		||||
        E: convert::From<Error>,
 | 
			
		||||
    {
 | 
			
		||||
        let mut stmt = try!(self.prepare(sql));
 | 
			
		||||
        let mut rows = try!(stmt.query(params));
 | 
			
		||||
        let mut stmt = self.prepare(sql)?;
 | 
			
		||||
        let mut rows = stmt.query(params)?;
 | 
			
		||||
 | 
			
		||||
        rows.get_expected_row().map_err(E::from).and_then(|r| f(&r))
 | 
			
		||||
    }
 | 
			
		||||
@@ -454,9 +454,9 @@ impl Connection {
 | 
			
		||||
    /// ```rust,no_run
 | 
			
		||||
    /// # use rusqlite::{Connection, Result};
 | 
			
		||||
    /// fn insert_new_people(conn: &Connection) -> Result<()> {
 | 
			
		||||
    ///     let mut stmt = try!(conn.prepare("INSERT INTO People (name) VALUES (?)"));
 | 
			
		||||
    ///     try!(stmt.execute(&["Joe Smith"]));
 | 
			
		||||
    ///     try!(stmt.execute(&["Bob Jones"]));
 | 
			
		||||
    ///     let mut stmt = conn.prepare("INSERT INTO People (name) VALUES (?)")?;
 | 
			
		||||
    ///     stmt.execute(&["Joe Smith"])?;
 | 
			
		||||
    ///     stmt.execute(&["Bob Jones"])?;
 | 
			
		||||
    ///     Ok(())
 | 
			
		||||
    /// }
 | 
			
		||||
    /// ```
 | 
			
		||||
@@ -493,8 +493,8 @@ impl Connection {
 | 
			
		||||
    /// # use rusqlite::{Connection, Result};
 | 
			
		||||
    /// # use std::path::{Path};
 | 
			
		||||
    /// fn load_my_extension(conn: &Connection) -> Result<()> {
 | 
			
		||||
    ///     try!(conn.load_extension_enable());
 | 
			
		||||
    ///     try!(conn.load_extension(Path::new("my_sqlite_extension"), None));
 | 
			
		||||
    ///     conn.load_extension_enable()?;
 | 
			
		||||
    ///     conn.load_extension(Path::new("my_sqlite_extension"), None)?;
 | 
			
		||||
    ///     conn.load_extension_disable()
 | 
			
		||||
    /// }
 | 
			
		||||
    /// ```
 | 
			
		||||
@@ -533,7 +533,7 @@ impl Connection {
 | 
			
		||||
    /// # use rusqlite::{Connection, Result, LoadExtensionGuard};
 | 
			
		||||
    /// # use std::path::{Path};
 | 
			
		||||
    /// fn load_my_extension(conn: &Connection) -> Result<()> {
 | 
			
		||||
    ///     let _guard = try!(LoadExtensionGuard::new(conn));
 | 
			
		||||
    ///     let _guard = LoadExtensionGuard::new(conn)?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     conn.load_extension("my_sqlite_extension", None)
 | 
			
		||||
    /// }
 | 
			
		||||
@@ -902,7 +902,7 @@ impl InnerConnection {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn execute_batch(&mut self, sql: &str) -> Result<()> {
 | 
			
		||||
        let c_sql = try!(str_to_cstring(sql));
 | 
			
		||||
        let c_sql = str_to_cstring(sql)?;
 | 
			
		||||
        unsafe {
 | 
			
		||||
            let r = ffi::sqlite3_exec(
 | 
			
		||||
                self.db(),
 | 
			
		||||
@@ -923,11 +923,11 @@ impl InnerConnection {
 | 
			
		||||
 | 
			
		||||
    #[cfg(feature = "load_extension")]
 | 
			
		||||
    fn load_extension(&self, dylib_path: &Path, entry_point: Option<&str>) -> Result<()> {
 | 
			
		||||
        let dylib_str = try!(path_to_cstring(dylib_path));
 | 
			
		||||
        let dylib_str = path_to_cstring(dylib_path)?;
 | 
			
		||||
        unsafe {
 | 
			
		||||
            let mut errmsg: *mut c_char = mem::uninitialized();
 | 
			
		||||
            let r = if let Some(entry_point) = entry_point {
 | 
			
		||||
                let c_entry = try!(str_to_cstring(entry_point));
 | 
			
		||||
                let c_entry = str_to_cstring(entry_point)?;
 | 
			
		||||
                ffi::sqlite3_load_extension(
 | 
			
		||||
                    self.db,
 | 
			
		||||
                    dylib_str.as_ptr(),
 | 
			
		||||
@@ -956,7 +956,7 @@ impl InnerConnection {
 | 
			
		||||
            return Err(error_from_sqlite_code(ffi::SQLITE_TOOBIG, None));
 | 
			
		||||
        }
 | 
			
		||||
        let mut c_stmt: *mut ffi::sqlite3_stmt = unsafe { mem::uninitialized() };
 | 
			
		||||
        let c_sql = try!(str_to_cstring(sql));
 | 
			
		||||
        let c_sql = str_to_cstring(sql)?;
 | 
			
		||||
        let len_with_nul = (sql.len() + 1) as c_int;
 | 
			
		||||
        let r = unsafe {
 | 
			
		||||
            if cfg!(feature = "unlock_notify") {
 | 
			
		||||
 
 | 
			
		||||
@@ -8,7 +8,7 @@ use {Connection, Result};
 | 
			
		||||
/// # use rusqlite::{Connection, Result, LoadExtensionGuard};
 | 
			
		||||
/// # use std::path::{Path};
 | 
			
		||||
/// fn load_my_extension(conn: &Connection) -> Result<()> {
 | 
			
		||||
///     let _guard = try!(LoadExtensionGuard::new(conn));
 | 
			
		||||
///     let _guard = LoadExtensionGuard::new(conn)?;
 | 
			
		||||
///
 | 
			
		||||
///     conn.load_extension(Path::new("my_sqlite_extension"), None)
 | 
			
		||||
/// }
 | 
			
		||||
 
 | 
			
		||||
@@ -165,7 +165,7 @@ impl<'a, 'stmt> Row<'a, 'stmt> {
 | 
			
		||||
    /// enabled), and the underlying SQLite column is a blob whose size is not
 | 
			
		||||
    /// 16 bytes, `Error::InvalidColumnType` will also be returned.
 | 
			
		||||
    pub fn get_checked<I: RowIndex, T: FromSql>(&self, idx: I) -> Result<T> {
 | 
			
		||||
        let idx = try!(idx.idx(self.stmt));
 | 
			
		||||
        let idx = idx.idx(self.stmt)?;
 | 
			
		||||
        let value = self.stmt.value_ref(idx);
 | 
			
		||||
        FromSql::column_result(value).map_err(|err| match err {
 | 
			
		||||
            FromSqlError::InvalidType => Error::InvalidColumnType(idx, value.data_type()),
 | 
			
		||||
 
 | 
			
		||||
@@ -70,10 +70,10 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    /// ```rust,no_run
 | 
			
		||||
    /// # use rusqlite::{Connection, Result};
 | 
			
		||||
    /// fn update_rows(conn: &Connection) -> Result<()> {
 | 
			
		||||
    ///     let mut stmt = try!(conn.prepare("UPDATE foo SET bar = 'baz' WHERE qux = ?"));
 | 
			
		||||
    ///     let mut stmt = conn.prepare("UPDATE foo SET bar = 'baz' WHERE qux = ?")?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     try!(stmt.execute(&[1i32]));
 | 
			
		||||
    ///     try!(stmt.execute(&[2i32]));
 | 
			
		||||
    ///     stmt.execute(&[1i32])?;
 | 
			
		||||
    ///     stmt.execute(&[2i32])?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     Ok(())
 | 
			
		||||
    /// }
 | 
			
		||||
@@ -89,7 +89,7 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
        P: IntoIterator,
 | 
			
		||||
        P::Item: ToSql,
 | 
			
		||||
    {
 | 
			
		||||
        try!(self.bind_parameters(params));
 | 
			
		||||
        self.bind_parameters(params)?;
 | 
			
		||||
        self.execute_with_bound_parameters()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -107,7 +107,7 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    /// ```rust,no_run
 | 
			
		||||
    /// # use rusqlite::{Connection, Result};
 | 
			
		||||
    /// fn insert(conn: &Connection) -> Result<usize> {
 | 
			
		||||
    ///     let mut stmt = try!(conn.prepare("INSERT INTO test (name) VALUES (:name)"));
 | 
			
		||||
    ///     let mut stmt = conn.prepare("INSERT INTO test (name) VALUES (:name)")?;
 | 
			
		||||
    ///     stmt.execute_named(&[(":name", &"one")])
 | 
			
		||||
    /// }
 | 
			
		||||
    /// ```
 | 
			
		||||
@@ -118,7 +118,7 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    /// returns rows (in which case `query` should be used instead), or the
 | 
			
		||||
    /// underling SQLite call fails.
 | 
			
		||||
    pub fn execute_named(&mut self, params: &[(&str, &ToSql)]) -> Result<usize> {
 | 
			
		||||
        try!(self.bind_parameters_named(params));
 | 
			
		||||
        self.bind_parameters_named(params)?;
 | 
			
		||||
        self.execute_with_bound_parameters()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -140,7 +140,7 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
        P: IntoIterator,
 | 
			
		||||
        P::Item: ToSql,
 | 
			
		||||
    {
 | 
			
		||||
        let changes = try!(self.execute(params));
 | 
			
		||||
        let changes = self.execute(params)?;
 | 
			
		||||
        match changes {
 | 
			
		||||
            1 => Ok(self.conn.last_insert_rowid()),
 | 
			
		||||
            _ => Err(Error::StatementChangedRows(changes)),
 | 
			
		||||
@@ -159,12 +159,12 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    /// ```rust,no_run
 | 
			
		||||
    /// # use rusqlite::{Connection, Result, NO_PARAMS};
 | 
			
		||||
    /// fn get_names(conn: &Connection) -> Result<Vec<String>> {
 | 
			
		||||
    ///     let mut stmt = try!(conn.prepare("SELECT name FROM people"));
 | 
			
		||||
    ///     let mut rows = try!(stmt.query(NO_PARAMS));
 | 
			
		||||
    ///     let mut stmt = conn.prepare("SELECT name FROM people")?;
 | 
			
		||||
    ///     let mut rows = stmt.query(NO_PARAMS)?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     let mut names = Vec::new();
 | 
			
		||||
    ///     while let Some(result_row) = rows.next() {
 | 
			
		||||
    ///         let row = try!(result_row);
 | 
			
		||||
    ///         let row = result_row?;
 | 
			
		||||
    ///         names.push(row.get(0));
 | 
			
		||||
    ///     }
 | 
			
		||||
    ///
 | 
			
		||||
@@ -180,8 +180,8 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
        P: IntoIterator,
 | 
			
		||||
        P::Item: ToSql,
 | 
			
		||||
    {
 | 
			
		||||
        try!(self.check_readonly());
 | 
			
		||||
        try!(self.bind_parameters(params));
 | 
			
		||||
        self.check_readonly()?;
 | 
			
		||||
        self.bind_parameters(params)?;
 | 
			
		||||
        Ok(Rows::new(self))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -196,8 +196,8 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    /// ```rust,no_run
 | 
			
		||||
    /// # use rusqlite::{Connection, Result};
 | 
			
		||||
    /// fn query(conn: &Connection) -> Result<()> {
 | 
			
		||||
    ///     let mut stmt = try!(conn.prepare("SELECT * FROM test where name = :name"));
 | 
			
		||||
    ///     let mut rows = try!(stmt.query_named(&[(":name", &"one")]));
 | 
			
		||||
    ///     let mut stmt = conn.prepare("SELECT * FROM test where name = :name")?;
 | 
			
		||||
    ///     let mut rows = stmt.query_named(&[(":name", &"one")])?;
 | 
			
		||||
    ///     while let Some(row) = rows.next() {
 | 
			
		||||
    ///         // ...
 | 
			
		||||
    ///     }
 | 
			
		||||
@@ -209,8 +209,8 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    ///
 | 
			
		||||
    /// Will return `Err` if binding parameters fails.
 | 
			
		||||
    pub fn query_named<'a>(&'a mut self, params: &[(&str, &ToSql)]) -> Result<Rows<'a>> {
 | 
			
		||||
        try!(self.check_readonly());
 | 
			
		||||
        try!(self.bind_parameters_named(params));
 | 
			
		||||
        self.check_readonly()?;
 | 
			
		||||
        self.bind_parameters_named(params)?;
 | 
			
		||||
        Ok(Rows::new(self))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -222,12 +222,12 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    /// ```rust,no_run
 | 
			
		||||
    /// # use rusqlite::{Connection, Result, NO_PARAMS};
 | 
			
		||||
    /// fn get_names(conn: &Connection) -> Result<Vec<String>> {
 | 
			
		||||
    ///     let mut stmt = try!(conn.prepare("SELECT name FROM people"));
 | 
			
		||||
    ///     let rows = try!(stmt.query_map(NO_PARAMS, |row| row.get(0)));
 | 
			
		||||
    ///     let mut stmt = conn.prepare("SELECT name FROM people")?;
 | 
			
		||||
    ///     let rows = stmt.query_map(NO_PARAMS, |row| row.get(0))?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     let mut names = Vec::new();
 | 
			
		||||
    ///     for name_result in rows {
 | 
			
		||||
    ///         names.push(try!(name_result));
 | 
			
		||||
    ///         names.push(name_result?);
 | 
			
		||||
    ///     }
 | 
			
		||||
    ///
 | 
			
		||||
    ///     Ok(names)
 | 
			
		||||
@@ -259,12 +259,12 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    /// ```rust,no_run
 | 
			
		||||
    /// # use rusqlite::{Connection, Result};
 | 
			
		||||
    /// fn get_names(conn: &Connection) -> Result<Vec<String>> {
 | 
			
		||||
    ///     let mut stmt = try!(conn.prepare("SELECT name FROM people WHERE id = :id"));
 | 
			
		||||
    ///     let rows = try!(stmt.query_map_named(&[(":id", &"one")], |row| row.get(0)));
 | 
			
		||||
    ///     let mut stmt = conn.prepare("SELECT name FROM people WHERE id = :id")?;
 | 
			
		||||
    ///     let rows = stmt.query_map_named(&[(":id", &"one")], |row| row.get(0))?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     let mut names = Vec::new();
 | 
			
		||||
    ///     for name_result in rows {
 | 
			
		||||
    ///         names.push(try!(name_result));
 | 
			
		||||
    ///         names.push(name_result?);
 | 
			
		||||
    ///     }
 | 
			
		||||
    ///
 | 
			
		||||
    ///     Ok(names)
 | 
			
		||||
@@ -330,13 +330,13 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    /// }
 | 
			
		||||
    ///
 | 
			
		||||
    /// fn get_names(conn: &Connection) -> Result<Vec<Person>> {
 | 
			
		||||
    ///     let mut stmt = try!(conn.prepare("SELECT name FROM people WHERE id = :id"));
 | 
			
		||||
    ///     let mut stmt = conn.prepare("SELECT name FROM people WHERE id = :id")?;
 | 
			
		||||
    ///     let rows =
 | 
			
		||||
    ///         try!(stmt.query_and_then_named(&[(":id", &"one")], |row| name_to_person(row.get(0))));
 | 
			
		||||
    ///         stmt.query_and_then_named(&[(":id", &"one")], |row| name_to_person(row.get(0)))?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     let mut persons = Vec::new();
 | 
			
		||||
    ///     for person_result in rows {
 | 
			
		||||
    ///         persons.push(try!(person_result));
 | 
			
		||||
    ///         persons.push(person_result?);
 | 
			
		||||
    ///     }
 | 
			
		||||
    ///
 | 
			
		||||
    ///     Ok(persons)
 | 
			
		||||
@@ -366,7 +366,7 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
        P: IntoIterator,
 | 
			
		||||
        P::Item: ToSql,
 | 
			
		||||
    {
 | 
			
		||||
        let mut rows = try!(self.query(params));
 | 
			
		||||
        let mut rows = self.query(params)?;
 | 
			
		||||
        let exists = rows.next().is_some();
 | 
			
		||||
        Ok(exists)
 | 
			
		||||
    }
 | 
			
		||||
@@ -386,7 +386,7 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
        P::Item: ToSql,
 | 
			
		||||
        F: FnOnce(&Row) -> T,
 | 
			
		||||
    {
 | 
			
		||||
        let mut rows = try!(self.query(params));
 | 
			
		||||
        let mut rows = self.query(params)?;
 | 
			
		||||
 | 
			
		||||
        rows.get_expected_row().map(|r| f(&r))
 | 
			
		||||
    }
 | 
			
		||||
@@ -410,7 +410,7 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    /// Will return Err if `name` is invalid. Will return Ok(None) if the name
 | 
			
		||||
    /// is valid but not a bound parameter of this statement.
 | 
			
		||||
    pub fn parameter_index(&self, name: &str) -> Result<Option<usize>> {
 | 
			
		||||
        let c_name = try!(str_to_cstring(name));
 | 
			
		||||
        let c_name = str_to_cstring(name)?;
 | 
			
		||||
        Ok(self.stmt.bind_parameter_index(&c_name))
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -426,7 +426,7 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
            if index > expected {
 | 
			
		||||
                break;
 | 
			
		||||
            }
 | 
			
		||||
            try!(self.bind_parameter(&p, index));
 | 
			
		||||
            self.bind_parameter(&p, index)?;
 | 
			
		||||
        }
 | 
			
		||||
        assert_eq!(
 | 
			
		||||
            index, expected,
 | 
			
		||||
@@ -439,8 +439,8 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
 | 
			
		||||
    fn bind_parameters_named(&mut self, params: &[(&str, &ToSql)]) -> Result<()> {
 | 
			
		||||
        for &(name, value) in params {
 | 
			
		||||
            if let Some(i) = try!(self.parameter_index(name)) {
 | 
			
		||||
                try!(self.bind_parameter(value, i));
 | 
			
		||||
            if let Some(i) = self.parameter_index(name)? {
 | 
			
		||||
                self.bind_parameter(value, i)?;
 | 
			
		||||
            } else {
 | 
			
		||||
                return Err(Error::InvalidParameterName(name.into()));
 | 
			
		||||
            }
 | 
			
		||||
@@ -449,7 +449,7 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn bind_parameter(&self, param: &ToSql, col: usize) -> Result<()> {
 | 
			
		||||
        let value = try!(param.to_sql());
 | 
			
		||||
        let value = param.to_sql()?;
 | 
			
		||||
 | 
			
		||||
        let ptr = unsafe { self.stmt.ptr() };
 | 
			
		||||
        let value = match value {
 | 
			
		||||
@@ -484,7 +484,7 @@ impl<'conn> Statement<'conn> {
 | 
			
		||||
                if length > ::std::i32::MAX as usize {
 | 
			
		||||
                    ffi::SQLITE_TOOBIG
 | 
			
		||||
                } else {
 | 
			
		||||
                    let c_str = try!(str_to_cstring(s));
 | 
			
		||||
                    let c_str = str_to_cstring(s)?;
 | 
			
		||||
                    let destructor = if length > 0 {
 | 
			
		||||
                        ffi::SQLITE_TRANSIENT()
 | 
			
		||||
                    } else {
 | 
			
		||||
 
 | 
			
		||||
@@ -42,10 +42,10 @@ pub enum DropBehavior {
 | 
			
		||||
/// # fn do_queries_part_1(_conn: &Connection) -> Result<()> { Ok(()) }
 | 
			
		||||
/// # fn do_queries_part_2(_conn: &Connection) -> Result<()> { Ok(()) }
 | 
			
		||||
/// fn perform_queries(conn: &mut Connection) -> Result<()> {
 | 
			
		||||
///     let tx = try!(conn.transaction());
 | 
			
		||||
///     let tx = conn.transaction()?;
 | 
			
		||||
///
 | 
			
		||||
///     try!(do_queries_part_1(&tx)); // tx causes rollback if this fails
 | 
			
		||||
///     try!(do_queries_part_2(&tx)); // tx causes rollback if this fails
 | 
			
		||||
///     do_queries_part_1(&tx)?; // tx causes rollback if this fails
 | 
			
		||||
///     do_queries_part_2(&tx)?; // tx causes rollback if this fails
 | 
			
		||||
///
 | 
			
		||||
///     tx.commit()
 | 
			
		||||
/// }
 | 
			
		||||
@@ -70,10 +70,10 @@ pub struct Transaction<'conn> {
 | 
			
		||||
/// # fn do_queries_part_1(_conn: &Connection) -> Result<()> { Ok(()) }
 | 
			
		||||
/// # fn do_queries_part_2(_conn: &Connection) -> Result<()> { Ok(()) }
 | 
			
		||||
/// fn perform_queries(conn: &mut Connection) -> Result<()> {
 | 
			
		||||
///     let sp = try!(conn.savepoint());
 | 
			
		||||
///     let sp = conn.savepoint()?;
 | 
			
		||||
///
 | 
			
		||||
///     try!(do_queries_part_1(&sp)); // sp causes rollback if this fails
 | 
			
		||||
///     try!(do_queries_part_2(&sp)); // sp causes rollback if this fails
 | 
			
		||||
///     do_queries_part_1(&sp)?; // sp causes rollback if this fails
 | 
			
		||||
///     do_queries_part_2(&sp)?; // sp causes rollback if this fails
 | 
			
		||||
///
 | 
			
		||||
///     sp.commit()
 | 
			
		||||
/// }
 | 
			
		||||
@@ -118,12 +118,12 @@ impl<'conn> Transaction<'conn> {
 | 
			
		||||
    /// # use rusqlite::{Connection, Result};
 | 
			
		||||
    /// # fn perform_queries_part_1_succeeds(_conn: &Connection) -> bool { true }
 | 
			
		||||
    /// fn perform_queries(conn: &mut Connection) -> Result<()> {
 | 
			
		||||
    ///     let mut tx = try!(conn.transaction());
 | 
			
		||||
    ///     let mut tx = conn.transaction()?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     {
 | 
			
		||||
    ///         let sp = try!(tx.savepoint());
 | 
			
		||||
    ///         let sp = tx.savepoint()?;
 | 
			
		||||
    ///         if perform_queries_part_1_succeeds(&sp) {
 | 
			
		||||
    ///             try!(sp.commit());
 | 
			
		||||
    ///             sp.commit()?;
 | 
			
		||||
    ///         }
 | 
			
		||||
    ///         // otherwise, sp will rollback
 | 
			
		||||
    ///     }
 | 
			
		||||
@@ -336,10 +336,10 @@ impl Connection {
 | 
			
		||||
    /// # fn do_queries_part_1(_conn: &Connection) -> Result<()> { Ok(()) }
 | 
			
		||||
    /// # fn do_queries_part_2(_conn: &Connection) -> Result<()> { Ok(()) }
 | 
			
		||||
    /// fn perform_queries(conn: &mut Connection) -> Result<()> {
 | 
			
		||||
    ///     let tx = try!(conn.transaction());
 | 
			
		||||
    ///     let tx = conn.transaction()?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     try!(do_queries_part_1(&tx)); // tx causes rollback if this fails
 | 
			
		||||
    ///     try!(do_queries_part_2(&tx)); // tx causes rollback if this fails
 | 
			
		||||
    ///     do_queries_part_1(&tx)?; // tx causes rollback if this fails
 | 
			
		||||
    ///     do_queries_part_2(&tx)?; // tx causes rollback if this fails
 | 
			
		||||
    ///
 | 
			
		||||
    ///     tx.commit()
 | 
			
		||||
    /// }
 | 
			
		||||
@@ -379,10 +379,10 @@ impl Connection {
 | 
			
		||||
    /// # fn do_queries_part_1(_conn: &Connection) -> Result<()> { Ok(()) }
 | 
			
		||||
    /// # fn do_queries_part_2(_conn: &Connection) -> Result<()> { Ok(()) }
 | 
			
		||||
    /// fn perform_queries(conn: &mut Connection) -> Result<()> {
 | 
			
		||||
    ///     let sp = try!(conn.savepoint());
 | 
			
		||||
    ///     let sp = conn.savepoint()?;
 | 
			
		||||
    ///
 | 
			
		||||
    ///     try!(do_queries_part_1(&sp)); // sp causes rollback if this fails
 | 
			
		||||
    ///     try!(do_queries_part_2(&sp)); // sp causes rollback if this fails
 | 
			
		||||
    ///     do_queries_part_1(&sp)?; // sp causes rollback if this fails
 | 
			
		||||
    ///     do_queries_part_2(&sp)?; // sp causes rollback if this fails
 | 
			
		||||
    ///
 | 
			
		||||
    ///     sp.commit()
 | 
			
		||||
    /// }
 | 
			
		||||
 
 | 
			
		||||
@@ -95,7 +95,7 @@ impl FromSql for DateTime<Utc> {
 | 
			
		||||
    fn column_result(value: ValueRef) -> FromSqlResult<Self> {
 | 
			
		||||
        {
 | 
			
		||||
            // Try to parse value as rfc3339 first.
 | 
			
		||||
            let s = try!(value.as_str());
 | 
			
		||||
            let s = value.as_str()?;
 | 
			
		||||
 | 
			
		||||
            // If timestamp looks space-separated, make a copy and replace it with 'T'.
 | 
			
		||||
            let s = if s.len() >= 11 && s.as_bytes()[10] == b' ' {
 | 
			
		||||
@@ -122,7 +122,7 @@ impl FromSql for DateTime<Utc> {
 | 
			
		||||
/// RFC3339 ("YYYY-MM-DDTHH:MM:SS.SSS[+-]HH:MM") into `DateTime<Local>`.
 | 
			
		||||
impl FromSql for DateTime<Local> {
 | 
			
		||||
    fn column_result(value: ValueRef) -> FromSqlResult<Self> {
 | 
			
		||||
        let utc_dt = try!(DateTime::<Utc>::column_result(value));
 | 
			
		||||
        let utc_dt = DateTime::<Utc>::column_result(value)?;
 | 
			
		||||
        Ok(utc_dt.with_timezone(&Local))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -131,7 +131,7 @@ impl ArrayTabCursor {
 | 
			
		||||
impl VTabCursor for ArrayTabCursor {
 | 
			
		||||
    fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values) -> Result<()> {
 | 
			
		||||
        if idx_num > 0 {
 | 
			
		||||
            self.ptr = try!(args.get_array(0));
 | 
			
		||||
            self.ptr = args.get_array(0)?;
 | 
			
		||||
        } else {
 | 
			
		||||
            self.ptr = None;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -60,7 +60,7 @@ impl CSVTab {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn parameter(c_slice: &[u8]) -> Result<(&str, &str)> {
 | 
			
		||||
        let arg = try!(str::from_utf8(c_slice)).trim();
 | 
			
		||||
        let arg = str::from_utf8(c_slice)?.trim();
 | 
			
		||||
        let mut split = arg.split('=');
 | 
			
		||||
        if let Some(key) = split.next() {
 | 
			
		||||
            if let Some(value) = split.next() {
 | 
			
		||||
@@ -107,7 +107,7 @@ impl VTab for CSVTab {
 | 
			
		||||
 | 
			
		||||
        let args = &args[3..];
 | 
			
		||||
        for c_slice in args {
 | 
			
		||||
            let (param, value) = try!(CSVTab::parameter(c_slice));
 | 
			
		||||
            let (param, value) = CSVTab::parameter(c_slice)?;
 | 
			
		||||
            match param {
 | 
			
		||||
                "filename" => {
 | 
			
		||||
                    if !Path::new(value).exists() {
 | 
			
		||||
@@ -189,10 +189,10 @@ impl VTab for CSVTab {
 | 
			
		||||
 | 
			
		||||
        let mut cols: Vec<String> = Vec::new();
 | 
			
		||||
        if vtab.has_headers || (n_col.is_none() && schema.is_none()) {
 | 
			
		||||
            let mut reader = try!(vtab.reader());
 | 
			
		||||
            let mut reader = vtab.reader()?;
 | 
			
		||||
            if vtab.has_headers {
 | 
			
		||||
                {
 | 
			
		||||
                    let headers = try!(reader.headers());
 | 
			
		||||
                    let headers = reader.headers()?;
 | 
			
		||||
                    // headers ignored if cols is not empty
 | 
			
		||||
                    if n_col.is_none() && schema.is_none() {
 | 
			
		||||
                        cols = headers
 | 
			
		||||
@@ -204,7 +204,7 @@ impl VTab for CSVTab {
 | 
			
		||||
                vtab.offset_first_row = reader.position().clone();
 | 
			
		||||
            } else {
 | 
			
		||||
                let mut record = csv::ByteRecord::new();
 | 
			
		||||
                if try!(reader.read_byte_record(&mut record)) {
 | 
			
		||||
                if reader.read_byte_record(&mut record)? {
 | 
			
		||||
                    for (i, _) in record.iter().enumerate() {
 | 
			
		||||
                        cols.push(format!("c{}", i));
 | 
			
		||||
                    }
 | 
			
		||||
@@ -245,7 +245,7 @@ impl VTab for CSVTab {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fn open(&self) -> Result<CSVTabCursor> {
 | 
			
		||||
        Ok(CSVTabCursor::new(try!(self.reader())))
 | 
			
		||||
        Ok(CSVTabCursor::new(self.reader()?))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -288,7 +288,7 @@ impl VTabCursor for CSVTabCursor {
 | 
			
		||||
    fn filter(&mut self, _idx_num: c_int, _idx_str: Option<&str>, _args: &Values) -> Result<()> {
 | 
			
		||||
        {
 | 
			
		||||
            let offset_first_row = self.vtab().offset_first_row.clone();
 | 
			
		||||
            try!(self.reader.seek(offset_first_row));
 | 
			
		||||
            self.reader.seek(offset_first_row)?;
 | 
			
		||||
        }
 | 
			
		||||
        self.row_number = 0;
 | 
			
		||||
        self.next()
 | 
			
		||||
@@ -301,7 +301,7 @@ impl VTabCursor for CSVTabCursor {
 | 
			
		||||
                return Ok(());
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            self.eof = !try!(self.reader.read_record(&mut self.cols));
 | 
			
		||||
            self.eof = !self.reader.read_record(&mut self.cols)?;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        self.row_number += 1;
 | 
			
		||||
 
 | 
			
		||||
@@ -546,7 +546,7 @@ impl InnerConnection {
 | 
			
		||||
        module: &Module<T>,
 | 
			
		||||
        aux: Option<T::Aux>,
 | 
			
		||||
    ) -> Result<()> {
 | 
			
		||||
        let c_name = try!(str_to_cstring(module_name));
 | 
			
		||||
        let c_name = str_to_cstring(module_name)?;
 | 
			
		||||
        let r = match aux {
 | 
			
		||||
            Some(aux) => {
 | 
			
		||||
                let boxed_aux: *mut T::Aux = Box::into_raw(Box::new(aux));
 | 
			
		||||
 
 | 
			
		||||
@@ -188,19 +188,19 @@ impl VTabCursor for SeriesTabCursor {
 | 
			
		||||
        let idx_num = QueryPlanFlags::from_bits_truncate(idx_num);
 | 
			
		||||
        let mut i = 0;
 | 
			
		||||
        if idx_num.contains(QueryPlanFlags::START) {
 | 
			
		||||
            self.min_value = try!(args.get(i));
 | 
			
		||||
            self.min_value = args.get(i)?;
 | 
			
		||||
            i += 1;
 | 
			
		||||
        } else {
 | 
			
		||||
            self.min_value = 0;
 | 
			
		||||
        }
 | 
			
		||||
        if idx_num.contains(QueryPlanFlags::STOP) {
 | 
			
		||||
            self.max_value = try!(args.get(i));
 | 
			
		||||
            self.max_value = args.get(i)?;
 | 
			
		||||
            i += 1;
 | 
			
		||||
        } else {
 | 
			
		||||
            self.max_value = 0xffff_ffff;
 | 
			
		||||
        }
 | 
			
		||||
        if idx_num.contains(QueryPlanFlags::STEP) {
 | 
			
		||||
            self.step = try!(args.get(i));
 | 
			
		||||
            self.step = args.get(i)?;
 | 
			
		||||
            if self.step < 1 {
 | 
			
		||||
                self.step = 1;
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user