sqlparser-devexpress 2.5.8 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/converter.js +11 -9
- package/src/core/parser.js +4 -1
- package/tests/fixtures/FilterCases.json +1470 -0
- package/tests/parser.test.js +27 -574
package/package.json
CHANGED
package/src/core/converter.js
CHANGED
|
@@ -108,6 +108,7 @@ function DevExpressConverter() {
|
|
|
108
108
|
|
|
109
109
|
// Short-circuit: always-false conditions
|
|
110
110
|
if (left === false || right === false) {
|
|
111
|
+
if (operator === 'and') return false;
|
|
111
112
|
return left === false ? right : left;
|
|
112
113
|
}
|
|
113
114
|
}
|
|
@@ -240,7 +241,15 @@ function DevExpressConverter() {
|
|
|
240
241
|
// Apply short-circuit evaluation if enabled
|
|
241
242
|
// Skip for "IS NOT" (e.g. "col IS NOT NULL"): its null is a literal from the query
|
|
242
243
|
// itself, not a placeholder resolving to null, so it must remain a real filter.
|
|
243
|
-
|
|
244
|
+
// Avoid null short-circuit when comparison is produced from ISNULL(column, default),
|
|
245
|
+
// otherwise OR branches like ISNULL(CompanyID,0)=param OR ISNULL(CompanyID,0)=0
|
|
246
|
+
// can collapse to a full-match filter when param is null.
|
|
247
|
+
if (EnableShortCircuit && IsValueNullShortCircuit && originalOperator !== "IS NOT" && (left == null || right == null) && !isLeftNullCheck && !isRightNullCheck) {
|
|
248
|
+
// No column involved (e.g. {var} = 0): evaluate null against the value instead of dropping it.
|
|
249
|
+
if (typeof ast.field !== "string") {
|
|
250
|
+
const evaluated = evaluateExpression(left, operatorToken, right, leftDefault, rightDefault);
|
|
251
|
+
if (evaluated === true || evaluated === false) return evaluated;
|
|
252
|
+
}
|
|
244
253
|
return true; // If either value is null, return true for short-circuit evaluation
|
|
245
254
|
}
|
|
246
255
|
|
|
@@ -359,10 +368,6 @@ function DevExpressConverter() {
|
|
|
359
368
|
}
|
|
360
369
|
}
|
|
361
370
|
|
|
362
|
-
if (EnableShortCircuit && IsValueNullShortCircuit && (ast.field?.type === "placeholder" || ast.value?.type === "placeholder" || ast.value === null) && resolvedValue === null) {
|
|
363
|
-
return true;
|
|
364
|
-
}
|
|
365
|
-
|
|
366
371
|
let operatorToken = operator === "IN" ? '=' : operator === "NOT IN" ? '!=' : operator;
|
|
367
372
|
let joinOperatorToken = operator === "IN" ? 'or' : operator === "NOT IN" ? 'and' : operator;
|
|
368
373
|
let field = convertValue(ast.field);
|
|
@@ -550,10 +555,7 @@ function DevExpressConverter() {
|
|
|
550
555
|
|
|
551
556
|
if ((left !== null && isNaN(left)) || (right !== null && isNaN(right))) return null;
|
|
552
557
|
|
|
553
|
-
//
|
|
554
|
-
if (left === null && (right == 0 || right == "")) return true;
|
|
555
|
-
if (right === null && (left == 0 || left == "")) return true;
|
|
556
|
-
|
|
558
|
+
// NULL only equals NULL (NULL = 0 is false); use ISNULL(x, 0) to treat NULL as 0
|
|
557
559
|
if (left === null || right === null) {
|
|
558
560
|
if (operator === '=' || operator === '==') return left === right;
|
|
559
561
|
if (operator === '<>' || operator === '!=') return left !== right;
|
package/src/core/parser.js
CHANGED
|
@@ -99,8 +99,11 @@ export function parse(input, variables = []) {
|
|
|
99
99
|
if (currentToken && currentToken.type === "operator") {
|
|
100
100
|
const operator = currentToken.value;
|
|
101
101
|
next(); // Move to the next token after the operator
|
|
102
|
-
const rightOperand = parseValue(); // Parse the value after the operator
|
|
103
102
|
const nodeType = LOGICAL_OPERATORS.includes(operator.toLowerCase()) ? "logical" : "comparison";
|
|
103
|
+
// After AND / OR the right side is a full expression (e.g. "(a = 1)" or "a = 1"), not a single value
|
|
104
|
+
const rightOperand = nodeType === "logical"
|
|
105
|
+
? parseExpression(OPERATOR_PRECEDENCE[operator.toUpperCase()] + 1)
|
|
106
|
+
: parseValue(); // Parse the value after the operator
|
|
104
107
|
|
|
105
108
|
if (nodeType === "logical") {
|
|
106
109
|
return { type: "logical", operator, left: { type: "function", name: functionName, args: functionArgs }, right: rightOperand };
|