diff --git a/package.json b/package.json index 8c1cebf..3ac5753 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sqlparser-devexpress", - "version": "2.3.3", + "version": "2.3.4", "main": "src/index.js", "type": "module", "scripts": { diff --git a/src/core/converter.js b/src/core/converter.js index 078fbff..7b12e24 100644 --- a/src/core/converter.js +++ b/src/core/converter.js @@ -141,9 +141,9 @@ function DevExpressConverter() { let comparison = [left, operatorToken, right]; if ((ast.left && isFunctionNullCheck(ast.left, true)) || (ast.value && isFunctionNullCheck(ast.value, false))) { - comparison = [[left, operatorToken, right], 'or', [left, operatorToken, null]]; + comparison = [[left, operatorToken, right], 'or', [left, operatorToken, null, {type: "ISNULL", defaultValue: (ast.left ?? ast.value).args[1]?.value}]]; } else if (ast.right && isFunctionNullCheck(ast.right, true)) { - comparison = [[left, operatorToken, right], 'or', [right, operatorToken, null]]; + comparison = [[left, operatorToken, right], 'or', [right, operatorToken, null, {type: "ISNULL", defaultValue: ast.right.args[1]?.value}]]; } // Apply short-circuit evaluation if enabled @@ -322,7 +322,7 @@ function DevExpressConverter() { * @returns {boolean} True if the condition is always true. */ function isAlwaysTrue(condition) { - return Array.isArray(condition) && condition.length === 3 && evaluateExpression(...condition) == true; + return Array.isArray(condition) && condition.length >= 3 && evaluateExpression(...condition) == true; } /** @@ -331,7 +331,7 @@ function DevExpressConverter() { * @returns {boolean} True if the condition is always false. */ function isAlwaysFalse(condition) { - return Array.isArray(condition) && condition.length === 3 && evaluateExpression(...condition) == false; + return Array.isArray(condition) && condition.length >= 3 && evaluateExpression(...condition) == false; } /** diff --git a/tests/parser.test.js b/tests/parser.test.js index 2c44580..dfd8d1c 100644 --- a/tests/parser.test.js +++ b/tests/parser.test.js @@ -137,11 +137,11 @@ describe("Parser SQL to dx Filter Builder", () => { expected: [ ["SourceID", "=", 2], "or", - ["SourceID", "=", null], + ["SourceID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}], "or", ["SourceID", "=", 0], "or", - ["SourceID", "=", null] + ["SourceID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}] ] }, { @@ -153,14 +153,14 @@ describe("Parser SQL to dx Filter Builder", () => { [ ["CompanyID", "=", 0], "or", - ["CompanyID", "=", null] + ["CompanyID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}] ] ], "and", [ ["IsSubdealer", "=", true], "or", - ["IsSubdealer", "=", null] + ["IsSubdealer", "=", null,{ "defaultValue": 0, "type": "ISNULL"}] ] ] }, @@ -187,7 +187,7 @@ describe("Parser SQL to dx Filter Builder", () => { expected: [ ["TicketID", "=", 123], "or", - ["TicketID", "=", null] + ["TicketID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}] ] }, { @@ -195,11 +195,13 @@ describe("Parser SQL to dx Filter Builder", () => { expected: [ ["CompanyID", "=", 7], "or", - ["CompanyID", "=", null], + ["CompanyID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}], "or", ["CompanyID", "=", 0], "or", - ["CompanyID", "=", null] + ["CompanyID", "=", null,{ "defaultValue": 0, "type": "ISNULL"}, + + ] ] }