sqlparser-devexpress 2.3.8 → 2.3.10
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 +21 -10
- package/tests/parser.test.js +14 -10
package/package.json
CHANGED
package/src/core/converter.js
CHANGED
|
@@ -135,7 +135,9 @@ function DevExpressConverter() {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
const left = ast.left !== undefined ? processAstNode(ast.left) : convertValue(ast.field);
|
|
138
|
+
const leftDefault = ast.left?.args[1]?.value;
|
|
138
139
|
const right = ast.right !== undefined ? processAstNode(ast.right) : convertValue(ast.value);
|
|
140
|
+
const rightDefault = ast.right?.args[1]?.value;
|
|
139
141
|
let operatorToken = ast.operator.toLowerCase();
|
|
140
142
|
|
|
141
143
|
if (operatorToken === "like") {
|
|
@@ -146,17 +148,17 @@ function DevExpressConverter() {
|
|
|
146
148
|
|
|
147
149
|
let comparison = [left, operatorToken, right];
|
|
148
150
|
|
|
149
|
-
//
|
|
151
|
+
// 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
|
|
150
152
|
if ((ast.left && isFunctionNullCheck(ast.left, true)) || (ast.value && isFunctionNullCheck(ast.value, false))) {
|
|
151
|
-
comparison = [[left, operatorToken, right], 'or', [left, operatorToken, null,
|
|
153
|
+
comparison = [[left, operatorToken, right], 'or', [left, operatorToken, null, { type: "ISNULL", defaultValue: (ast.left ?? ast.value).args[1]?.value }, null]];
|
|
152
154
|
} else if (ast.right && isFunctionNullCheck(ast.right, true)) {
|
|
153
|
-
comparison = [[left, operatorToken, right], 'or', [right, operatorToken, null,
|
|
155
|
+
comparison = [[left, operatorToken, right], 'or', [right, operatorToken, null, { type: "ISNULL", defaultValue: ast.right.args[1]?.value }, null]];
|
|
154
156
|
}
|
|
155
157
|
|
|
156
158
|
// Apply short-circuit evaluation if enabled
|
|
157
159
|
if (EnableShortCircuit) {
|
|
158
|
-
if (isAlwaysTrue(comparison)) return true;
|
|
159
|
-
if (isAlwaysFalse(comparison)) return false;
|
|
160
|
+
if (isAlwaysTrue(comparison, leftDefault, rightDefault)) return true;
|
|
161
|
+
if (isAlwaysFalse(comparison, leftDefault, rightDefault)) return false;
|
|
160
162
|
}
|
|
161
163
|
|
|
162
164
|
return comparison;
|
|
@@ -332,19 +334,23 @@ function DevExpressConverter() {
|
|
|
332
334
|
/**
|
|
333
335
|
* Checks if a condition is always true.
|
|
334
336
|
* @param {Array} condition - The condition to check.
|
|
337
|
+
* @param {*} leftDefault - The default value for the left operand.
|
|
338
|
+
* @param {*} rightDefault - The default value for the right operand.
|
|
335
339
|
* @returns {boolean} True if the condition is always true.
|
|
336
340
|
*/
|
|
337
|
-
function isAlwaysTrue(condition) {
|
|
338
|
-
return Array.isArray(condition) && condition.length >= 3 && evaluateExpression(...condition) == true;
|
|
341
|
+
function isAlwaysTrue(condition, leftDefault, rightDefault) {
|
|
342
|
+
return Array.isArray(condition) && condition.length >= 3 && evaluateExpression(...condition, leftDefault, rightDefault) == true;
|
|
339
343
|
}
|
|
340
344
|
|
|
341
345
|
/**
|
|
342
346
|
* Checks if a condition is always false.
|
|
343
347
|
* @param {Array} condition - The condition to check.
|
|
348
|
+
* @param {*} leftDefault - The default value for the left operand.
|
|
349
|
+
* @param {*} rightDefault - The default value for the right operand.
|
|
344
350
|
* @returns {boolean} True if the condition is always false.
|
|
345
351
|
*/
|
|
346
|
-
function isAlwaysFalse(condition) {
|
|
347
|
-
return Array.isArray(condition) && condition.length >= 3 && evaluateExpression(...condition) == false;
|
|
352
|
+
function isAlwaysFalse(condition, leftDefault, rightDefault) {
|
|
353
|
+
return Array.isArray(condition) && condition.length >= 3 && evaluateExpression(...condition, leftDefault, rightDefault) == false;
|
|
348
354
|
}
|
|
349
355
|
|
|
350
356
|
/**
|
|
@@ -352,9 +358,14 @@ function DevExpressConverter() {
|
|
|
352
358
|
* @param {*} left - The left operand.
|
|
353
359
|
* @param {string} operator - The operator.
|
|
354
360
|
* @param {*} right - The right operand.
|
|
361
|
+
* @param {*} leftDefault - The default value for the left operand.
|
|
362
|
+
* @param {*} rightDefault - The default value for the right
|
|
355
363
|
* @returns {boolean|null} The result of the evaluation or null if not evaluable.
|
|
356
364
|
*/
|
|
357
|
-
function evaluateExpression(left, operator, right) {
|
|
365
|
+
function evaluateExpression(left, operator, right, leftDefault, rightDefault) {
|
|
366
|
+
if (left == null && leftDefault != undefined) left = leftDefault;
|
|
367
|
+
if (right == null && rightDefault != undefined) right = rightDefault;
|
|
368
|
+
|
|
358
369
|
if ((left !== null && isNaN(left)) || (right !== null && isNaN(right))) return null;
|
|
359
370
|
|
|
360
371
|
if (left === null || right === null) {
|
package/tests/parser.test.js
CHANGED
|
@@ -137,11 +137,11 @@ describe("Parser SQL to dx Filter Builder", () => {
|
|
|
137
137
|
expected: [
|
|
138
138
|
["SourceID", "=", 2],
|
|
139
139
|
"or",
|
|
140
|
-
["SourceID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}],
|
|
140
|
+
["SourceID", "=", null, { "defaultValue": 0, "type": "ISNULL" }, null],
|
|
141
141
|
"or",
|
|
142
142
|
["SourceID", "=", 0],
|
|
143
143
|
"or",
|
|
144
|
-
["SourceID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}]
|
|
144
|
+
["SourceID", "=", null, { "defaultValue": 0, "type": "ISNULL" }, null]
|
|
145
145
|
]
|
|
146
146
|
},
|
|
147
147
|
{
|
|
@@ -153,14 +153,14 @@ describe("Parser SQL to dx Filter Builder", () => {
|
|
|
153
153
|
[
|
|
154
154
|
["CompanyID", "=", 0],
|
|
155
155
|
"or",
|
|
156
|
-
["CompanyID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}]
|
|
156
|
+
["CompanyID", "=", null, { "defaultValue": 0, "type": "ISNULL" }, null]
|
|
157
157
|
]
|
|
158
158
|
],
|
|
159
159
|
"and",
|
|
160
160
|
[
|
|
161
161
|
["IsSubdealer", "=", true],
|
|
162
162
|
"or",
|
|
163
|
-
["IsSubdealer", "=", null,{ "defaultValue": 0, "type": "ISNULL"}]
|
|
163
|
+
["IsSubdealer", "=", null, { "defaultValue": 0, "type": "ISNULL" }, null]
|
|
164
164
|
]
|
|
165
165
|
]
|
|
166
166
|
},
|
|
@@ -187,7 +187,7 @@ describe("Parser SQL to dx Filter Builder", () => {
|
|
|
187
187
|
expected: [
|
|
188
188
|
["TicketID", "=", 123],
|
|
189
189
|
"or",
|
|
190
|
-
["TicketID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}]
|
|
190
|
+
["TicketID", "=", null, { "defaultValue": 0, "type": "ISNULL" }, null]
|
|
191
191
|
]
|
|
192
192
|
},
|
|
193
193
|
{
|
|
@@ -195,14 +195,12 @@ describe("Parser SQL to dx Filter Builder", () => {
|
|
|
195
195
|
expected: [
|
|
196
196
|
["CompanyID", "=", 7],
|
|
197
197
|
"or",
|
|
198
|
-
["CompanyID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}],
|
|
198
|
+
["CompanyID", "=", null, { "defaultValue": 0, "type": "ISNULL" }, null],
|
|
199
199
|
"or",
|
|
200
200
|
["CompanyID", "=", 0],
|
|
201
201
|
"or",
|
|
202
|
-
["CompanyID", "=", null,{ "defaultValue": 0, "type": "ISNULL"},
|
|
202
|
+
["CompanyID", "=", null, { "defaultValue": 0, "type": "ISNULL" }, null]
|
|
203
203
|
|
|
204
|
-
]
|
|
205
|
-
|
|
206
204
|
]
|
|
207
205
|
},
|
|
208
206
|
{
|
|
@@ -212,6 +210,10 @@ describe("Parser SQL to dx Filter Builder", () => {
|
|
|
212
210
|
"and",
|
|
213
211
|
["BranchName", "notcontains", "42"]
|
|
214
212
|
]
|
|
213
|
+
},
|
|
214
|
+
{
|
|
215
|
+
input: "(RS2ID in ({SaleOrderStatusStmtGlobalRpt.StateID}) Or (ISNULL({SaleOrderStatusStmtGlobalRpt.StateID},0) =0)) And (RS3ID in (0,{SaleOrderStatusStmtGlobalRpt.RegionID}) Or ISNULL({SaleOrderStatusStmtGlobalRpt.RegionID},0) =0 )",
|
|
216
|
+
expected: []
|
|
215
217
|
}
|
|
216
218
|
];
|
|
217
219
|
|
|
@@ -272,5 +274,7 @@ const sampleData = {
|
|
|
272
274
|
"LeadDocument.CompanyID": 7,
|
|
273
275
|
"ServiceOrderDocument.SourceID": 2,
|
|
274
276
|
"LeadDocument.AllowSubDealer": true,
|
|
275
|
-
"SupportResolution.TicketID": 123
|
|
277
|
+
"SupportResolution.TicketID": 123,
|
|
278
|
+
"SaleOrderStatusStmtGlobalRpt.StateID": null,
|
|
279
|
+
"SaleOrderStatusStmtGlobalRpt.RegionID": null,
|
|
276
280
|
};
|