sqlparser-devexpress 2.3.9 → 2.3.10

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.3.9",
3
+ "version": "2.3.10",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -135,7 +135,9 @@ function DevExpressConverter() {
135
135
  }
136
136
 
137
137
  const left = ast.left !== undefined ? processAstNode(ast.left) : convertValue(ast.field);
138
+ const leftDefault = ast.left?.args[1]?.value;
138
139
  const right = ast.right !== undefined ? processAstNode(ast.right) : convertValue(ast.value);
140
+ const rightDefault = ast.right?.args[1]?.value;
139
141
  let operatorToken = ast.operator.toLowerCase();
140
142
 
141
143
  if (operatorToken === "like") {
@@ -155,8 +157,8 @@ function DevExpressConverter() {
155
157
 
156
158
  // Apply short-circuit evaluation if enabled
157
159
  if (EnableShortCircuit) {
158
- if (isAlwaysTrue(comparison)) return true;
159
- if (isAlwaysFalse(comparison)) return false;
160
+ if (isAlwaysTrue(comparison, leftDefault, rightDefault)) return true;
161
+ if (isAlwaysFalse(comparison, leftDefault, rightDefault)) return false;
160
162
  }
161
163
 
162
164
  return comparison;
@@ -332,19 +334,23 @@ function DevExpressConverter() {
332
334
  /**
333
335
  * Checks if a condition is always true.
334
336
  * @param {Array} condition - The condition to check.
337
+ * @param {*} leftDefault - The default value for the left operand.
338
+ * @param {*} rightDefault - The default value for the right operand.
335
339
  * @returns {boolean} True if the condition is always true.
336
340
  */
337
- function isAlwaysTrue(condition) {
338
- return Array.isArray(condition) && condition.length >= 3 && evaluateExpression(...condition) == true;
341
+ function isAlwaysTrue(condition, leftDefault, rightDefault) {
342
+ return Array.isArray(condition) && condition.length >= 3 && evaluateExpression(...condition, leftDefault, rightDefault) == true;
339
343
  }
340
344
 
341
345
  /**
342
346
  * Checks if a condition is always false.
343
347
  * @param {Array} condition - The condition to check.
348
+ * @param {*} leftDefault - The default value for the left operand.
349
+ * @param {*} rightDefault - The default value for the right operand.
344
350
  * @returns {boolean} True if the condition is always false.
345
351
  */
346
- function isAlwaysFalse(condition) {
347
- return Array.isArray(condition) && condition.length >= 3 && evaluateExpression(...condition) == false;
352
+ function isAlwaysFalse(condition, leftDefault, rightDefault) {
353
+ return Array.isArray(condition) && condition.length >= 3 && evaluateExpression(...condition, leftDefault, rightDefault) == false;
348
354
  }
349
355
 
350
356
  /**
@@ -352,9 +358,14 @@ function DevExpressConverter() {
352
358
  * @param {*} left - The left operand.
353
359
  * @param {string} operator - The operator.
354
360
  * @param {*} right - The right operand.
361
+ * @param {*} leftDefault - The default value for the left operand.
362
+ * @param {*} rightDefault - The default value for the right
355
363
  * @returns {boolean|null} The result of the evaluation or null if not evaluable.
356
364
  */
357
- function evaluateExpression(left, operator, right) {
365
+ function evaluateExpression(left, operator, right, leftDefault, rightDefault) {
366
+ if (left == null && leftDefault != undefined) left = leftDefault;
367
+ if (right == null && rightDefault != undefined) right = rightDefault;
368
+
358
369
  if ((left !== null && isNaN(left)) || (right !== null && isNaN(right))) return null;
359
370
 
360
371
  if (left === null || right === null) {
@@ -210,6 +210,10 @@ describe("Parser SQL to dx Filter Builder", () => {
210
210
  "and",
211
211
  ["BranchName", "notcontains", "42"]
212
212
  ]
213
+ },
214
+ {
215
+ input: "(RS2ID in ({SaleOrderStatusStmtGlobalRpt.StateID}) Or (ISNULL({SaleOrderStatusStmtGlobalRpt.StateID},0) =0)) And (RS3ID in (0,{SaleOrderStatusStmtGlobalRpt.RegionID}) Or ISNULL({SaleOrderStatusStmtGlobalRpt.RegionID},0) =0 )",
216
+ expected: []
213
217
  }
214
218
  ];
215
219
 
@@ -270,5 +274,7 @@ const sampleData = {
270
274
  "LeadDocument.CompanyID": 7,
271
275
  "ServiceOrderDocument.SourceID": 2,
272
276
  "LeadDocument.AllowSubDealer": true,
273
- "SupportResolution.TicketID": 123
277
+ "SupportResolution.TicketID": 123,
278
+ "SaleOrderStatusStmtGlobalRpt.StateID": null,
279
+ "SaleOrderStatusStmtGlobalRpt.RegionID": null,
274
280
  };