From 3a2312e0bd3b1a57bd5ab8c3d57700fbba7ce16b Mon Sep 17 00:00:00 2001 From: David Selassie Date: Thu, 6 Jul 2023 17:23:28 -0700 Subject: [PATCH] Interpret generate_series arguments as possibly NULL --- src/vtab/series.rs | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/vtab/series.rs b/src/vtab/series.rs index 53d13b9..1e178de 100644 --- a/src/vtab/series.rs +++ b/src/vtab/series.rs @@ -8,7 +8,6 @@ use std::marker::PhantomData; use std::os::raw::c_int; use crate::ffi; -use crate::types::Type; use crate::vtab::{ eponymous_only_module, Context, IndexConstraintOp, IndexInfo, VTab, VTabConfig, VTabConnection, VTabCursor, Values, @@ -198,21 +197,34 @@ impl SeriesTabCursor<'_> { unsafe impl VTabCursor for SeriesTabCursor<'_> { fn filter(&mut self, idx_num: c_int, _idx_str: Option<&str>, args: &Values<'_>) -> Result<()> { let mut idx_num = QueryPlanFlags::from_bits_truncate(idx_num); + let mut any_null = false; let mut i = 0; if idx_num.contains(QueryPlanFlags::START) { - self.min_value = args.get(i)?; + if let Some(min_value) = args.get(i)? { + self.min_value = min_value; + } else { + any_null = true; + } i += 1; } else { self.min_value = 0; } if idx_num.contains(QueryPlanFlags::STOP) { - self.max_value = args.get(i)?; + if let Some(max_value) = args.get(i)? { + self.max_value = max_value; + } else { + any_null = true; + } i += 1; } else { self.max_value = 0xffff_ffff; } if idx_num.contains(QueryPlanFlags::STEP) { - self.step = args.get(i)?; + if let Some(step) = args.get(i)? { + self.step = step; + } else { + any_null = true; + } if self.step == 0 { self.step = 1; } else if self.step < 0 { @@ -224,13 +236,11 @@ unsafe impl VTabCursor for SeriesTabCursor<'_> { } else { 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; - } + if any_null { + // If any of the constraints have a NULL value, then + // return no rows. + self.min_value = 1; + self.max_value = 0; } self.is_desc = idx_num.contains(QueryPlanFlags::DESC); if self.is_desc {