Sync series with original impl

This commit is contained in:
gwenn 2018-05-13 19:49:11 +02:00
parent 88a7ed5812
commit b60ffe1940

View File

@ -4,6 +4,7 @@ use std::default::Default;
use std::os::raw::{c_char, c_int, c_void}; use std::os::raw::{c_char, c_int, c_void};
use ffi; use ffi;
use types::Type;
use vtab::{self, declare_vtab, Context, IndexInfo, VTab, VTabCursor, Values}; use vtab::{self, declare_vtab, Context, IndexInfo, VTab, VTabCursor, Values};
use {Connection, Error, Result}; use {Connection, Error, Result};
@ -130,13 +131,13 @@ impl VTab for SeriesTab {
} }
if idx_num.contains(QueryPlanFlags::BOTH) { if idx_num.contains(QueryPlanFlags::BOTH) {
// Both start= and stop= boundaries are available. // Both start= and stop= boundaries are available.
info.set_estimated_cost( info.set_estimated_cost(f64::from(
f64::from(2 - if idx_num.contains(QueryPlanFlags::STEP) { 2 - if idx_num.contains(QueryPlanFlags::STEP) {
1 1
} else { } else {
0 0
}), },
); ));
info.set_estimated_rows(1000); info.set_estimated_rows(1000);
if info.num_of_order_by() == 1 { if info.num_of_order_by() == 1 {
if info.is_order_by_desc(0) { if info.is_order_by_desc(0) {
@ -211,16 +212,24 @@ impl VTabCursor for SeriesTabCursor {
} else { } else {
self.step = 1; self.step = 1;
}; };
for arg in args.iter() {
if arg.data_type() == Type::Null {
// If any of the constraints have a NULL value, then return no rows.
self.min_value = 1;
self.max_value = 0;
break;
}
}
self.is_desc = idx_num.contains(QueryPlanFlags::DESC); self.is_desc = idx_num.contains(QueryPlanFlags::DESC);
if self.is_desc { if self.is_desc {
self.value = self.max_value; self.value = self.max_value;
if self.step > 1 { if self.step > 0 {
self.value -= (self.max_value - self.min_value) % self.step; self.value -= (self.max_value - self.min_value) % self.step;
} }
} else { } else {
self.value = self.min_value; self.value = self.min_value;
} }
self.row_id = 0; self.row_id = 1;
Ok(()) Ok(())
} }
fn next(&mut self) -> Result<()> { fn next(&mut self) -> Result<()> {