sqlparser-devexpress 2.6.0 → 2.6.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlparser-devexpress",
3
- "version": "2.6.0",
3
+ "version": "2.6.1",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -291,6 +291,27 @@ function DevExpressConverter() {
291
291
  return value === 0 || value === 1 ? Boolean(value) : value;
292
292
  }
293
293
 
294
+ /**
295
+ * Converts boolean and numeric strings to their literal values.
296
+ *
297
+ * "true"/"false" (case-insensitive) become booleans and numeric strings become numbers.
298
+ * Empty strings and any other value are returned unchanged.
299
+ *
300
+ * @param {*} value - The value to normalize.
301
+ * @returns {*} - The literal value, or the original value if it is not a boolean or numeric string.
302
+ */
303
+ function normalizeLiteralString(value) {
304
+ if (typeof value !== "string") return value;
305
+
306
+ const trimmed = value.trim();
307
+ const lower = trimmed.toLowerCase();
308
+ if (lower === "true") return true;
309
+ if (lower === "false") return false;
310
+ if (trimmed !== "" && !isNaN(trimmed)) return Number(trimmed);
311
+
312
+ return value;
313
+ }
314
+
294
315
 
295
316
  /**
296
317
  * Handles function calls, focusing on ISNULL.
@@ -553,6 +574,10 @@ function DevExpressConverter() {
553
574
  if (left == null && leftDefault != undefined) left = leftDefault;
554
575
  if (right == null && rightDefault != undefined) right = rightDefault;
555
576
 
577
+ // Placeholders may resolve to strings like "1", "0", "true" or "False"
578
+ left = normalizeLiteralString(left);
579
+ right = normalizeLiteralString(right);
580
+
556
581
  if ((left !== null && isNaN(left)) || (right !== null && isNaN(right))) return null;
557
582
 
558
583
  // NULL only equals NULL (NULL = 0 is false); use ISNULL(x, 0) to treat NULL as 0
@@ -74,7 +74,12 @@
74
74
  "QuoteDocument.IsVehicle": true,
75
75
  "PurchaseOrderLine.ItemID": 42,
76
76
  "PurchaseOrderLine.VarMatrixID0": null,
77
- "PurchaseOrderLine.VarMatrixID1": 5
77
+ "PurchaseOrderLine.VarMatrixID1": 5,
78
+ "SaleOrderDocument.AllowedDocType": "10809,40927",
79
+ "SaleOrderDocument.CompanyID": 2,
80
+ "SaleOrderDocument.CompanyContact": 15,
81
+ "SaleOrderDocument.ParentCompanyID": 3,
82
+ "SaleOrderDocument.IsVehicle": "True"
78
83
  },
79
84
  "groups": [
80
85
  {
@@ -1020,6 +1025,110 @@
1020
1025
  ],
1021
1026
  "expectedSql": "\"ItemID\" = 42",
1022
1027
  "note": "A null variable compared with a value is evaluated: null = 5 is false, so the AND group is dropped from the OR."
1028
+ },
1029
+ {
1030
+ "id": 58,
1031
+ "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 ({SaleOrderDocument.IsVehicle}=0 OR ({SaleOrderDocument.IsVehicle}=1 AND EntityType=1004))",
1032
+ "filter": [
1033
+ [
1034
+ [
1035
+ "DocType",
1036
+ "=",
1037
+ "10809"
1038
+ ],
1039
+ "or",
1040
+ [
1041
+ "DocType",
1042
+ "=",
1043
+ "40927"
1044
+ ]
1045
+ ],
1046
+ "and",
1047
+ [
1048
+ [
1049
+ [
1050
+ [
1051
+ "IsDealer",
1052
+ "=",
1053
+ 0
1054
+ ],
1055
+ "or",
1056
+ [
1057
+ "IsDealer",
1058
+ "=",
1059
+ null,
1060
+ {
1061
+ "type": "ISNULL",
1062
+ "position": "column",
1063
+ "defaultValue": 0
1064
+ },
1065
+ null
1066
+ ],
1067
+ "or",
1068
+ [
1069
+ "IsDealer",
1070
+ "=",
1071
+ false
1072
+ ]
1073
+ ],
1074
+ "and",
1075
+ [
1076
+ "CompanyID",
1077
+ "=",
1078
+ 2
1079
+ ]
1080
+ ],
1081
+ "or",
1082
+ [
1083
+ [
1084
+ [
1085
+ [
1086
+ "IsDealer",
1087
+ "=",
1088
+ 1,
1089
+ {
1090
+ "type": "ISNULL",
1091
+ "position": "column",
1092
+ "defaultValue": 0
1093
+ },
1094
+ 1
1095
+ ],
1096
+ "or",
1097
+ [
1098
+ "IsDealer",
1099
+ "=",
1100
+ true
1101
+ ]
1102
+ ],
1103
+ "and",
1104
+ [
1105
+ "CompanyContact",
1106
+ "=",
1107
+ 15
1108
+ ]
1109
+ ],
1110
+ "and",
1111
+ [
1112
+ "CompanyID",
1113
+ "=",
1114
+ 3
1115
+ ]
1116
+ ]
1117
+ ],
1118
+ "and",
1119
+ [
1120
+ "EntityType",
1121
+ "=",
1122
+ 1004
1123
+ ]
1124
+ ],
1125
+ "expectedSql": [
1126
+ "( \"DocType\" = N'10809' OR \"DocType\" = N'40927' )",
1127
+ "AND ( ( ( \"IsDealer\" = 0 OR ISNULL(\"IsDealer\", 0) = 0 OR \"IsDealer\" = 0 ) AND \"CompanyID\" = 2 )",
1128
+ "OR ( ( ( ISNULL(\"IsDealer\", 0) = 1 OR \"IsDealer\" = 1 ) AND \"CompanyContact\" = 15 ) AND \"CompanyID\" = 3 ) )",
1129
+ "AND \"EntityType\" = 1004"
1130
+ ],
1131
+ "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."
1023
1132
  }
1024
1133
  ]
1025
1134
  },