sqlparser-devexpress 2.5.6 → 2.5.8

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.6",
3
+ "version": "2.5.8",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -238,7 +238,9 @@ function DevExpressConverter() {
238
238
  }
239
239
 
240
240
  // Apply short-circuit evaluation if enabled
241
- if (EnableShortCircuit && IsValueNullShortCircuit && (left == null || right == null)) {
241
+ // Skip for "IS NOT" (e.g. "col IS NOT NULL"): its null is a literal from the query
242
+ // itself, not a placeholder resolving to null, so it must remain a real filter.
243
+ if (EnableShortCircuit && IsValueNullShortCircuit && originalOperator !== "IS NOT" && (left == null || right == null)) {
242
244
  return true; // If either value is null, return true for short-circuit evaluation
243
245
  }
244
246
 
@@ -364,11 +366,27 @@ function DevExpressConverter() {
364
366
  let operatorToken = operator === "IN" ? '=' : operator === "NOT IN" ? '!=' : operator;
365
367
  let joinOperatorToken = operator === "IN" ? 'or' : operator === "NOT IN" ? 'and' : operator;
366
368
  let field = convertValue(ast.field);
369
+
370
+ // When the field itself is an ISNULL(column, default) check, preserve the
371
+ // null-fallback semantics instead of silently collapsing it to the bare column.
372
+ const isFieldNullCheck = isFunctionNullCheck(ast.field, true);
373
+ const nullCheckArg = isFieldNullCheck ? ast.field.args[1]?.value : undefined;
374
+
375
+ const buildEntry = (val) => {
376
+ const base = [field, operatorToken, val];
377
+ if (!isFieldNullCheck) return base;
378
+
379
+ if (normalizeBool(val) == normalizeBool(nullCheckArg)) {
380
+ return [base, 'or', [field, operatorToken, null, { type: "ISNULL", position: "column", defaultValue: nullCheckArg }, null]];
381
+ }
382
+ return [...base, { type: "ISNULL", position: "column", defaultValue: nullCheckArg }, val];
383
+ };
384
+
367
385
  if (Array.isArray(resolvedValue) && resolvedValue.length) {
368
- return resolvedValue.flatMap(i => [[field, operatorToken, i], joinOperatorToken]).slice(0, -1);
386
+ return resolvedValue.flatMap(i => [buildEntry(i), joinOperatorToken]).slice(0, -1);
369
387
  }
370
388
 
371
- return [field, operatorToken, resolvedValue];
389
+ return buildEntry(resolvedValue);
372
390
  }
373
391
 
374
392
  /**
@@ -381,6 +381,28 @@ describe("Parser SQL to dx Filter Builder", () => {
381
381
  expected: [
382
382
  "AllowSubDealer", "=", true, { "type": "ISNULL", "position": "column", "defaultValue": 0 }, true
383
383
  ]
384
+ },
385
+ {
386
+ input: "(CompanyID = {SingleStepTransferDocument.CompanyID} OR {SingleStepTransferDocument.CompanyID} = 0 OR ISNULL(CompanyID,0) = 0) AND ((ISNULL(IsSubdealer,0)) IN ({SingleStepTransferDocument.AllowedSubdealer}))",
387
+ expected: [
388
+ [
389
+ [ "CompanyID", "=", 2, ],
390
+ "or",
391
+ [
392
+ [ "CompanyID", "=", 0, ],
393
+ "or",
394
+ [ "CompanyID", "=", null, { "defaultValue": 0, "position": "column", "type": "ISNULL", }, null, ],
395
+ "or",
396
+ [ "CompanyID", "=", false, ],
397
+ ],
398
+ ],
399
+ "and",
400
+ [
401
+ [ "IsSubdealer", "=", false, ],
402
+ "or",
403
+ [ "IsSubdealer", "=", null, { "defaultValue": 0, "position": "column", "type": "ISNULL", }, null, ]
404
+ ]
405
+ ]
384
406
  },
385
407
  {
386
408
  input: "ISNULL(AllowSubDealer,1) = {LeadDocument.AllowSubDealer}",
@@ -456,6 +478,30 @@ describe("Parser SQL to dx Filter Builder", () => {
456
478
  ["SupplierInvoiceNO", "=", "INV1"]
457
479
 
458
480
  ]
481
+ },
482
+ {
483
+ input: `DocType IN ({QuoteDocument.AllowedDocType})
484
+ AND CompanyID = {QuoteDocument.CompanyID}
485
+ AND
486
+ (
487
+ {QuoteDocument.IsVehicle} = 0
488
+ OR
489
+ (
490
+ {QuoteDocument.IsVehicle} = 1
491
+ AND ProspectID IS NOT NULL
492
+ )
493
+ )`,
494
+ expected: [
495
+ [
496
+ ["DocType", "=", "10809"],
497
+ "or",
498
+ ["DocType", "=", "40927"]
499
+ ],
500
+ "and",
501
+ ["CompanyID", "=", 2],
502
+ "and",
503
+ ["ProspectID", "!=", null, { "type": "IS NOT" }, null]
504
+ ]
459
505
  }
460
506
  ];
461
507
 
@@ -495,6 +541,8 @@ describe("Parser SQL to dx Filter Builder", () => {
495
541
 
496
542
 
497
543
  const sampleData = {
544
+ "SingleStepTransferDocument.CompanyID": 2,
545
+ "SingleStepTransferDocument.AllowedSubdealer": false,
498
546
  "Example.ZeroValue": 0,
499
547
  "CoreEntity0022.CompanyGroupID": 42,
500
548
  "CoreEntity0022.BranchID": 7,
@@ -534,5 +582,8 @@ const sampleData = {
534
582
  "AdjustmentDocument.BranchID": 42,
535
583
  "AdjustmentDocument.CompanyID": 7,
536
584
  "AdjustmentDocument.IsFromInvoice": true,
537
- "AdjustmentDocument.SupplierInvoiceNos": "INV1"
585
+ "AdjustmentDocument.SupplierInvoiceNos": "INV1",
586
+ "QuoteDocument.AllowedDocType": "10809,40927",
587
+ "QuoteDocument.CompanyID": 2,
588
+ "QuoteDocument.IsVehicle": true
538
589
  };