sqlparser-devexpress 2.4.0 → 2.4.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 +1 -1
- package/src/core/converter.js +21 -4
- package/src/debug.js +1 -1
- package/tests/parser.test.js +30 -0
package/package.json
CHANGED
package/src/core/converter.js
CHANGED
|
@@ -111,8 +111,8 @@ function DevExpressConverter() {
|
|
|
111
111
|
|
|
112
112
|
// Detect and flatten nested logical expressions
|
|
113
113
|
if (parentOperator === null) {
|
|
114
|
-
if (left.length === 3 && LOGICAL_OPERATORS.includes(left[1])) parentOperator = left[1];
|
|
115
|
-
if (right.length === 3 && LOGICAL_OPERATORS.includes(right[1])) parentOperator = right[1];
|
|
114
|
+
if (left && left.length === 3 && LOGICAL_OPERATORS.includes(left[1])) parentOperator = left[1];
|
|
115
|
+
if (right && right.length === 3 && LOGICAL_OPERATORS.includes(right[1])) parentOperator = right[1];
|
|
116
116
|
}
|
|
117
117
|
|
|
118
118
|
// Flatten nested logical expressions if applicable
|
|
@@ -160,14 +160,31 @@ function DevExpressConverter() {
|
|
|
160
160
|
includeExtradata = true;
|
|
161
161
|
}
|
|
162
162
|
let comparison = [left, operatorToken, right];
|
|
163
|
+
|
|
163
164
|
if (includeExtradata)
|
|
164
165
|
comparison = [left, operatorToken, right, { type: originalOperator }, right];
|
|
165
166
|
|
|
166
167
|
// 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
|
|
167
168
|
if ((ast.left && isFunctionNullCheck(ast.left, true)) || (ast.value && isFunctionNullCheck(ast.value, false))) {
|
|
168
|
-
|
|
169
|
+
const nullCheckArg = (ast.left ?? ast.value).args[1]?.value;
|
|
170
|
+
let baseComparison = comparison;
|
|
171
|
+
|
|
172
|
+
if (Array.isArray(right) && (right.includes("or") || right.includes("and"))) {
|
|
173
|
+
const valueRight = right.shift();
|
|
174
|
+
baseComparison = [[left, operatorToken, valueRight], ...right];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
comparison = [baseComparison, 'or', [left, operatorToken, null, { type: "ISNULL", defaultValue: nullCheckArg }, null]];
|
|
169
178
|
} else if (ast.right && isFunctionNullCheck(ast.right, true)) {
|
|
170
|
-
|
|
179
|
+
const nullCheckArg = ast.right.args[1]?.value;
|
|
180
|
+
let baseComparison = comparison;
|
|
181
|
+
|
|
182
|
+
if (Array.isArray(right) && (right.includes("or") || right.includes("and"))) {
|
|
183
|
+
const valueRight = right.shift();
|
|
184
|
+
baseComparison = [[left, operatorToken, valueRight], ...right];
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
comparison = [baseComparison, 'or', [right, operatorToken, null, { type: "ISNULL", defaultValue: nullCheckArg }, null]];
|
|
171
188
|
}
|
|
172
189
|
|
|
173
190
|
// Apply short-circuit evaluation if enabled
|
package/src/debug.js
CHANGED
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
// return convertToDevExpressFormat({ ast: astTree, resultObject: sampleData, isValueNullShortCircuit: true });
|
|
29
29
|
// }
|
|
30
30
|
|
|
31
|
-
// const devexpress = parseFilterString("
|
|
31
|
+
// const devexpress = parseFilterString("ISNULL(CompanyID,0) = ISNULL({CustomerOrders.OrderID},0) OR (ISNULL(CompanyID,0) = 0)", sampleData);
|
|
32
32
|
// console.log("DevExpress Filter:", JSON.stringify(devexpress, null, 2));
|
|
33
33
|
// // const devexpress = parseFilterString("(RS2ID in ({LeadStatementGlobalRpt.StateID}) Or ({LeadStatementGlobalRpt.StateID} =0)) And (RS3ID in (0,{LeadStatementGlobalRpt.RegionID}) Or {LeadStatementGlobalRpt.RegionID} =0 )", sampleData);
|
|
34
34
|
|
package/tests/parser.test.js
CHANGED
|
@@ -302,6 +302,36 @@ describe("Parser SQL to dx Filter Builder", () => {
|
|
|
302
302
|
"or",
|
|
303
303
|
["IsChecked", "=", true]
|
|
304
304
|
]
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
input: "ISNULL(CompanyID,0) = ISNULL({TransferOutwardDocument.CompanyID},0) OR (ISNULL(CompanyID,0) = 0)",
|
|
308
|
+
expected: [
|
|
309
|
+
[
|
|
310
|
+
|
|
311
|
+
["CompanyID", "=", 7],
|
|
312
|
+
"or",
|
|
313
|
+
[
|
|
314
|
+
["CompanyID", "=", 0],
|
|
315
|
+
"or",
|
|
316
|
+
["CompanyID", "=", null,
|
|
317
|
+
{
|
|
318
|
+
"type": "ISNULL",
|
|
319
|
+
"defaultValue": 0
|
|
320
|
+
}, null
|
|
321
|
+
],
|
|
322
|
+
"or",
|
|
323
|
+
["CompanyID", "=", false]
|
|
324
|
+
]
|
|
325
|
+
],
|
|
326
|
+
"or",
|
|
327
|
+
[
|
|
328
|
+
"CompanyID", "=", null,
|
|
329
|
+
{
|
|
330
|
+
"type": "ISNULL",
|
|
331
|
+
"defaultValue": 0
|
|
332
|
+
}, null
|
|
333
|
+
]
|
|
334
|
+
]
|
|
305
335
|
}
|
|
306
336
|
];
|
|
307
337
|
|