sqlparser-devexpress 2.4.1 → 2.4.2

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.4.1",
3
+ "version": "2.4.2",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -160,14 +160,31 @@ function DevExpressConverter() {
160
160
  includeExtradata = true;
161
161
  }
162
162
  let comparison = [left, operatorToken, right];
163
+
163
164
  if (includeExtradata)
164
165
  comparison = [left, operatorToken, right, { type: originalOperator }, right];
165
166
 
166
167
  // Last null because of special case when using dropdown it https://github.com/DevExpress/DevExtreme/blob/25_1/packages/devextreme/js/__internal/data/m_utils.ts#L18 it takes last value as null
167
168
  if ((ast.left && isFunctionNullCheck(ast.left, true)) || (ast.value && isFunctionNullCheck(ast.value, false))) {
168
- comparison = [[left, operatorToken, right], 'or', [left, operatorToken, null, { type: "ISNULL", defaultValue: (ast.left ?? ast.value).args[1]?.value }, null]];
169
+ const nullCheckArg = (ast.left ?? ast.value).args[1]?.value;
170
+ let baseComparison = comparison;
171
+
172
+ if (Array.isArray(right) && (right.includes("or") || right.includes("and"))) {
173
+ const valueRight = right.shift();
174
+ baseComparison = [[left, operatorToken, valueRight], ...right];
175
+ }
176
+
177
+ comparison = [baseComparison, 'or', [left, operatorToken, null, { type: "ISNULL", defaultValue: nullCheckArg }, null]];
169
178
  } else if (ast.right && isFunctionNullCheck(ast.right, true)) {
170
- comparison = [[left, operatorToken, right], 'or', [right, operatorToken, null, { type: "ISNULL", defaultValue: ast.right.args[1]?.value }, null]];
179
+ const nullCheckArg = ast.right.args[1]?.value;
180
+ let baseComparison = comparison;
181
+
182
+ if (Array.isArray(right) && (right.includes("or") || right.includes("and"))) {
183
+ const valueRight = right.shift();
184
+ baseComparison = [[left, operatorToken, valueRight], ...right];
185
+ }
186
+
187
+ comparison = [baseComparison, 'or', [right, operatorToken, null, { type: "ISNULL", defaultValue: nullCheckArg }, null]];
171
188
  }
172
189
 
173
190
  // Apply short-circuit evaluation if enabled
package/src/debug.js CHANGED
@@ -28,7 +28,7 @@
28
28
  // return convertToDevExpressFormat({ ast: astTree, resultObject: sampleData, isValueNullShortCircuit: true });
29
29
  // }
30
30
 
31
- // const devexpress = parseFilterString("(ISNULL(TicketID, 0) = ISNULL({CustomerOrders.OrderID}, 0))", sampleData);
31
+ // const devexpress = parseFilterString("ISNULL(CompanyID,0) = ISNULL({CustomerOrders.OrderID},0) OR (ISNULL(CompanyID,0) = 0)", sampleData);
32
32
  // console.log("DevExpress Filter:", JSON.stringify(devexpress, null, 2));
33
33
  // // const devexpress = parseFilterString("(RS2ID in ({LeadStatementGlobalRpt.StateID}) Or ({LeadStatementGlobalRpt.StateID} =0)) And (RS3ID in (0,{LeadStatementGlobalRpt.RegionID}) Or {LeadStatementGlobalRpt.RegionID} =0 )", sampleData);
34
34
 
@@ -302,6 +302,36 @@ describe("Parser SQL to dx Filter Builder", () => {
302
302
  "or",
303
303
  ["IsChecked", "=", true]
304
304
  ]
305
+ },
306
+ {
307
+ input: "ISNULL(CompanyID,0) = ISNULL({TransferOutwardDocument.CompanyID},0) OR (ISNULL(CompanyID,0) = 0)",
308
+ expected: [
309
+ [
310
+
311
+ ["CompanyID", "=", 7],
312
+ "or",
313
+ [
314
+ ["CompanyID", "=", 0],
315
+ "or",
316
+ ["CompanyID", "=", null,
317
+ {
318
+ "type": "ISNULL",
319
+ "defaultValue": 0
320
+ }, null
321
+ ],
322
+ "or",
323
+ ["CompanyID", "=", false]
324
+ ]
325
+ ],
326
+ "or",
327
+ [
328
+ "CompanyID", "=", null,
329
+ {
330
+ "type": "ISNULL",
331
+ "defaultValue": 0
332
+ }, null
333
+ ]
334
+ ]
305
335
  }
306
336
  ];
307
337