mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-25 02:21:37 +08:00
commit
dca3ceef92
@ -58,11 +58,7 @@ impl Connection {
|
||||
pub fn busy_handler(&self, callback: Option<fn(i32) -> bool>) -> Result<()> {
|
||||
unsafe extern "C" fn busy_handler_callback(p_arg: *mut c_void, count: c_int) -> c_int {
|
||||
let handler_fn: fn(i32) -> bool = mem::transmute(p_arg);
|
||||
if let Ok(true) = catch_unwind(|| handler_fn(count)) {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
c_int::from(catch_unwind(|| handler_fn(count)).unwrap_or_default())
|
||||
}
|
||||
let c = self.db.borrow_mut();
|
||||
let r = match callback {
|
||||
|
@ -33,7 +33,7 @@ impl Statement<'_> {
|
||||
/// calling this method.
|
||||
pub fn column_names(&self) -> Vec<&str> {
|
||||
let n = self.column_count();
|
||||
let mut cols = Vec::with_capacity(n as usize);
|
||||
let mut cols = Vec::with_capacity(n);
|
||||
for i in 0..n {
|
||||
let s = self.column_name_unwrap(i);
|
||||
cols.push(s);
|
||||
@ -95,6 +95,7 @@ impl Statement<'_> {
|
||||
pub fn column_name(&self, col: usize) -> Result<&str> {
|
||||
self.stmt
|
||||
.column_name(col)
|
||||
// clippy::or_fun_call (nightly) vs clippy::unnecessary-lazy-evaluations (stable)
|
||||
.ok_or(Error::InvalidColumnIndex(col))
|
||||
.map(|slice| {
|
||||
str::from_utf8(slice.to_bytes()).expect("Invalid UTF-8 sequence in column name")
|
||||
@ -137,7 +138,7 @@ impl Statement<'_> {
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "column_decltype")))]
|
||||
pub fn columns(&self) -> Vec<Column> {
|
||||
let n = self.column_count();
|
||||
let mut cols = Vec::with_capacity(n as usize);
|
||||
let mut cols = Vec::with_capacity(n);
|
||||
for i in 0..n {
|
||||
let name = self.column_name_unwrap(i);
|
||||
let slice = self.stmt.column_decltype(i);
|
||||
|
12
src/hooks.rs
12
src/hooks.rs
@ -426,11 +426,7 @@ impl InnerConnection {
|
||||
let boxed_hook: *mut F = p_arg.cast::<F>();
|
||||
(*boxed_hook)()
|
||||
});
|
||||
if let Ok(true) = r {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
c_int::from(r.unwrap_or_default())
|
||||
}
|
||||
|
||||
// unlike `sqlite3_create_function_v2`, we cannot specify a `xDestroy` with
|
||||
@ -568,11 +564,7 @@ impl InnerConnection {
|
||||
let boxed_handler: *mut F = p_arg.cast::<F>();
|
||||
(*boxed_handler)()
|
||||
});
|
||||
if let Ok(true) = r {
|
||||
1
|
||||
} else {
|
||||
0
|
||||
}
|
||||
c_int::from(r.unwrap_or_default())
|
||||
}
|
||||
|
||||
if let Some(handler) = handler {
|
||||
|
@ -71,55 +71,49 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn test_limit_values() {
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_LENGTH as i32,
|
||||
ffi::SQLITE_LIMIT_LENGTH as i32,
|
||||
);
|
||||
assert_eq!(Limit::SQLITE_LIMIT_LENGTH as i32, ffi::SQLITE_LIMIT_LENGTH,);
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_SQL_LENGTH as i32,
|
||||
ffi::SQLITE_LIMIT_SQL_LENGTH as i32,
|
||||
);
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_COLUMN as i32,
|
||||
ffi::SQLITE_LIMIT_COLUMN as i32,
|
||||
ffi::SQLITE_LIMIT_SQL_LENGTH,
|
||||
);
|
||||
assert_eq!(Limit::SQLITE_LIMIT_COLUMN as i32, ffi::SQLITE_LIMIT_COLUMN,);
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_EXPR_DEPTH as i32,
|
||||
ffi::SQLITE_LIMIT_EXPR_DEPTH as i32,
|
||||
ffi::SQLITE_LIMIT_EXPR_DEPTH,
|
||||
);
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_COMPOUND_SELECT as i32,
|
||||
ffi::SQLITE_LIMIT_COMPOUND_SELECT as i32,
|
||||
ffi::SQLITE_LIMIT_COMPOUND_SELECT,
|
||||
);
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_VDBE_OP as i32,
|
||||
ffi::SQLITE_LIMIT_VDBE_OP as i32,
|
||||
ffi::SQLITE_LIMIT_VDBE_OP,
|
||||
);
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_FUNCTION_ARG as i32,
|
||||
ffi::SQLITE_LIMIT_FUNCTION_ARG as i32,
|
||||
ffi::SQLITE_LIMIT_FUNCTION_ARG,
|
||||
);
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_ATTACHED as i32,
|
||||
ffi::SQLITE_LIMIT_ATTACHED as i32,
|
||||
ffi::SQLITE_LIMIT_ATTACHED,
|
||||
);
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_LIKE_PATTERN_LENGTH as i32,
|
||||
ffi::SQLITE_LIMIT_LIKE_PATTERN_LENGTH as i32,
|
||||
ffi::SQLITE_LIMIT_LIKE_PATTERN_LENGTH,
|
||||
);
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_VARIABLE_NUMBER as i32,
|
||||
ffi::SQLITE_LIMIT_VARIABLE_NUMBER as i32,
|
||||
ffi::SQLITE_LIMIT_VARIABLE_NUMBER,
|
||||
);
|
||||
#[cfg(feature = "bundled")]
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_TRIGGER_DEPTH as i32,
|
||||
ffi::SQLITE_LIMIT_TRIGGER_DEPTH as i32,
|
||||
ffi::SQLITE_LIMIT_TRIGGER_DEPTH,
|
||||
);
|
||||
#[cfg(feature = "bundled")]
|
||||
assert_eq!(
|
||||
Limit::SQLITE_LIMIT_WORKER_THREADS as i32,
|
||||
ffi::SQLITE_LIMIT_WORKER_THREADS as i32,
|
||||
ffi::SQLITE_LIMIT_WORKER_THREADS,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -115,6 +115,7 @@ unsafe impl<'vtab> VTab<'vtab> for SeriesTab {
|
||||
}
|
||||
if idx_num.contains(QueryPlanFlags::BOTH) {
|
||||
// Both start= and stop= boundaries are available.
|
||||
//#[allow(clippy::bool_to_int_with_if)]
|
||||
info.set_estimated_cost(f64::from(
|
||||
2 - if idx_num.contains(QueryPlanFlags::STEP) {
|
||||
1
|
||||
|
@ -163,7 +163,7 @@ impl<'vtab> UpdateVTab<'vtab> for VTabLog {
|
||||
self.i_inst,
|
||||
args.iter().collect::<Vec<ValueRef<'_>>>()
|
||||
);
|
||||
Ok(self.n_row as i64)
|
||||
Ok(self.n_row)
|
||||
}
|
||||
|
||||
fn update(&mut self, args: &Values<'_>) -> Result<()> {
|
||||
|
Loading…
Reference in New Issue
Block a user