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