mirror of
https://github.com/isar/rusqlite.git
synced 2024-11-23 00:39:20 +08:00
Introduce IndexConstraintUsage
This commit is contained in:
parent
b11a4b1c73
commit
58b7d62517
@ -95,21 +95,13 @@ impl IndexInfo {
|
||||
}
|
||||
|
||||
/// if `argv_index` > 0, constraint is part of argv to xFilter
|
||||
pub fn set_argv_index(&mut self, constraint_idx: usize, argv_index: libc::c_int) {
|
||||
unsafe {
|
||||
let mut constraint_usages = slice::from_raw_parts_mut((*self.0).aConstraintUsage,
|
||||
(*self.0).nConstraint as usize);
|
||||
constraint_usages[constraint_idx].argvIndex = argv_index;
|
||||
}
|
||||
}
|
||||
/// if `omit`, do not code a test for this constraint
|
||||
pub fn set_omit(&mut self, constraint_idx: usize, omit: bool) {
|
||||
unsafe {
|
||||
let mut constraint_usages = slice::from_raw_parts_mut((*self.0).aConstraintUsage,
|
||||
(*self.0).nConstraint as usize);
|
||||
constraint_usages[constraint_idx].omit = if omit { 1 } else { 0 };
|
||||
}
|
||||
pub fn constraint_usage(&mut self, constraint_idx: usize) -> IndexConstraintUsage {
|
||||
let mut constraint_usages = unsafe {
|
||||
slice::from_raw_parts_mut((*self.0).aConstraintUsage, (*self.0).nConstraint as usize)
|
||||
};
|
||||
IndexConstraintUsage(&mut constraint_usages[constraint_idx])
|
||||
}
|
||||
|
||||
/// Number used to identify the index
|
||||
pub fn set_idx_num(&mut self, idx_num: libc::c_int) {
|
||||
unsafe {
|
||||
@ -168,6 +160,19 @@ impl<'a> IndexConstraint<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct IndexConstraintUsage<'a>(&'a mut ffi::Struct_sqlite3_index_constraint_usage);
|
||||
|
||||
impl<'a> IndexConstraintUsage<'a> {
|
||||
/// if `argv_index` > 0, constraint is part of argv to xFilter
|
||||
pub fn set_argv_index(&mut self, argv_index: libc::c_int) {
|
||||
self.0.argvIndex = argv_index;
|
||||
}
|
||||
/// if `omit`, do not code a test for this constraint
|
||||
pub fn set_omit(&mut self, omit: bool) {
|
||||
self.0.omit = if omit { 1 } else { 0 };
|
||||
}
|
||||
}
|
||||
|
||||
/// Virtual table cursor trait.
|
||||
pub trait VTabCursor<V: VTab<Self>>: Sized {
|
||||
/// Accessor to the associated virtual table.
|
||||
|
@ -108,18 +108,21 @@ impl VTab<SeriesTabCursor> for SeriesTab {
|
||||
let mut num_of_arg = 0;
|
||||
if let Some(start_idx) = start_idx {
|
||||
num_of_arg += 1;
|
||||
info.set_argv_index(start_idx, num_of_arg);
|
||||
info.set_omit(start_idx, true);
|
||||
let mut constraint_usage = info.constraint_usage(start_idx);
|
||||
constraint_usage.set_argv_index(num_of_arg);
|
||||
constraint_usage.set_omit(true);
|
||||
}
|
||||
if let Some(stop_idx) = stop_idx {
|
||||
num_of_arg += 1;
|
||||
info.set_argv_index(stop_idx, num_of_arg);
|
||||
info.set_omit(stop_idx, true);
|
||||
let mut constraint_usage = info.constraint_usage(stop_idx);
|
||||
constraint_usage.set_argv_index(num_of_arg);
|
||||
constraint_usage.set_omit(true);
|
||||
}
|
||||
if let Some(step_idx) = step_idx {
|
||||
num_of_arg += 1;
|
||||
info.set_argv_index(step_idx, num_of_arg);
|
||||
info.set_omit(step_idx, true);
|
||||
let mut constraint_usage = info.constraint_usage(step_idx);
|
||||
constraint_usage.set_argv_index(num_of_arg);
|
||||
constraint_usage.set_omit(true);
|
||||
}
|
||||
if idx_num.contains(BOTH) {
|
||||
// Both start= and stop= boundaries are available.
|
||||
|
Loading…
Reference in New Issue
Block a user