mirror of
https://github.com/isar/rusqlite.git
synced 2025-01-19 19:20:50 +08:00
Merge pull request #1357 from davidselassie/fix-null-series
Fixes generate_series to handle NULL arguments
This commit is contained in:
commit
7b0393210b
@ -200,19 +200,19 @@ unsafe impl VTabCursor for SeriesTabCursor<'_> {
|
|||||||
let mut idx_num = QueryPlanFlags::from_bits_truncate(idx_num);
|
let mut 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 = args.get(i)?;
|
self.min_value = args.get::<Option<_>>(i)?.unwrap_or_default();
|
||||||
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 = args.get(i)?;
|
self.max_value = args.get::<Option<_>>(i)?.unwrap_or_default();
|
||||||
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 = args.get(i)?;
|
self.step = args.get::<Option<_>>(i)?.unwrap_or_default();
|
||||||
if self.step == 0 {
|
if self.step == 0 {
|
||||||
self.step = 1;
|
self.step = 1;
|
||||||
} else if self.step < 0 {
|
} else if self.step < 0 {
|
||||||
@ -316,6 +316,26 @@ mod test {
|
|||||||
let series: Vec<i32> = s.query([])?.map(|r| r.get(0)).collect()?;
|
let series: Vec<i32> = s.query([])?.map(|r| r.get(0)).collect()?;
|
||||||
assert_eq!(vec![30, 25, 20, 15, 10, 5, 0], series);
|
assert_eq!(vec![30, 25, 20, 15, 10, 5, 0], series);
|
||||||
|
|
||||||
|
let mut s = db.prepare("SELECT * FROM generate_series(NULL)")?;
|
||||||
|
let series: Vec<i32> = s.query([])?.map(|r| r.get(0)).collect()?;
|
||||||
|
let empty = Vec::<i32>::new();
|
||||||
|
assert_eq!(empty, series);
|
||||||
|
let mut s = db.prepare("SELECT * FROM generate_series(5,NULL)")?;
|
||||||
|
let series: Vec<i32> = s.query([])?.map(|r| r.get(0)).collect()?;
|
||||||
|
assert_eq!(empty, series);
|
||||||
|
let mut s = db.prepare("SELECT * FROM generate_series(5,10,NULL)")?;
|
||||||
|
let series: Vec<i32> = s.query([])?.map(|r| r.get(0)).collect()?;
|
||||||
|
assert_eq!(empty, series);
|
||||||
|
let mut s = db.prepare("SELECT * FROM generate_series(NULL,10,2)")?;
|
||||||
|
let series: Vec<i32> = s.query([])?.map(|r| r.get(0)).collect()?;
|
||||||
|
assert_eq!(empty, series);
|
||||||
|
let mut s = db.prepare("SELECT * FROM generate_series(5,NULL,2)")?;
|
||||||
|
let series: Vec<i32> = s.query([])?.map(|r| r.get(0)).collect()?;
|
||||||
|
assert_eq!(empty, series);
|
||||||
|
let mut s = db.prepare("SELECT * FROM generate_series(NULL) ORDER BY value DESC")?;
|
||||||
|
let series: Vec<i32> = s.query([])?.map(|r| r.get(0)).collect()?;
|
||||||
|
assert_eq!(empty, series);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user