sqlparser-devexpress 2.5.9 → 2.6.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlparser-devexpress",
3
- "version": "2.5.9",
3
+ "version": "2.6.1",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -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
  }
@@ -244,6 +245,11 @@ function DevExpressConverter() {
244
245
  // otherwise OR branches like ISNULL(CompanyID,0)=param OR ISNULL(CompanyID,0)=0
245
246
  // can collapse to a full-match filter when param is null.
246
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
+ }
247
253
  return true; // If either value is null, return true for short-circuit evaluation
248
254
  }
249
255
 
@@ -285,6 +291,27 @@ function DevExpressConverter() {
285
291
  return value === 0 || value === 1 ? Boolean(value) : value;
286
292
  }
287
293
 
294
+ /**
295
+ * Converts boolean and numeric strings to their literal values.
296
+ *
297
+ * "true"/"false" (case-insensitive) become booleans and numeric strings become numbers.
298
+ * Empty strings and any other value are returned unchanged.
299
+ *
300
+ * @param {*} value - The value to normalize.
301
+ * @returns {*} - The literal value, or the original value if it is not a boolean or numeric string.
302
+ */
303
+ function normalizeLiteralString(value) {
304
+ if (typeof value !== "string") return value;
305
+
306
+ const trimmed = value.trim();
307
+ const lower = trimmed.toLowerCase();
308
+ if (lower === "true") return true;
309
+ if (lower === "false") return false;
310
+ if (trimmed !== "" && !isNaN(trimmed)) return Number(trimmed);
311
+
312
+ return value;
313
+ }
314
+
288
315
 
289
316
  /**
290
317
  * Handles function calls, focusing on ISNULL.
@@ -547,12 +574,13 @@ function DevExpressConverter() {
547
574
  if (left == null && leftDefault != undefined) left = leftDefault;
548
575
  if (right == null && rightDefault != undefined) right = rightDefault;
549
576
 
550
- if ((left !== null && isNaN(left)) || (right !== null && isNaN(right))) return null;
577
+ // Placeholders may resolve to strings like "1", "0", "true" or "False"
578
+ left = normalizeLiteralString(left);
579
+ right = normalizeLiteralString(right);
551
580
 
552
- // Handle NULL == 0 OR NULL == "" cases
553
- if (left === null && (right == 0 || right == "")) return true;
554
- if (right === null && (left == 0 || left == "")) return true;
581
+ if ((left !== null && isNaN(left)) || (right !== null && isNaN(right))) return null;
555
582
 
583
+ // NULL only equals NULL (NULL = 0 is false); use ISNULL(x, 0) to treat NULL as 0
556
584
  if (left === null || right === null) {
557
585
  if (operator === '=' || operator === '==') return left === right;
558
586
  if (operator === '<>' || operator === '!=') return left !== right;
@@ -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 };