sqlparser-devexpress 2.5.5 → 2.5.7
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 +32 -2
- package/tests/parser.test.js +45 -2
package/package.json
CHANGED
package/src/core/converter.js
CHANGED
|
@@ -149,6 +149,20 @@ function DevExpressConverter() {
|
|
|
149
149
|
const leftDefault = ast.left?.args && ast.left?.args[1]?.value;
|
|
150
150
|
const right = ast.right !== undefined ? processAstNode(ast.right) : convertValue(ast.value);
|
|
151
151
|
const rightDefault = ast.right?.args && ast.right?.args[1]?.value;
|
|
152
|
+
|
|
153
|
+
// Short-circuit when ISNULL's first arg is a placeholder (resolved concrete value, not a column).
|
|
154
|
+
// evaluateExpression cannot handle non-numeric string comparisons (e.g. "INV1" = ""),
|
|
155
|
+
// so detect and short-circuit here before any ISNULL column-null handling runs.
|
|
156
|
+
if (EnableShortCircuit && ast.left?.type === "function" && ast.left?.name === "ISNULL" &&
|
|
157
|
+
ast.left?.args?.[0]?.value?.type === "placeholder") {
|
|
158
|
+
if (IsValueNullShortCircuit && (left === null || right === null)) return true;
|
|
159
|
+
if (left !== null && right !== null) {
|
|
160
|
+
const normalL = normalizeBool(left);
|
|
161
|
+
const normalR = normalizeBool(right);
|
|
162
|
+
return normalL === normalR ? true : false;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
152
166
|
let operatorToken = ast.operator.toLowerCase();
|
|
153
167
|
let includeExtradata = false;
|
|
154
168
|
|
|
@@ -350,11 +364,27 @@ function DevExpressConverter() {
|
|
|
350
364
|
let operatorToken = operator === "IN" ? '=' : operator === "NOT IN" ? '!=' : operator;
|
|
351
365
|
let joinOperatorToken = operator === "IN" ? 'or' : operator === "NOT IN" ? 'and' : operator;
|
|
352
366
|
let field = convertValue(ast.field);
|
|
367
|
+
|
|
368
|
+
// When the field itself is an ISNULL(column, default) check, preserve the
|
|
369
|
+
// null-fallback semantics instead of silently collapsing it to the bare column.
|
|
370
|
+
const isFieldNullCheck = isFunctionNullCheck(ast.field, true);
|
|
371
|
+
const nullCheckArg = isFieldNullCheck ? ast.field.args[1]?.value : undefined;
|
|
372
|
+
|
|
373
|
+
const buildEntry = (val) => {
|
|
374
|
+
const base = [field, operatorToken, val];
|
|
375
|
+
if (!isFieldNullCheck) return base;
|
|
376
|
+
|
|
377
|
+
if (normalizeBool(val) == normalizeBool(nullCheckArg)) {
|
|
378
|
+
return [base, 'or', [field, operatorToken, null, { type: "ISNULL", position: "column", defaultValue: nullCheckArg }, null]];
|
|
379
|
+
}
|
|
380
|
+
return [...base, { type: "ISNULL", position: "column", defaultValue: nullCheckArg }, val];
|
|
381
|
+
};
|
|
382
|
+
|
|
353
383
|
if (Array.isArray(resolvedValue) && resolvedValue.length) {
|
|
354
|
-
return resolvedValue.flatMap(i => [
|
|
384
|
+
return resolvedValue.flatMap(i => [buildEntry(i), joinOperatorToken]).slice(0, -1);
|
|
355
385
|
}
|
|
356
386
|
|
|
357
|
-
return
|
|
387
|
+
return buildEntry(resolvedValue);
|
|
358
388
|
}
|
|
359
389
|
|
|
360
390
|
/**
|
package/tests/parser.test.js
CHANGED
|
@@ -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}",
|
|
@@ -440,6 +462,21 @@ describe("Parser SQL to dx Filter Builder", () => {
|
|
|
440
462
|
["CompanyID", "=", false]
|
|
441
463
|
]
|
|
442
464
|
]
|
|
465
|
+
],
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
input: "BranchID = {AdjustmentDocument.BranchID} AND CompanyID = {AdjustmentDocument.CompanyID} AND IsFromInvoice = {AdjustmentDocument.IsFromInvoice} AND (SupplierInvoiceNO IN ('{AdjustmentDocument.SupplierInvoiceNos}') OR ISNULL('{AdjustmentDocument.SupplierInvoiceNos}','''') = '''')",
|
|
469
|
+
expected: [
|
|
470
|
+
[
|
|
471
|
+
["BranchID", "=", 42],
|
|
472
|
+
"and",
|
|
473
|
+
["CompanyID", "=", 7],
|
|
474
|
+
"and",
|
|
475
|
+
["IsFromInvoice", "=", true],
|
|
476
|
+
],
|
|
477
|
+
"and",
|
|
478
|
+
["SupplierInvoiceNO", "=", "INV1"]
|
|
479
|
+
|
|
443
480
|
]
|
|
444
481
|
}
|
|
445
482
|
];
|
|
@@ -480,6 +517,8 @@ describe("Parser SQL to dx Filter Builder", () => {
|
|
|
480
517
|
|
|
481
518
|
|
|
482
519
|
const sampleData = {
|
|
520
|
+
"SingleStepTransferDocument.CompanyID": 2,
|
|
521
|
+
"SingleStepTransferDocument.AllowedSubdealer": false,
|
|
483
522
|
"Example.ZeroValue": 0,
|
|
484
523
|
"CoreEntity0022.CompanyGroupID": 42,
|
|
485
524
|
"CoreEntity0022.BranchID": 7,
|
|
@@ -513,7 +552,11 @@ const sampleData = {
|
|
|
513
552
|
"PurchaseOrderDocument.IsMultiBrand": false,
|
|
514
553
|
"PurchaseOrderDocument.AllowedApplicableMake": "0",
|
|
515
554
|
"SampleDoc.AuthFilterID": "ID",
|
|
516
|
-
|
|
555
|
+
"ItemPrice.AllowedItemGroupType": "1,2",
|
|
517
556
|
"ItemPrice.AllowedNonStock": 1,
|
|
518
|
-
"ItemPrice.CompanyID": 7
|
|
557
|
+
"ItemPrice.CompanyID": 7,
|
|
558
|
+
"AdjustmentDocument.BranchID": 42,
|
|
559
|
+
"AdjustmentDocument.CompanyID": 7,
|
|
560
|
+
"AdjustmentDocument.IsFromInvoice": true,
|
|
561
|
+
"AdjustmentDocument.SupplierInvoiceNos": "INV1"
|
|
519
562
|
};
|