sqlparser-devexpress 2.6.1 → 2.6.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
package/src/@types/default.d.ts
CHANGED
package/src/core/converter.js
CHANGED
|
@@ -10,6 +10,7 @@ function DevExpressConverter() {
|
|
|
10
10
|
let EnableShortCircuit = true;
|
|
11
11
|
let IsValueNullShortCircuit = false; // Flag to enable/disable null short-circuiting
|
|
12
12
|
let TreatNumberAsNullableBit = false; // Flag to enable/disable optional boolean with number conversion
|
|
13
|
+
let TreatNullAsFalse = false; // Flag to evaluate null as equal to 0 / false / ""
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Main conversion function that sets up the global context
|
|
@@ -18,14 +19,16 @@ function DevExpressConverter() {
|
|
|
18
19
|
* @param {boolean} enableShortCircuit - Optional enabling and disabling the shortcircuit ie evaluating value = value scenario
|
|
19
20
|
* @param {boolean} isValueNullShortCircuit - Optional enabling and disabling the null shortcircuit ie evaluating value = null scenario
|
|
20
21
|
* @param {boolean} treatNumberAsNullableBit - Optional enabling and disabling the optional boolean with number conversion
|
|
22
|
+
* @param {boolean} treatNullAsFalse - Optional evaluating null as equal to 0 / false / "" (e.g. {var} = 0 is true when var is null)
|
|
21
23
|
* @returns {Array|null} DevExpress format filter
|
|
22
24
|
*/
|
|
23
|
-
function convert(ast, ResultObject = null, enableShortCircuit = true, isValueNullShortCircuit = false, treatNumberAsNullableBit = false) {
|
|
25
|
+
function convert(ast, ResultObject = null, enableShortCircuit = true, isValueNullShortCircuit = false, treatNumberAsNullableBit = false, treatNullAsFalse = false) {
|
|
24
26
|
// Set up global context
|
|
25
27
|
resultObject = ResultObject;
|
|
26
28
|
EnableShortCircuit = enableShortCircuit;
|
|
27
29
|
IsValueNullShortCircuit = isValueNullShortCircuit;
|
|
28
30
|
TreatNumberAsNullableBit = treatNumberAsNullableBit;
|
|
31
|
+
TreatNullAsFalse = treatNullAsFalse;
|
|
29
32
|
|
|
30
33
|
// Process the AST
|
|
31
34
|
let result = processAstNode(ast);
|
|
@@ -580,6 +583,15 @@ function DevExpressConverter() {
|
|
|
580
583
|
|
|
581
584
|
if ((left !== null && isNaN(left)) || (right !== null && isNaN(right))) return null;
|
|
582
585
|
|
|
586
|
+
// With TreatNullAsFalse, NULL behaves like 0 / false / "" (NULL = 0 is true)
|
|
587
|
+
if (TreatNullAsFalse && (left === null) !== (right === null)) {
|
|
588
|
+
const other = left === null ? right : left;
|
|
589
|
+
if (other === 0 || other === false || other === "") {
|
|
590
|
+
if (operator === '=' || operator === '==') return true;
|
|
591
|
+
if (operator === '<>' || operator === '!=') return false;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
|
|
583
595
|
// NULL only equals NULL (NULL = 0 is false); use ISNULL(x, 0) to treat NULL as 0
|
|
584
596
|
if (left === null || right === null) {
|
|
585
597
|
if (operator === '=' || operator === '==') return left === right;
|
|
@@ -617,9 +629,10 @@ const devExpressConverter = DevExpressConverter();
|
|
|
617
629
|
* @param {boolean} options.enableShortCircuit - Enable or disable short-circuit evaluation
|
|
618
630
|
* @param {boolean} options.isValueNullShortCircuit - Enable or disable null short-circuit evaluation
|
|
619
631
|
* @param {boolean} options.treatNumberAsNullableBit - Enable or disable optional boolean with number conversion
|
|
632
|
+
* @param {boolean} options.treatNullAsFalse - Evaluate null as equal to 0 / false / "" during short-circuit evaluation
|
|
620
633
|
* @returns {Array|null} DevExpress format filter
|
|
621
634
|
*/
|
|
622
635
|
export function convertToDevExpressFormat({ ast, resultObject = null, options = {} }) {
|
|
623
|
-
const { enableShortCircuit = true, isValueNullShortCircuit = false, treatNumberAsNullableBit = false } = options;
|
|
624
|
-
return devExpressConverter.init(ast, resultObject, enableShortCircuit, isValueNullShortCircuit, treatNumberAsNullableBit);
|
|
636
|
+
const { enableShortCircuit = true, isValueNullShortCircuit = false, treatNumberAsNullableBit = false, treatNullAsFalse = false } = options;
|
|
637
|
+
return devExpressConverter.init(ast, resultObject, enableShortCircuit, isValueNullShortCircuit, treatNumberAsNullableBit, treatNullAsFalse);
|
|
625
638
|
}
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
],
|
|
19
19
|
"converterOptions": {
|
|
20
20
|
"isValueNullShortCircuit": true,
|
|
21
|
-
"treatNumberAsNullableBit": true
|
|
21
|
+
"treatNumberAsNullableBit": true,
|
|
22
|
+
"treatNullAsFalse": true
|
|
22
23
|
},
|
|
23
24
|
"variables": {
|
|
24
25
|
"SingleStepTransferDocument.CompanyID": 2,
|
|
@@ -976,19 +977,50 @@
|
|
|
976
977
|
],
|
|
977
978
|
"and",
|
|
978
979
|
[
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
980
|
+
[
|
|
981
|
+
"varID",
|
|
982
|
+
"=",
|
|
983
|
+
null,
|
|
984
|
+
{
|
|
985
|
+
"type": "ISNULL",
|
|
986
|
+
"position": "value",
|
|
987
|
+
"defaultValue": 0
|
|
988
|
+
},
|
|
989
|
+
null
|
|
990
|
+
],
|
|
991
|
+
"or",
|
|
992
|
+
[
|
|
993
|
+
[
|
|
994
|
+
"varID",
|
|
995
|
+
"=",
|
|
996
|
+
0
|
|
997
|
+
],
|
|
998
|
+
"or",
|
|
999
|
+
[
|
|
1000
|
+
"varID",
|
|
1001
|
+
"=",
|
|
1002
|
+
null,
|
|
1003
|
+
{
|
|
1004
|
+
"type": "ISNULL",
|
|
1005
|
+
"position": "column",
|
|
1006
|
+
"defaultValue": 0
|
|
1007
|
+
},
|
|
1008
|
+
null
|
|
1009
|
+
],
|
|
1010
|
+
"or",
|
|
1011
|
+
[
|
|
1012
|
+
"varID",
|
|
1013
|
+
"=",
|
|
1014
|
+
false
|
|
1015
|
+
]
|
|
1016
|
+
]
|
|
988
1017
|
]
|
|
989
1018
|
],
|
|
990
|
-
"expectedSql":
|
|
991
|
-
|
|
1019
|
+
"expectedSql": [
|
|
1020
|
+
"ISNULL(\"ItemID\", 0) = 42",
|
|
1021
|
+
"AND ( \"varID\" = ISNULL(NULL, 0) OR ( \"varID\" = 0 OR ISNULL(\"varID\", 0) = 0 OR \"varID\" = 0 ) )"
|
|
1022
|
+
],
|
|
1023
|
+
"note": "VarMatrixID0 is null: varID = ISNULL({VarMatrixID0}, 0) keeps the null with its ISNULL default (same as case 42). With treatNullAsFalse, {VarMatrixID0} = 0 is true (null is treated as 0), so that AND group reduces to ISNULL(varID, 0) = 0."
|
|
992
1024
|
},
|
|
993
1025
|
{
|
|
994
1026
|
"id": 56,
|