sqlparser-devexpress 2.6.1 → 2.6.3
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);
|
|
@@ -148,18 +151,37 @@ function DevExpressConverter() {
|
|
|
148
151
|
|
|
149
152
|
const left = ast.left !== undefined ? processAstNode(ast.left) : convertValue(ast.field);
|
|
150
153
|
const leftDefault = ast.left?.args && ast.left?.args[1]?.value;
|
|
151
|
-
|
|
154
|
+
let right = ast.right !== undefined ? processAstNode(ast.right) : convertValue(ast.value);
|
|
152
155
|
const rightDefault = ast.right?.args && ast.right?.args[1]?.value;
|
|
153
156
|
|
|
157
|
+
// With TreatNullAsFalse, ISNULL(column, d) = {var} where {var} is null or blank means
|
|
158
|
+
// "compare against false": use 0 (or '' for a string default), so rows whose column is
|
|
159
|
+
// 0 / false / NULL match, instead of emitting "column = null" (which only matches NULL).
|
|
160
|
+
// A numeric 0 also gets an "= false" branch (see TreatNumberAsNullableBit below), since DevExtreme
|
|
161
|
+
// compares 0 strictly and a boolean column holding false would otherwise not match.
|
|
162
|
+
const rightNode = ast.right ?? ast.value;
|
|
163
|
+
let nullTreatedAsFalse = false;
|
|
164
|
+
// Only for "=": for <>, >, LIKE etc. the extra OR branches would match the wrong rows.
|
|
165
|
+
if (TreatNullAsFalse && operator === "=" && rightNode?.type === "placeholder" && isFunctionNullCheck(ast.left, true) &&
|
|
166
|
+
(right == null || (typeof right === "string" && right.trim() === ""))) {
|
|
167
|
+
right = typeof leftDefault === "string" ? "" : 0;
|
|
168
|
+
nullTreatedAsFalse = right === 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
154
171
|
// Short-circuit when ISNULL's first arg is a placeholder (resolved concrete value, not a column).
|
|
155
172
|
// evaluateExpression cannot handle non-numeric string comparisons (e.g. "INV1" = ""),
|
|
156
173
|
// so detect and short-circuit here before any ISNULL column-null handling runs.
|
|
157
174
|
if (EnableShortCircuit && ast.left?.type === "function" && ast.left?.name === "ISNULL" &&
|
|
158
175
|
ast.left?.args?.[0]?.value?.type === "placeholder") {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
176
|
+
// With TreatNullAsFalse, a blank placeholder value ("") is unset, the same as NULL
|
|
177
|
+
// (only against numeric/boolean operands; "" = '' stays a plain string comparison)
|
|
178
|
+
const blankToNull = (v, other) => (TreatNullAsFalse && typeof v === "string" && v.trim() === "" && typeof other !== "string") ? null : v;
|
|
179
|
+
const sL = blankToNull(left, right);
|
|
180
|
+
const sR = blankToNull(right, left);
|
|
181
|
+
if (IsValueNullShortCircuit && (sL === null || sR === null)) return true;
|
|
182
|
+
if (sL !== null && sR !== null) {
|
|
183
|
+
const normalL = normalizeBool(normalizeLiteralString(sL));
|
|
184
|
+
const normalR = normalizeBool(normalizeLiteralString(sR));
|
|
163
185
|
return normalL === normalR ? true : false;
|
|
164
186
|
}
|
|
165
187
|
}
|
|
@@ -258,7 +280,7 @@ function DevExpressConverter() {
|
|
|
258
280
|
if (isAlwaysFalse(comparison, leftDefault, rightDefault)) return false;
|
|
259
281
|
}
|
|
260
282
|
|
|
261
|
-
if (TreatNumberAsNullableBit && typeof right === "number" && (right == 0 || right == 1)) {
|
|
283
|
+
if ((TreatNumberAsNullableBit || nullTreatedAsFalse) && typeof right === "number" && (right == 0 || right == 1)) {
|
|
262
284
|
|
|
263
285
|
if (Array.isArray(comparison[0])) {
|
|
264
286
|
return [
|
|
@@ -580,6 +602,21 @@ function DevExpressConverter() {
|
|
|
580
602
|
|
|
581
603
|
if ((left !== null && isNaN(left)) || (right !== null && isNaN(right))) return null;
|
|
582
604
|
|
|
605
|
+
// With TreatNullAsFalse, a blank placeholder value ("") is unset, the same as NULL
|
|
606
|
+
if (TreatNullAsFalse) {
|
|
607
|
+
if (typeof left === "string" && left.trim() === "") left = null;
|
|
608
|
+
if (typeof right === "string" && right.trim() === "") right = null;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// With TreatNullAsFalse, NULL behaves like 0 / false / "" (NULL = 0 is true)
|
|
612
|
+
if (TreatNullAsFalse && (left === null) !== (right === null)) {
|
|
613
|
+
const other = left === null ? right : left;
|
|
614
|
+
if (other === 0 || other === false || other === "") {
|
|
615
|
+
if (operator === '=' || operator === '==') return true;
|
|
616
|
+
if (operator === '<>' || operator === '!=') return false;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
|
|
583
620
|
// NULL only equals NULL (NULL = 0 is false); use ISNULL(x, 0) to treat NULL as 0
|
|
584
621
|
if (left === null || right === null) {
|
|
585
622
|
if (operator === '=' || operator === '==') return left === right;
|
|
@@ -617,9 +654,10 @@ const devExpressConverter = DevExpressConverter();
|
|
|
617
654
|
* @param {boolean} options.enableShortCircuit - Enable or disable short-circuit evaluation
|
|
618
655
|
* @param {boolean} options.isValueNullShortCircuit - Enable or disable null short-circuit evaluation
|
|
619
656
|
* @param {boolean} options.treatNumberAsNullableBit - Enable or disable optional boolean with number conversion
|
|
657
|
+
* @param {boolean} options.treatNullAsFalse - Evaluate null as equal to 0 / false / "" during short-circuit evaluation
|
|
620
658
|
* @returns {Array|null} DevExpress format filter
|
|
621
659
|
*/
|
|
622
660
|
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);
|
|
661
|
+
const { enableShortCircuit = true, isValueNullShortCircuit = false, treatNumberAsNullableBit = false, treatNullAsFalse = false } = options;
|
|
662
|
+
return devExpressConverter.init(ast, resultObject, enableShortCircuit, isValueNullShortCircuit, treatNumberAsNullableBit, treatNullAsFalse);
|
|
625
663
|
}
|
|
@@ -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,
|
|
@@ -79,7 +80,10 @@
|
|
|
79
80
|
"SaleOrderDocument.CompanyID": 2,
|
|
80
81
|
"SaleOrderDocument.CompanyContact": 15,
|
|
81
82
|
"SaleOrderDocument.ParentCompanyID": 3,
|
|
82
|
-
"SaleOrderDocument.IsVehicle": "True"
|
|
83
|
+
"SaleOrderDocument.IsVehicle": "True",
|
|
84
|
+
"SaleOrderBlankVehicle.IsVehicle": "",
|
|
85
|
+
"PurchaseOrderDocument.CompanyID": 2,
|
|
86
|
+
"PurchaseOrderDocument.AllowSubDealer": null
|
|
83
87
|
},
|
|
84
88
|
"groups": [
|
|
85
89
|
{
|
|
@@ -976,19 +980,50 @@
|
|
|
976
980
|
],
|
|
977
981
|
"and",
|
|
978
982
|
[
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
983
|
+
[
|
|
984
|
+
"varID",
|
|
985
|
+
"=",
|
|
986
|
+
null,
|
|
987
|
+
{
|
|
988
|
+
"type": "ISNULL",
|
|
989
|
+
"position": "value",
|
|
990
|
+
"defaultValue": 0
|
|
991
|
+
},
|
|
992
|
+
null
|
|
993
|
+
],
|
|
994
|
+
"or",
|
|
995
|
+
[
|
|
996
|
+
[
|
|
997
|
+
"varID",
|
|
998
|
+
"=",
|
|
999
|
+
0
|
|
1000
|
+
],
|
|
1001
|
+
"or",
|
|
1002
|
+
[
|
|
1003
|
+
"varID",
|
|
1004
|
+
"=",
|
|
1005
|
+
null,
|
|
1006
|
+
{
|
|
1007
|
+
"type": "ISNULL",
|
|
1008
|
+
"position": "column",
|
|
1009
|
+
"defaultValue": 0
|
|
1010
|
+
},
|
|
1011
|
+
null
|
|
1012
|
+
],
|
|
1013
|
+
"or",
|
|
1014
|
+
[
|
|
1015
|
+
"varID",
|
|
1016
|
+
"=",
|
|
1017
|
+
false
|
|
1018
|
+
]
|
|
1019
|
+
]
|
|
988
1020
|
]
|
|
989
1021
|
],
|
|
990
|
-
"expectedSql":
|
|
991
|
-
|
|
1022
|
+
"expectedSql": [
|
|
1023
|
+
"ISNULL(\"ItemID\", 0) = 42",
|
|
1024
|
+
"AND ( \"varID\" = ISNULL(NULL, 0) OR ( \"varID\" = 0 OR ISNULL(\"varID\", 0) = 0 OR \"varID\" = 0 ) )"
|
|
1025
|
+
],
|
|
1026
|
+
"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
1027
|
},
|
|
993
1028
|
{
|
|
994
1029
|
"id": 56,
|
|
@@ -1129,6 +1164,173 @@
|
|
|
1129
1164
|
"AND \"EntityType\" = 1004"
|
|
1130
1165
|
],
|
|
1131
1166
|
"note": "IsVehicle resolves to the string \"True\": it must be evaluated as a boolean, so {IsVehicle}=0 is false and {IsVehicle}=1 is true, leaving only EntityType = 1004 from the last group."
|
|
1167
|
+
},
|
|
1168
|
+
{
|
|
1169
|
+
"id": 59,
|
|
1170
|
+
"input": "DocType IN ({SaleOrderDocument.AllowedDocType}) AND ((ISNULL(IsDealer,0)=0 AND CompanyID={SaleOrderDocument.CompanyID}) OR (ISNULL(IsDealer,0)=1 AND CompanyContact={SaleOrderDocument.CompanyContact} AND CompanyID={SaleOrderDocument.ParentCompanyID})) AND ({SaleOrderBlankVehicle.IsVehicle}=0 OR ({SaleOrderBlankVehicle.IsVehicle}=1 AND EntityType=1004))",
|
|
1171
|
+
"filter": [
|
|
1172
|
+
[
|
|
1173
|
+
[
|
|
1174
|
+
"DocType",
|
|
1175
|
+
"=",
|
|
1176
|
+
"10809"
|
|
1177
|
+
],
|
|
1178
|
+
"or",
|
|
1179
|
+
[
|
|
1180
|
+
"DocType",
|
|
1181
|
+
"=",
|
|
1182
|
+
"40927"
|
|
1183
|
+
]
|
|
1184
|
+
],
|
|
1185
|
+
"and",
|
|
1186
|
+
[
|
|
1187
|
+
[
|
|
1188
|
+
[
|
|
1189
|
+
[
|
|
1190
|
+
"IsDealer",
|
|
1191
|
+
"=",
|
|
1192
|
+
0
|
|
1193
|
+
],
|
|
1194
|
+
"or",
|
|
1195
|
+
[
|
|
1196
|
+
"IsDealer",
|
|
1197
|
+
"=",
|
|
1198
|
+
null,
|
|
1199
|
+
{
|
|
1200
|
+
"type": "ISNULL",
|
|
1201
|
+
"position": "column",
|
|
1202
|
+
"defaultValue": 0
|
|
1203
|
+
},
|
|
1204
|
+
null
|
|
1205
|
+
],
|
|
1206
|
+
"or",
|
|
1207
|
+
[
|
|
1208
|
+
"IsDealer",
|
|
1209
|
+
"=",
|
|
1210
|
+
false
|
|
1211
|
+
]
|
|
1212
|
+
],
|
|
1213
|
+
"and",
|
|
1214
|
+
[
|
|
1215
|
+
"CompanyID",
|
|
1216
|
+
"=",
|
|
1217
|
+
2
|
|
1218
|
+
]
|
|
1219
|
+
],
|
|
1220
|
+
"or",
|
|
1221
|
+
[
|
|
1222
|
+
[
|
|
1223
|
+
[
|
|
1224
|
+
[
|
|
1225
|
+
"IsDealer",
|
|
1226
|
+
"=",
|
|
1227
|
+
1,
|
|
1228
|
+
{
|
|
1229
|
+
"type": "ISNULL",
|
|
1230
|
+
"position": "column",
|
|
1231
|
+
"defaultValue": 0
|
|
1232
|
+
},
|
|
1233
|
+
1
|
|
1234
|
+
],
|
|
1235
|
+
"or",
|
|
1236
|
+
[
|
|
1237
|
+
"IsDealer",
|
|
1238
|
+
"=",
|
|
1239
|
+
true
|
|
1240
|
+
]
|
|
1241
|
+
],
|
|
1242
|
+
"and",
|
|
1243
|
+
[
|
|
1244
|
+
"CompanyContact",
|
|
1245
|
+
"=",
|
|
1246
|
+
15
|
|
1247
|
+
]
|
|
1248
|
+
],
|
|
1249
|
+
"and",
|
|
1250
|
+
[
|
|
1251
|
+
"CompanyID",
|
|
1252
|
+
"=",
|
|
1253
|
+
3
|
|
1254
|
+
]
|
|
1255
|
+
]
|
|
1256
|
+
]
|
|
1257
|
+
],
|
|
1258
|
+
"expectedSql": [
|
|
1259
|
+
"( \"DocType\" = N'10809' OR \"DocType\" = N'40927' )",
|
|
1260
|
+
"AND ( ( ( \"IsDealer\" = 0 OR ISNULL(\"IsDealer\", 0) = 0 OR \"IsDealer\" = 0 ) AND \"CompanyID\" = 2 )",
|
|
1261
|
+
"OR ( ( ( ISNULL(\"IsDealer\", 0) = 1 OR \"IsDealer\" = 1 ) AND \"CompanyContact\" = 15 ) AND \"CompanyID\" = 3 ) )"
|
|
1262
|
+
],
|
|
1263
|
+
"note": "IsVehicle resolves to a blank string: with treatNullAsFalse it is unset like null, so {IsVehicle}=0 is true and the whole last group is dropped. Before, \"\" = 0 and \"\" = 1 were both false, collapsing the filter to false (empty filter, all rows shown)."
|
|
1264
|
+
},
|
|
1265
|
+
{
|
|
1266
|
+
"id": 60,
|
|
1267
|
+
"input": "(CompanyID = {PurchaseOrderDocument.CompanyID} OR {PurchaseOrderDocument.CompanyID} = 0 OR ISNULL(CompanyID,0) = 0) AND (ISNULL(IsSubdealer,0) = {PurchaseOrderDocument.AllowSubDealer})",
|
|
1268
|
+
"filter": [
|
|
1269
|
+
[
|
|
1270
|
+
[
|
|
1271
|
+
"CompanyID",
|
|
1272
|
+
"=",
|
|
1273
|
+
2
|
|
1274
|
+
],
|
|
1275
|
+
"or",
|
|
1276
|
+
[
|
|
1277
|
+
[
|
|
1278
|
+
"CompanyID",
|
|
1279
|
+
"=",
|
|
1280
|
+
0
|
|
1281
|
+
],
|
|
1282
|
+
"or",
|
|
1283
|
+
[
|
|
1284
|
+
"CompanyID",
|
|
1285
|
+
"=",
|
|
1286
|
+
null,
|
|
1287
|
+
{
|
|
1288
|
+
"type": "ISNULL",
|
|
1289
|
+
"position": "column",
|
|
1290
|
+
"defaultValue": 0
|
|
1291
|
+
},
|
|
1292
|
+
null
|
|
1293
|
+
],
|
|
1294
|
+
"or",
|
|
1295
|
+
[
|
|
1296
|
+
"CompanyID",
|
|
1297
|
+
"=",
|
|
1298
|
+
false
|
|
1299
|
+
]
|
|
1300
|
+
]
|
|
1301
|
+
],
|
|
1302
|
+
"and",
|
|
1303
|
+
[
|
|
1304
|
+
[
|
|
1305
|
+
"IsSubdealer",
|
|
1306
|
+
"=",
|
|
1307
|
+
0
|
|
1308
|
+
],
|
|
1309
|
+
"or",
|
|
1310
|
+
[
|
|
1311
|
+
"IsSubdealer",
|
|
1312
|
+
"=",
|
|
1313
|
+
null,
|
|
1314
|
+
{
|
|
1315
|
+
"type": "ISNULL",
|
|
1316
|
+
"position": "column",
|
|
1317
|
+
"defaultValue": 0
|
|
1318
|
+
},
|
|
1319
|
+
null
|
|
1320
|
+
],
|
|
1321
|
+
"or",
|
|
1322
|
+
[
|
|
1323
|
+
"IsSubdealer",
|
|
1324
|
+
"=",
|
|
1325
|
+
false
|
|
1326
|
+
]
|
|
1327
|
+
]
|
|
1328
|
+
],
|
|
1329
|
+
"expectedSql": [
|
|
1330
|
+
"( \"CompanyID\" = 2 OR ( \"CompanyID\" = 0 OR ISNULL(\"CompanyID\", 0) = 0 OR \"CompanyID\" = 0 ) )",
|
|
1331
|
+
"AND ( \"IsSubdealer\" = 0 OR ISNULL(\"IsSubdealer\", 0) = 0 OR \"IsSubdealer\" = 0 )"
|
|
1332
|
+
],
|
|
1333
|
+
"note": "AllowSubDealer is null: with treatNullAsFalse, ISNULL(IsSubdealer,0) = {AllowSubDealer} compares against 0, matching IsSubdealer 0 / false / NULL. Before, it emitted IsSubdealer = null, which matched only NULL rows and dropped IsSubdealer = false."
|
|
1132
1334
|
}
|
|
1133
1335
|
]
|
|
1134
1336
|
},
|
|
@@ -1576,4 +1778,4 @@
|
|
|
1576
1778
|
]
|
|
1577
1779
|
}
|
|
1578
1780
|
]
|
|
1579
|
-
}
|
|
1781
|
+
}
|