sqlparser-devexpress 2.6.2 → 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sqlparser-devexpress",
3
- "version": "2.6.2",
3
+ "version": "2.6.3",
4
4
  "main": "src/index.js",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -151,18 +151,37 @@ function DevExpressConverter() {
151
151
 
152
152
  const left = ast.left !== undefined ? processAstNode(ast.left) : convertValue(ast.field);
153
153
  const leftDefault = ast.left?.args && ast.left?.args[1]?.value;
154
- const right = ast.right !== undefined ? processAstNode(ast.right) : convertValue(ast.value);
154
+ let right = ast.right !== undefined ? processAstNode(ast.right) : convertValue(ast.value);
155
155
  const rightDefault = ast.right?.args && ast.right?.args[1]?.value;
156
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
+
157
171
  // Short-circuit when ISNULL's first arg is a placeholder (resolved concrete value, not a column).
158
172
  // evaluateExpression cannot handle non-numeric string comparisons (e.g. "INV1" = ""),
159
173
  // so detect and short-circuit here before any ISNULL column-null handling runs.
160
174
  if (EnableShortCircuit && ast.left?.type === "function" && ast.left?.name === "ISNULL" &&
161
175
  ast.left?.args?.[0]?.value?.type === "placeholder") {
162
- if (IsValueNullShortCircuit && (left === null || right === null)) return true;
163
- if (left !== null && right !== null) {
164
- const normalL = normalizeBool(left);
165
- const normalR = normalizeBool(right);
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));
166
185
  return normalL === normalR ? true : false;
167
186
  }
168
187
  }
@@ -261,7 +280,7 @@ function DevExpressConverter() {
261
280
  if (isAlwaysFalse(comparison, leftDefault, rightDefault)) return false;
262
281
  }
263
282
 
264
- if (TreatNumberAsNullableBit && typeof right === "number" && (right == 0 || right == 1)) {
283
+ if ((TreatNumberAsNullableBit || nullTreatedAsFalse) && typeof right === "number" && (right == 0 || right == 1)) {
265
284
 
266
285
  if (Array.isArray(comparison[0])) {
267
286
  return [
@@ -583,6 +602,12 @@ function DevExpressConverter() {
583
602
 
584
603
  if ((left !== null && isNaN(left)) || (right !== null && isNaN(right))) return null;
585
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
+
586
611
  // With TreatNullAsFalse, NULL behaves like 0 / false / "" (NULL = 0 is true)
587
612
  if (TreatNullAsFalse && (left === null) !== (right === null)) {
588
613
  const other = left === null ? right : left;
@@ -80,7 +80,10 @@
80
80
  "SaleOrderDocument.CompanyID": 2,
81
81
  "SaleOrderDocument.CompanyContact": 15,
82
82
  "SaleOrderDocument.ParentCompanyID": 3,
83
- "SaleOrderDocument.IsVehicle": "True"
83
+ "SaleOrderDocument.IsVehicle": "True",
84
+ "SaleOrderBlankVehicle.IsVehicle": "",
85
+ "PurchaseOrderDocument.CompanyID": 2,
86
+ "PurchaseOrderDocument.AllowSubDealer": null
84
87
  },
85
88
  "groups": [
86
89
  {
@@ -1161,6 +1164,173 @@
1161
1164
  "AND \"EntityType\" = 1004"
1162
1165
  ],
1163
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."
1164
1334
  }
1165
1335
  ]
1166
1336
  },
@@ -1608,4 +1778,4 @@
1608
1778
  ]
1609
1779
  }
1610
1780
  ]
1611
- }
1781
+ }