Fix for more than/less than ranges, zeros were ignored when building up ranges, so that it simply acted like an upper limit, rather than a range.

This commit is contained in:
mike12345567 2023-09-14 14:00:49 +01:00
parent 80e217afda
commit 217d10f5fb
2 changed files with 8 additions and 3 deletions

View File

@ -147,6 +147,10 @@ export async function validate({
return { valid: Object.keys(errors).length === 0, errors } return { valid: Object.keys(errors).length === 0, errors }
} }
export function isValidFilter(value: any) {
return value != null && value !== ""
}
// don't do a pure falsy check, as 0 is included // don't do a pure falsy check, as 0 is included
// https://github.com/Budibase/budibase/issues/10118 // https://github.com/Budibase/budibase/issues/10118
export function removeEmptyFilters(filters: SearchFilters) { export function removeEmptyFilters(filters: SearchFilters) {

View File

@ -11,6 +11,7 @@ import { QueryOptions } from "../../definitions/datasource"
import { isIsoDateString, SqlClient } from "../utils" import { isIsoDateString, SqlClient } from "../utils"
import SqlTableQueryBuilder from "./sqlTable" import SqlTableQueryBuilder from "./sqlTable"
import environment from "../../environment" import environment from "../../environment"
import { isValidFilter } from "../../api/controllers/row/utils"
const envLimit = environment.SQL_MAX_ROWS const envLimit = environment.SQL_MAX_ROWS
? parseInt(environment.SQL_MAX_ROWS) ? parseInt(environment.SQL_MAX_ROWS)
@ -261,15 +262,15 @@ class InternalBuilder {
if (isEmptyObject(value.high)) { if (isEmptyObject(value.high)) {
value.high = "" value.high = ""
} }
if (value.low && value.high) { if (isValidFilter(value.low) && isValidFilter(value.high)) {
// Use a between operator if we have 2 valid range values // Use a between operator if we have 2 valid range values
const fnc = allOr ? "orWhereBetween" : "whereBetween" const fnc = allOr ? "orWhereBetween" : "whereBetween"
query = query[fnc](key, [value.low, value.high]) query = query[fnc](key, [value.low, value.high])
} else if (value.low) { } else if (isValidFilter(value.low)) {
// Use just a single greater than operator if we only have a low // Use just a single greater than operator if we only have a low
const fnc = allOr ? "orWhere" : "where" const fnc = allOr ? "orWhere" : "where"
query = query[fnc](key, ">", value.low) query = query[fnc](key, ">", value.low)
} else if (value.high) { } else if (isValidFilter(value.high)) {
// Use just a single less than operator if we only have a high // Use just a single less than operator if we only have a high
const fnc = allOr ? "orWhere" : "where" const fnc = allOr ? "orWhere" : "where"
query = query[fnc](key, "<", value.high) query = query[fnc](key, "<", value.high)