sqlparser-devexpress 2.5.8 → 2.6.0

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.
@@ -0,0 +1,1470 @@
1
+ {
2
+ "$comment": [
3
+ "Shared test cases for both projects:",
4
+ " JS (SQLParser) tests/parser.test.js : input + variables -> convertSQLToAst/convertAstToDevextreme -> must equal 'filter'",
5
+ " C# (SQLParserTests) DevexpressFilterParserTests : 'filter' -> DevexpressFilterParser.ParseFilterQuery -> must equal 'expectedSql'",
6
+ "",
7
+ "Each case:",
8
+ " id - unique case number (shown in both test runners).",
9
+ " input - original SQL given to the JS converter (documentation only). String, or array of lines.",
10
+ " filter - DevExtreme filter the JS converter must produce for 'input' (null = convertSQLToAst returns null).",
11
+ " [column, op, value] or [column, op, value, options, rawValue]; groups are [cond, 'and'|'or', cond, ...].",
12
+ " expectedSql - SQL the C# parser must produce. String, or array of lines joined with a single space.",
13
+ " note - optional explanation of non-obvious behaviour.",
14
+ " skip - optional { \"js\" | \"csharp\": \"reason\" } to skip the case in one test runner.",
15
+ "",
16
+ "SQL conventions: identifiers are double-quoted, strings are N'...', booleans become 1/0,",
17
+ "'= null' becomes IS NULL, and nested groups are wrapped as '( ... )'."
18
+ ],
19
+ "converterOptions": {
20
+ "isValueNullShortCircuit": true,
21
+ "treatNumberAsNullableBit": true
22
+ },
23
+ "variables": {
24
+ "SingleStepTransferDocument.CompanyID": 2,
25
+ "SingleStepTransferDocument.AllowedSubdealer": false,
26
+ "Example.ZeroValue": 0,
27
+ "CoreEntity0022.CompanyGroupID": 42,
28
+ "CoreEntity0022.BranchID": 7,
29
+ "Employee.District": 0,
30
+ "Employee.BranchID": 7,
31
+ "SaleInvoiceDocument.ContactID": 42,
32
+ "SaleInvoiceDocument.BranchID": 7,
33
+ "AccountingRule.CompanyID": 42,
34
+ "AccountingRule.BranchID": 7,
35
+ "Area.AreaType": 42,
36
+ "Area.BranchID": 7,
37
+ "Item.ID": 42,
38
+ "Item.BranchID": 7,
39
+ "Item.AllowedItemGroupType": "1,2",
40
+ "Item.AllowedItemGroupTypeOne": "1",
41
+ "WorkOrderLine.ApplicableUoms": [
42
+ "UOM1",
43
+ "UOM2",
44
+ "UOM3"
45
+ ],
46
+ "WorkOrderLine.CompanyID": 2,
47
+ "WorkOrderDocument.CompanyID": 42,
48
+ "WorkOrderDocument.BranchID": 7,
49
+ "TransferOutwardDocument.DocDate": "2022-01-01",
50
+ "TransferOutwardDocument.RefBranchID": 42,
51
+ "TransferOutwardDocument.CompanyID": 7,
52
+ "LeadDocument.BranchID": 42,
53
+ "LeadDocument.CompanyID": 7,
54
+ "ServiceOrderDocument.SourceID": 2,
55
+ "LeadDocument.AllowSubDealer": true,
56
+ "SupportResolution.TicketID": 123,
57
+ "SaleOrderStatusStmtGlobalRpt.StateID": null,
58
+ "SaleOrderStatusStmtGlobalRpt.RegionID": null,
59
+ "WorkOrderLine.CompanyIDs": [
60
+ "0,1"
61
+ ],
62
+ "PurchaseOrderDocument.IsMultiBrand": false,
63
+ "PurchaseOrderDocument.AllowedApplicableMake": "0",
64
+ "SampleDoc.AuthFilterID": "ID",
65
+ "ItemPrice.AllowedItemGroupType": "1,2",
66
+ "ItemPrice.AllowedNonStock": 1,
67
+ "ItemPrice.CompanyID": 7,
68
+ "AdjustmentDocument.BranchID": 42,
69
+ "AdjustmentDocument.CompanyID": 7,
70
+ "AdjustmentDocument.IsFromInvoice": true,
71
+ "AdjustmentDocument.SupplierInvoiceNos": "INV1",
72
+ "QuoteDocument.AllowedDocType": "10809,40927",
73
+ "QuoteDocument.CompanyID": 2,
74
+ "QuoteDocument.IsVehicle": true,
75
+ "PurchaseOrderLine.ItemID": 42,
76
+ "PurchaseOrderLine.VarMatrixID0": null,
77
+ "PurchaseOrderLine.VarMatrixID1": 5
78
+ },
79
+ "groups": [
80
+ {
81
+ "name": "Simple comparisons",
82
+ "cases": [
83
+ {
84
+ "id": 1,
85
+ "input": "(ID = {CoreEntity0022.CompanyGroupID} OR ISNULL({CoreEntity0022.CompanyGroupID},0) = 0)",
86
+ "filter": [
87
+ "ID",
88
+ "=",
89
+ 42
90
+ ],
91
+ "expectedSql": "\"ID\" = 42"
92
+ },
93
+ {
94
+ "id": 5,
95
+ "input": "CompanyID = {AccountingRule.CompanyID}",
96
+ "filter": [
97
+ "CompanyID",
98
+ "=",
99
+ 42
100
+ ],
101
+ "expectedSql": "\"CompanyID\" = 42"
102
+ },
103
+ {
104
+ "id": 6,
105
+ "input": "(Level > {Area.AreaType})",
106
+ "filter": [
107
+ "Level",
108
+ ">",
109
+ 42
110
+ ],
111
+ "expectedSql": "\"Level\" > 42"
112
+ },
113
+ {
114
+ "id": 9,
115
+ "input": "(ID <> {Item.ID}) AND ( ItemGroupType = '''')",
116
+ "filter": [
117
+ [
118
+ "ID",
119
+ "<>",
120
+ 42
121
+ ],
122
+ "and",
123
+ [
124
+ "ItemGroupType",
125
+ "=",
126
+ ""
127
+ ]
128
+ ],
129
+ "expectedSql": "\"ID\" <> 42 AND \"ItemGroupType\" = N''"
130
+ },
131
+ {
132
+ "id": 15,
133
+ "input": "AddressType NOT IN (2, 4)",
134
+ "filter": [
135
+ [
136
+ "AddressType",
137
+ "!=",
138
+ 2
139
+ ],
140
+ "and",
141
+ [
142
+ "AddressType",
143
+ "!=",
144
+ 4
145
+ ]
146
+ ],
147
+ "expectedSql": "\"AddressType\" != 2 AND \"AddressType\" != 4"
148
+ },
149
+ {
150
+ "id": 16,
151
+ "input": "AddressType IN ('2', ('4')) OR AddressType =({ServiceOrderDocument .SourceID})",
152
+ "filter": [
153
+ [
154
+ "AddressType",
155
+ "=",
156
+ "2"
157
+ ],
158
+ "or",
159
+ [
160
+ "AddressType",
161
+ "=",
162
+ "4"
163
+ ],
164
+ "or",
165
+ [
166
+ "AddressType",
167
+ "=",
168
+ 2
169
+ ]
170
+ ],
171
+ "expectedSql": "\"AddressType\" = N'2' OR \"AddressType\" = N'4' OR \"AddressType\" = 2"
172
+ },
173
+ {
174
+ "id": 21,
175
+ "input": "ID IN ({WorkOrderLine.CompanyIDs}) AND 0 IN ({WorkOrderLine.CompanyIDs})",
176
+ "filter": [
177
+ [
178
+ "ID",
179
+ "=",
180
+ "0"
181
+ ],
182
+ "or",
183
+ [
184
+ "ID",
185
+ "=",
186
+ "1"
187
+ ]
188
+ ],
189
+ "expectedSql": "\"ID\" = N'0' OR \"ID\" = N'1'"
190
+ },
191
+ {
192
+ "id": 33,
193
+ "input": "{ServiceOrderDocument.SourceID} = ID",
194
+ "filter": [
195
+ "ID",
196
+ "=",
197
+ 2
198
+ ],
199
+ "expectedSql": "\"ID\" = 2"
200
+ },
201
+ {
202
+ "id": 34,
203
+ "input": "IsChecked = 1",
204
+ "filter": [
205
+ [
206
+ "IsChecked",
207
+ "=",
208
+ 1
209
+ ],
210
+ "or",
211
+ [
212
+ "IsChecked",
213
+ "=",
214
+ true
215
+ ]
216
+ ],
217
+ "expectedSql": "\"IsChecked\" = 1 OR \"IsChecked\" = 1"
218
+ },
219
+ {
220
+ "id": 49,
221
+ "input": "AccountID = {AccountingRule.CompanyId}",
222
+ "filter": [
223
+ "AccountID",
224
+ "=",
225
+ 42
226
+ ],
227
+ "expectedSql": "\"AccountID\" = 42"
228
+ }
229
+ ]
230
+ },
231
+ {
232
+ "name": "Nested groups (IN lists, AND / OR)",
233
+ "cases": [
234
+ {
235
+ "id": 3,
236
+ "input": "ContactID = {SaleInvoiceDocument.ContactID} AND AddressType IN (2, 4)",
237
+ "filter": [
238
+ [
239
+ "ContactID",
240
+ "=",
241
+ 42
242
+ ],
243
+ "and",
244
+ [
245
+ [
246
+ "AddressType",
247
+ "=",
248
+ 2
249
+ ],
250
+ "or",
251
+ [
252
+ "AddressType",
253
+ "=",
254
+ 4
255
+ ]
256
+ ]
257
+ ],
258
+ "expectedSql": "\"ContactID\" = 42 AND ( \"AddressType\" = 2 OR \"AddressType\" = 4 )"
259
+ },
260
+ {
261
+ "id": 4,
262
+ "input": "ID IN ({WorkOrderLine.ApplicableUoms}) AND (CompanyID = {WorkOrderDocument.CompanyID} OR {WorkOrderDocument.CompanyID} = 0)",
263
+ "filter": [
264
+ [
265
+ [
266
+ "ID",
267
+ "=",
268
+ "UOM1"
269
+ ],
270
+ "or",
271
+ [
272
+ "ID",
273
+ "=",
274
+ "UOM2"
275
+ ],
276
+ "or",
277
+ [
278
+ "ID",
279
+ "=",
280
+ "UOM3"
281
+ ]
282
+ ],
283
+ "and",
284
+ [
285
+ "CompanyID",
286
+ "=",
287
+ 42
288
+ ]
289
+ ],
290
+ "expectedSql": [
291
+ "( \"ID\" = N'UOM1' OR \"ID\" = N'UOM2' OR \"ID\" = N'UOM3' )",
292
+ "AND \"CompanyID\" = 42"
293
+ ]
294
+ },
295
+ {
296
+ "id": 7,
297
+ "input": "(ID <> {Item.ID}) AND (ItemGroupType IN ({Item.AllowedItemGroupType}))",
298
+ "filter": [
299
+ [
300
+ "ID",
301
+ "<>",
302
+ 42
303
+ ],
304
+ "and",
305
+ [
306
+ [
307
+ "ItemGroupType",
308
+ "=",
309
+ "1"
310
+ ],
311
+ "or",
312
+ [
313
+ "ItemGroupType",
314
+ "=",
315
+ "2"
316
+ ]
317
+ ]
318
+ ],
319
+ "expectedSql": "\"ID\" <> 42 AND ( \"ItemGroupType\" = N'1' OR \"ItemGroupType\" = N'2' )"
320
+ },
321
+ {
322
+ "id": 10,
323
+ "input": "((ISNULL({0}, 0) = 0 AND CompanyID = {1}) OR CompanyID IS NULL) OR BranchID = {0} | [LeadDocument.BranchID] | [LeadDocument.CompanyID]",
324
+ "filter": [
325
+ [
326
+ "CompanyID",
327
+ "=",
328
+ null,
329
+ {
330
+ "type": "IS"
331
+ },
332
+ null
333
+ ],
334
+ "or",
335
+ [
336
+ "BranchID",
337
+ "=",
338
+ 42
339
+ ]
340
+ ],
341
+ "expectedSql": "\"CompanyID\" IS NULL OR \"BranchID\" = 42",
342
+ "note": "ISNULL(42, 0) = 0 is false, so the whole (... AND CompanyID = 7) group is false and dropped from the OR."
343
+ },
344
+ {
345
+ "id": 32,
346
+ "input": "10 < ID AND ApplicableUoms IN ({WorkOrderLine.ApplicableUoms})",
347
+ "filter": [
348
+ [
349
+ "ID",
350
+ ">",
351
+ 10
352
+ ],
353
+ "and",
354
+ [
355
+ [
356
+ "ApplicableUoms",
357
+ "=",
358
+ "UOM1"
359
+ ],
360
+ "or",
361
+ [
362
+ "ApplicableUoms",
363
+ "=",
364
+ "UOM2"
365
+ ],
366
+ "or",
367
+ [
368
+ "ApplicableUoms",
369
+ "=",
370
+ "UOM3"
371
+ ]
372
+ ]
373
+ ],
374
+ "expectedSql": [
375
+ "\"ID\" > 10",
376
+ "AND ( \"ApplicableUoms\" = N'UOM1' OR \"ApplicableUoms\" = N'UOM2' OR \"ApplicableUoms\" = N'UOM3' )"
377
+ ]
378
+ },
379
+ {
380
+ "id": 52,
381
+ "input": "BranchID = {AdjustmentDocument.BranchID} AND CompanyID = {AdjustmentDocument.CompanyID} AND IsFromInvoice = {AdjustmentDocument.IsFromInvoice} AND (SupplierInvoiceNO IN ('{AdjustmentDocument.SupplierInvoiceNos}') OR ISNULL('{AdjustmentDocument.SupplierInvoiceNos}','''') = '''')",
382
+ "filter": [
383
+ [
384
+ [
385
+ "BranchID",
386
+ "=",
387
+ 42
388
+ ],
389
+ "and",
390
+ [
391
+ "CompanyID",
392
+ "=",
393
+ 7
394
+ ],
395
+ "and",
396
+ [
397
+ "IsFromInvoice",
398
+ "=",
399
+ true
400
+ ]
401
+ ],
402
+ "and",
403
+ [
404
+ "SupplierInvoiceNO",
405
+ "=",
406
+ "INV1"
407
+ ]
408
+ ],
409
+ "expectedSql": [
410
+ "( \"BranchID\" = 42 AND \"CompanyID\" = 7 AND \"IsFromInvoice\" = 1 )",
411
+ "AND \"SupplierInvoiceNO\" = N'INV1'"
412
+ ]
413
+ }
414
+ ]
415
+ },
416
+ {
417
+ "name": "IS NULL / IS NOT NULL",
418
+ "cases": [
419
+ {
420
+ "id": 8,
421
+ "input": "((FromDate <= '{TransferOutwardDocument.DocDate}' AND ToDate >= '{TransferOutwardDocument.DocDate}') OR ToDate is NULL) AND (BranchID = {TransferOutwardDocument.RefBranchID} OR RefBranchID is NULL) AND (CompanyID = {TransferOutwardDocument.CompanyID} OR {TransferOutwardDocument.CompanyID} = 0 OR CompanyID is NULL)",
422
+ "filter": [
423
+ [
424
+ [
425
+ [
426
+ [
427
+ "FromDate",
428
+ "<=",
429
+ "2022-01-01"
430
+ ],
431
+ "and",
432
+ [
433
+ "ToDate",
434
+ ">=",
435
+ "2022-01-01"
436
+ ]
437
+ ],
438
+ "or",
439
+ [
440
+ "ToDate",
441
+ "=",
442
+ null,
443
+ {
444
+ "type": "IS"
445
+ },
446
+ null
447
+ ]
448
+ ],
449
+ "and",
450
+ [
451
+ [
452
+ "BranchID",
453
+ "=",
454
+ 42
455
+ ],
456
+ "or",
457
+ [
458
+ "RefBranchID",
459
+ "=",
460
+ null,
461
+ {
462
+ "type": "IS"
463
+ },
464
+ null
465
+ ]
466
+ ]
467
+ ],
468
+ "and",
469
+ [
470
+ [
471
+ "CompanyID",
472
+ "=",
473
+ 7
474
+ ],
475
+ "or",
476
+ [
477
+ "CompanyID",
478
+ "=",
479
+ null,
480
+ {
481
+ "type": "IS"
482
+ },
483
+ null
484
+ ]
485
+ ]
486
+ ],
487
+ "expectedSql": [
488
+ "( ( ( \"FromDate\" <= N'2022-01-01' AND \"ToDate\" >= N'2022-01-01' ) OR \"ToDate\" IS NULL )",
489
+ "AND ( \"BranchID\" = 42 OR \"RefBranchID\" IS NULL ) )",
490
+ "AND ( \"CompanyID\" = 7 OR \"CompanyID\" IS NULL )"
491
+ ]
492
+ },
493
+ {
494
+ "id": 12,
495
+ "input": "BranchID is Null OR BranchID is not 12",
496
+ "filter": [
497
+ [
498
+ "BranchID",
499
+ "=",
500
+ null,
501
+ {
502
+ "type": "IS"
503
+ },
504
+ null
505
+ ],
506
+ "or",
507
+ [
508
+ "BranchID",
509
+ "!=",
510
+ 12,
511
+ {
512
+ "type": "IS NOT"
513
+ },
514
+ 12
515
+ ]
516
+ ],
517
+ "expectedSql": "\"BranchID\" IS NULL OR \"BranchID\" != 12",
518
+ "note": "'IS NOT 12' is not valid T-SQL, so non-NULL values keep the DevExtreme operator."
519
+ },
520
+ {
521
+ "id": 22,
522
+ "input": "CompanyID is null OR CompanyID is 7 OR CompanyID is not 8",
523
+ "filter": [
524
+ [
525
+ "CompanyID",
526
+ "=",
527
+ null,
528
+ {
529
+ "type": "IS"
530
+ },
531
+ null
532
+ ],
533
+ "or",
534
+ [
535
+ "CompanyID",
536
+ "=",
537
+ 7,
538
+ {
539
+ "type": "IS"
540
+ },
541
+ 7
542
+ ],
543
+ "or",
544
+ [
545
+ "CompanyID",
546
+ "!=",
547
+ 8,
548
+ {
549
+ "type": "IS NOT"
550
+ },
551
+ 8
552
+ ]
553
+ ],
554
+ "expectedSql": "\"CompanyID\" IS NULL OR \"CompanyID\" = 7 OR \"CompanyID\" != 8",
555
+ "note": "'IS 7' / 'IS NOT 8' are not valid T-SQL, so non-NULL values keep the DevExtreme operator."
556
+ },
557
+ {
558
+ "id": 31,
559
+ "input": "ID IN ({SaleOrderStatusStmtGlobalRpt.RegionID})",
560
+ "filter": [
561
+ "ID",
562
+ "=",
563
+ null
564
+ ],
565
+ "expectedSql": "\"ID\" IS NULL",
566
+ "note": "Plain '= null' (no options) must still become IS NULL."
567
+ },
568
+ {
569
+ "id": 48,
570
+ "input": "(CompanyID = {LeadDocument.CompanyID} OR CompanyID IS NULL) AND ItemGroupType IN ({Item.AllowedItemGroupTypeOne}) AND ({PurchaseOrderDocument.IsMultiBrand} = 0 OR ({PurchaseOrderDocument.IsMultiBrand} = 1 AND Make IN ({PurchaseOrderDocument.AllowedApplicableMake})))",
571
+ "filter": [
572
+ [
573
+ [
574
+ "CompanyID",
575
+ "=",
576
+ 7
577
+ ],
578
+ "or",
579
+ [
580
+ "CompanyID",
581
+ "=",
582
+ null,
583
+ {
584
+ "type": "IS"
585
+ },
586
+ null
587
+ ]
588
+ ],
589
+ "and",
590
+ [
591
+ "ItemGroupType",
592
+ "=",
593
+ "1"
594
+ ]
595
+ ],
596
+ "expectedSql": "( \"CompanyID\" = 7 OR \"CompanyID\" IS NULL ) AND \"ItemGroupType\" = N'1'"
597
+ },
598
+ {
599
+ "id": 53,
600
+ "input": [
601
+ "DocType IN ({QuoteDocument.AllowedDocType})",
602
+ "AND CompanyID = {QuoteDocument.CompanyID}",
603
+ "AND",
604
+ "(",
605
+ " {QuoteDocument.IsVehicle} = 0",
606
+ " OR",
607
+ " (",
608
+ " {QuoteDocument.IsVehicle} = 1",
609
+ " AND ProspectID IS NOT NULL",
610
+ " )",
611
+ ")"
612
+ ],
613
+ "filter": [
614
+ [
615
+ [
616
+ "DocType",
617
+ "=",
618
+ "10809"
619
+ ],
620
+ "or",
621
+ [
622
+ "DocType",
623
+ "=",
624
+ "40927"
625
+ ]
626
+ ],
627
+ "and",
628
+ [
629
+ "CompanyID",
630
+ "=",
631
+ 2
632
+ ],
633
+ "and",
634
+ [
635
+ "ProspectID",
636
+ "!=",
637
+ null,
638
+ {
639
+ "type": "IS NOT"
640
+ },
641
+ null
642
+ ]
643
+ ],
644
+ "expectedSql": [
645
+ "( \"DocType\" = N'10809' OR \"DocType\" = N'40927' )",
646
+ "AND \"CompanyID\" = 2",
647
+ "AND \"ProspectID\" IS NOT NULL"
648
+ ]
649
+ }
650
+ ]
651
+ },
652
+ {
653
+ "name": "ISNULL on column side - ISNULL(\"col\", default) = value",
654
+ "cases": [
655
+ {
656
+ "id": 13,
657
+ "input": "ISNULL(SourceID,0) = {ServiceOrderDocument.SourceID} OR ISNULL(SourceID,0) = 0",
658
+ "filter": [
659
+ [
660
+ "SourceID",
661
+ "=",
662
+ 2,
663
+ {
664
+ "type": "ISNULL",
665
+ "position": "column",
666
+ "defaultValue": 0
667
+ },
668
+ 2
669
+ ],
670
+ "or",
671
+ [
672
+ [
673
+ "SourceID",
674
+ "=",
675
+ 0
676
+ ],
677
+ "or",
678
+ [
679
+ "SourceID",
680
+ "=",
681
+ null,
682
+ {
683
+ "type": "ISNULL",
684
+ "position": "column",
685
+ "defaultValue": 0
686
+ },
687
+ null
688
+ ],
689
+ "or",
690
+ [
691
+ "SourceID",
692
+ "=",
693
+ false
694
+ ]
695
+ ]
696
+ ],
697
+ "expectedSql": [
698
+ "ISNULL(\"SourceID\", 0) = 2",
699
+ "OR ( \"SourceID\" = 0 OR ISNULL(\"SourceID\", 0) = 0 OR \"SourceID\" = 0 )"
700
+ ],
701
+ "note": "A null value with a column-side ISNULL compares against the default: ISNULL(col, 0) = 0."
702
+ },
703
+ {
704
+ "id": 14,
705
+ "input": "(CompanyID = {LeadDocument.CompanyID} OR ISNULL(CompanyID,0) = 0) AND (ISNULL(IsSubdealer,0) = {LeadDocument.AllowSubDealer})",
706
+ "filter": [
707
+ [
708
+ [
709
+ "CompanyID",
710
+ "=",
711
+ 7
712
+ ],
713
+ "or",
714
+ [
715
+ [
716
+ "CompanyID",
717
+ "=",
718
+ 0
719
+ ],
720
+ "or",
721
+ [
722
+ "CompanyID",
723
+ "=",
724
+ null,
725
+ {
726
+ "type": "ISNULL",
727
+ "position": "column",
728
+ "defaultValue": 0
729
+ },
730
+ null
731
+ ],
732
+ "or",
733
+ [
734
+ "CompanyID",
735
+ "=",
736
+ false
737
+ ]
738
+ ]
739
+ ],
740
+ "and",
741
+ [
742
+ "IsSubdealer",
743
+ "=",
744
+ true,
745
+ {
746
+ "type": "ISNULL",
747
+ "position": "column",
748
+ "defaultValue": 0
749
+ },
750
+ true
751
+ ]
752
+ ],
753
+ "expectedSql": [
754
+ "( \"CompanyID\" = 7 OR ( \"CompanyID\" = 0 OR ISNULL(\"CompanyID\", 0) = 0 OR \"CompanyID\" = 0 ) )",
755
+ "AND ISNULL(\"IsSubdealer\", 0) = 1"
756
+ ]
757
+ },
758
+ {
759
+ "id": 37,
760
+ "input": "ISNULL(CompanyID,0) = {LeadDocument.CompanyID}",
761
+ "filter": [
762
+ "CompanyID",
763
+ "=",
764
+ 7,
765
+ {
766
+ "type": "ISNULL",
767
+ "position": "column",
768
+ "defaultValue": 0
769
+ },
770
+ 7
771
+ ],
772
+ "expectedSql": "ISNULL(\"CompanyID\", 0) = 7"
773
+ },
774
+ {
775
+ "id": 45,
776
+ "input": "ISNULL(AllowSubDealer,0) = {LeadDocument.AllowSubDealer}",
777
+ "filter": [
778
+ "AllowSubDealer",
779
+ "=",
780
+ true,
781
+ {
782
+ "type": "ISNULL",
783
+ "position": "column",
784
+ "defaultValue": 0
785
+ },
786
+ true
787
+ ],
788
+ "expectedSql": "ISNULL(\"AllowSubDealer\", 0) = 1"
789
+ },
790
+ {
791
+ "id": 46,
792
+ "input": "(CompanyID = {SingleStepTransferDocument.CompanyID} OR {SingleStepTransferDocument.CompanyID} = 0 OR ISNULL(CompanyID,0) = 0) AND ((ISNULL(IsSubdealer,0)) IN ({SingleStepTransferDocument.AllowedSubdealer}))",
793
+ "filter": [
794
+ [
795
+ [
796
+ "CompanyID",
797
+ "=",
798
+ 2
799
+ ],
800
+ "or",
801
+ [
802
+ [
803
+ "CompanyID",
804
+ "=",
805
+ 0
806
+ ],
807
+ "or",
808
+ [
809
+ "CompanyID",
810
+ "=",
811
+ null,
812
+ {
813
+ "type": "ISNULL",
814
+ "position": "column",
815
+ "defaultValue": 0
816
+ },
817
+ null
818
+ ],
819
+ "or",
820
+ [
821
+ "CompanyID",
822
+ "=",
823
+ false
824
+ ]
825
+ ]
826
+ ],
827
+ "and",
828
+ [
829
+ [
830
+ "IsSubdealer",
831
+ "=",
832
+ false
833
+ ],
834
+ "or",
835
+ [
836
+ "IsSubdealer",
837
+ "=",
838
+ null,
839
+ {
840
+ "type": "ISNULL",
841
+ "position": "column",
842
+ "defaultValue": 0
843
+ },
844
+ null
845
+ ]
846
+ ]
847
+ ],
848
+ "expectedSql": [
849
+ "( \"CompanyID\" = 2 OR ( \"CompanyID\" = 0 OR ISNULL(\"CompanyID\", 0) = 0 OR \"CompanyID\" = 0 ) )",
850
+ "AND ( \"IsSubdealer\" = 0 OR ISNULL(\"IsSubdealer\", 0) = 0 )"
851
+ ]
852
+ },
853
+ {
854
+ "id": 47,
855
+ "input": "ISNULL(AllowSubDealer,1) = {LeadDocument.AllowSubDealer}",
856
+ "filter": [
857
+ [
858
+ "AllowSubDealer",
859
+ "=",
860
+ true
861
+ ],
862
+ "or",
863
+ [
864
+ "AllowSubDealer",
865
+ "=",
866
+ null,
867
+ {
868
+ "type": "ISNULL",
869
+ "position": "column",
870
+ "defaultValue": 1
871
+ },
872
+ null
873
+ ]
874
+ ],
875
+ "expectedSql": "\"AllowSubDealer\" = 1 OR ISNULL(\"AllowSubDealer\", 1) = 1"
876
+ },
877
+ {
878
+ "id": 51,
879
+ "input": "ItemGroupType IN ({ItemPrice.AllowedItemGroupType}) AND ((ISNULL(IsNonStock,0))={ItemPrice.AllowedNonStock}) AND (CompanyID = {ItemPrice.CompanyID} OR {ItemPrice.CompanyID} = 0 OR ISNULL(CompanyID,0) = 0)",
880
+ "filter": [
881
+ [
882
+ [
883
+ [
884
+ "ItemGroupType",
885
+ "=",
886
+ "1"
887
+ ],
888
+ "or",
889
+ [
890
+ "ItemGroupType",
891
+ "=",
892
+ "2"
893
+ ]
894
+ ],
895
+ "and",
896
+ [
897
+ [
898
+ "IsNonStock",
899
+ "=",
900
+ 1,
901
+ {
902
+ "type": "ISNULL",
903
+ "position": "column",
904
+ "defaultValue": 0
905
+ },
906
+ 1
907
+ ],
908
+ "or",
909
+ [
910
+ "IsNonStock",
911
+ "=",
912
+ true
913
+ ]
914
+ ]
915
+ ],
916
+ "and",
917
+ [
918
+ [
919
+ "CompanyID",
920
+ "=",
921
+ 7
922
+ ],
923
+ "or",
924
+ [
925
+ [
926
+ "CompanyID",
927
+ "=",
928
+ 0
929
+ ],
930
+ "or",
931
+ [
932
+ "CompanyID",
933
+ "=",
934
+ null,
935
+ {
936
+ "type": "ISNULL",
937
+ "position": "column",
938
+ "defaultValue": 0
939
+ },
940
+ null
941
+ ],
942
+ "or",
943
+ [
944
+ "CompanyID",
945
+ "=",
946
+ false
947
+ ]
948
+ ]
949
+ ]
950
+ ],
951
+ "expectedSql": [
952
+ "( ( \"ItemGroupType\" = N'1' OR \"ItemGroupType\" = N'2' )",
953
+ "AND ( ISNULL(\"IsNonStock\", 0) = 1 OR \"IsNonStock\" = 1 ) )",
954
+ "AND ( \"CompanyID\" = 7 OR ( \"CompanyID\" = 0 OR ISNULL(\"CompanyID\", 0) = 0 OR \"CompanyID\" = 0 ) )"
955
+ ]
956
+ },
957
+ {
958
+ "id": 55,
959
+ "input": "(ISNULL(ItemID,0) = {PurchaseOrderLine.ItemID}) AND (varID = ISNULL({PurchaseOrderLine.VarMatrixID0}, 0) OR ({PurchaseOrderLine.VarMatrixID0} = 0 AND ISNULL(varID, 0) = 0))",
960
+ "filter": [
961
+ [
962
+ "ItemID",
963
+ "=",
964
+ 42,
965
+ {
966
+ "type": "ISNULL",
967
+ "position": "column",
968
+ "defaultValue": 0
969
+ },
970
+ 42
971
+ ],
972
+ "and",
973
+ [
974
+ "varID",
975
+ "=",
976
+ null,
977
+ {
978
+ "type": "ISNULL",
979
+ "position": "value",
980
+ "defaultValue": 0
981
+ },
982
+ null
983
+ ]
984
+ ],
985
+ "expectedSql": "ISNULL(\"ItemID\", 0) = 42 AND \"varID\" = ISNULL(NULL, 0)",
986
+ "note": "VarMatrixID0 is null: varID = ISNULL({VarMatrixID0}, 0) keeps the null with its ISNULL default (same as case 42), and {VarMatrixID0} = 0 is false (null only equals null), so that AND group is dropped."
987
+ },
988
+ {
989
+ "id": 56,
990
+ "input": "(ISNULL(ItemID,0) = {PurchaseOrderLine.ItemID}) AND (varID = {PurchaseOrderLine.VarMatrixID1} OR ({PurchaseOrderLine.VarMatrixID1} = 0 AND ISNULL(varID, 0) = 0))",
991
+ "filter": [
992
+ [
993
+ "ItemID",
994
+ "=",
995
+ 42,
996
+ {
997
+ "type": "ISNULL",
998
+ "position": "column",
999
+ "defaultValue": 0
1000
+ },
1001
+ 42
1002
+ ],
1003
+ "and",
1004
+ [
1005
+ "varID",
1006
+ "=",
1007
+ 5
1008
+ ]
1009
+ ],
1010
+ "expectedSql": "ISNULL(\"ItemID\", 0) = 42 AND \"varID\" = 5",
1011
+ "note": "{VarMatrixID1} = 0 is false, so the whole AND group is false and dropped from the OR."
1012
+ },
1013
+ {
1014
+ "id": 57,
1015
+ "input": "ItemID = {PurchaseOrderLine.ItemID} OR ({PurchaseOrderLine.VarMatrixID0} = 5 AND varID = 2)",
1016
+ "filter": [
1017
+ "ItemID",
1018
+ "=",
1019
+ 42
1020
+ ],
1021
+ "expectedSql": "\"ItemID\" = 42",
1022
+ "note": "A null variable compared with a value is evaluated: null = 5 is false, so the AND group is dropped from the OR."
1023
+ }
1024
+ ]
1025
+ },
1026
+ {
1027
+ "name": "ISNULL on value side - \"col\" = ISNULL(value, defaultValue)",
1028
+ "cases": [
1029
+ {
1030
+ "id": 18,
1031
+ "input": "CompanyID = ISNULL({LeadDocument.CompanyID},0) OR (ISNULL(CompanyID,0) = 0))",
1032
+ "filter": [
1033
+ [
1034
+ "CompanyID",
1035
+ "=",
1036
+ 7,
1037
+ {
1038
+ "type": "ISNULL",
1039
+ "position": "value",
1040
+ "defaultValue": 0
1041
+ },
1042
+ 7
1043
+ ],
1044
+ "or",
1045
+ [
1046
+ [
1047
+ "CompanyID",
1048
+ "=",
1049
+ 0
1050
+ ],
1051
+ "or",
1052
+ [
1053
+ "CompanyID",
1054
+ "=",
1055
+ null,
1056
+ {
1057
+ "type": "ISNULL",
1058
+ "position": "column",
1059
+ "defaultValue": 0
1060
+ },
1061
+ null
1062
+ ],
1063
+ "or",
1064
+ [
1065
+ "CompanyID",
1066
+ "=",
1067
+ false
1068
+ ]
1069
+ ]
1070
+ ],
1071
+ "expectedSql": [
1072
+ "\"CompanyID\" = ISNULL(7, 0)",
1073
+ "OR ( \"CompanyID\" = 0 OR ISNULL(\"CompanyID\", 0) = 0 OR \"CompanyID\" = 0 )"
1074
+ ]
1075
+ },
1076
+ {
1077
+ "id": 40,
1078
+ "input": "CompanyID = ISNULL({LeadDocument.CompanyID},0)",
1079
+ "filter": [
1080
+ "CompanyID",
1081
+ "=",
1082
+ 7,
1083
+ {
1084
+ "type": "ISNULL",
1085
+ "position": "value",
1086
+ "defaultValue": 0
1087
+ },
1088
+ 7
1089
+ ],
1090
+ "expectedSql": "\"CompanyID\" = ISNULL(7, 0)"
1091
+ },
1092
+ {
1093
+ "id": 41,
1094
+ "input": "AllowSubDealer = ISNULL({LeadDocument.AllowSubDealer},0)",
1095
+ "filter": [
1096
+ "AllowSubDealer",
1097
+ "=",
1098
+ true,
1099
+ {
1100
+ "type": "ISNULL",
1101
+ "position": "value",
1102
+ "defaultValue": 0
1103
+ },
1104
+ true
1105
+ ],
1106
+ "expectedSql": "\"AllowSubDealer\" = ISNULL(1, 0)"
1107
+ },
1108
+ {
1109
+ "id": 42,
1110
+ "input": "AllowSubDealer = ISNULL({SaleOrderStatusStmtGlobalRpt.StateID},0)",
1111
+ "filter": [
1112
+ "AllowSubDealer",
1113
+ "=",
1114
+ null,
1115
+ {
1116
+ "type": "ISNULL",
1117
+ "position": "value",
1118
+ "defaultValue": 0
1119
+ },
1120
+ null
1121
+ ],
1122
+ "expectedSql": "\"AllowSubDealer\" = ISNULL(NULL, 0)"
1123
+ },
1124
+ {
1125
+ "id": 43,
1126
+ "input": "AllowSubDealer = ISNULL({LeadDocument.AllowSubDealer},1)",
1127
+ "filter": [
1128
+ "AllowSubDealer",
1129
+ "=",
1130
+ true,
1131
+ {
1132
+ "type": "ISNULL",
1133
+ "position": "value",
1134
+ "defaultValue": 1
1135
+ },
1136
+ true
1137
+ ],
1138
+ "expectedSql": "\"AllowSubDealer\" = ISNULL(1, 1)"
1139
+ }
1140
+ ]
1141
+ },
1142
+ {
1143
+ "name": "ISNULL on both sides - ISNULL(\"col\", defaultValue) = ISNULL(value, defaultValueRight)",
1144
+ "cases": [
1145
+ {
1146
+ "id": 17,
1147
+ "input": "(ISNULL(TicketID, 0) = ISNULL({SupportResolution.TicketID}, 0))",
1148
+ "filter": [
1149
+ [
1150
+ "TicketID",
1151
+ "=",
1152
+ 123,
1153
+ {
1154
+ "type": "ISNULL",
1155
+ "position": "both",
1156
+ "defaultValue": 0,
1157
+ "defaultValueRight": 0
1158
+ },
1159
+ 123
1160
+ ],
1161
+ "or",
1162
+ [
1163
+ "TicketID",
1164
+ "=",
1165
+ null
1166
+ ]
1167
+ ],
1168
+ "expectedSql": "ISNULL(\"TicketID\", 0) = ISNULL(123, 0) OR \"TicketID\" IS NULL"
1169
+ },
1170
+ {
1171
+ "id": 35,
1172
+ "input": "ISNULL(CompanyID,0) = ISNULL({TransferOutwardDocument.CompanyID},0) OR (ISNULL(CompanyID,0) = 0)",
1173
+ "filter": [
1174
+ [
1175
+ "CompanyID",
1176
+ "=",
1177
+ 7,
1178
+ {
1179
+ "type": "ISNULL",
1180
+ "position": "both",
1181
+ "defaultValue": 0,
1182
+ "defaultValueRight": 0
1183
+ },
1184
+ 7
1185
+ ],
1186
+ "or",
1187
+ [
1188
+ "CompanyID",
1189
+ "=",
1190
+ null
1191
+ ],
1192
+ "or",
1193
+ [
1194
+ "CompanyID",
1195
+ "=",
1196
+ 0
1197
+ ],
1198
+ "or",
1199
+ [
1200
+ "CompanyID",
1201
+ "=",
1202
+ null,
1203
+ {
1204
+ "type": "ISNULL",
1205
+ "position": "column",
1206
+ "defaultValue": 0
1207
+ },
1208
+ null
1209
+ ],
1210
+ "or",
1211
+ [
1212
+ "CompanyID",
1213
+ "=",
1214
+ false
1215
+ ]
1216
+ ],
1217
+ "expectedSql": [
1218
+ "ISNULL(\"CompanyID\", 0) = ISNULL(7, 0)",
1219
+ "OR \"CompanyID\" IS NULL",
1220
+ "OR \"CompanyID\" = 0",
1221
+ "OR ISNULL(\"CompanyID\", 0) = 0",
1222
+ "OR \"CompanyID\" = 0"
1223
+ ]
1224
+ },
1225
+ {
1226
+ "id": 36,
1227
+ "input": "ISNULL(CompanyID,0) = ISNULL({TransferOutwardDocument.CompanyID},0) OR (ISNULL(CompanyID,1) = 0)",
1228
+ "filter": [
1229
+ [
1230
+ "CompanyID",
1231
+ "=",
1232
+ 7,
1233
+ {
1234
+ "type": "ISNULL",
1235
+ "position": "both",
1236
+ "defaultValue": 0,
1237
+ "defaultValueRight": 0
1238
+ },
1239
+ 7
1240
+ ],
1241
+ "or",
1242
+ [
1243
+ "CompanyID",
1244
+ "=",
1245
+ null
1246
+ ],
1247
+ "or",
1248
+ [
1249
+ "CompanyID",
1250
+ "=",
1251
+ 0,
1252
+ {
1253
+ "type": "ISNULL",
1254
+ "position": "column",
1255
+ "defaultValue": 1
1256
+ },
1257
+ 0
1258
+ ],
1259
+ "or",
1260
+ [
1261
+ "CompanyID",
1262
+ "=",
1263
+ false
1264
+ ]
1265
+ ],
1266
+ "expectedSql": [
1267
+ "ISNULL(\"CompanyID\", 0) = ISNULL(7, 0)",
1268
+ "OR \"CompanyID\" IS NULL",
1269
+ "OR ISNULL(\"CompanyID\", 1) = 0",
1270
+ "OR \"CompanyID\" = 0"
1271
+ ]
1272
+ },
1273
+ {
1274
+ "id": 38,
1275
+ "input": "ISNULL(CompanyID,0) = ISNULL({LeadDocument.CompanyID},0)",
1276
+ "filter": [
1277
+ [
1278
+ "CompanyID",
1279
+ "=",
1280
+ 7,
1281
+ {
1282
+ "type": "ISNULL",
1283
+ "position": "both",
1284
+ "defaultValue": 0,
1285
+ "defaultValueRight": 0
1286
+ },
1287
+ 7
1288
+ ],
1289
+ "or",
1290
+ [
1291
+ "CompanyID",
1292
+ "=",
1293
+ null
1294
+ ]
1295
+ ],
1296
+ "expectedSql": "ISNULL(\"CompanyID\", 0) = ISNULL(7, 0) OR \"CompanyID\" IS NULL"
1297
+ },
1298
+ {
1299
+ "id": 39,
1300
+ "input": "ISNULL(CompanyID,1) = ISNULL({LeadDocument.CompanyID},2)",
1301
+ "filter": [
1302
+ "CompanyID",
1303
+ "=",
1304
+ 7,
1305
+ {
1306
+ "type": "ISNULL",
1307
+ "position": "both",
1308
+ "defaultValue": 1,
1309
+ "defaultValueRight": 2
1310
+ },
1311
+ 7
1312
+ ],
1313
+ "expectedSql": "ISNULL(\"CompanyID\", 1) = ISNULL(7, 2)"
1314
+ },
1315
+ {
1316
+ "id": 44,
1317
+ "input": "ISNULL(AllowSubDealer,0) = ISNULL({LeadDocument.AllowSubDealer},1)",
1318
+ "filter": [
1319
+ "AllowSubDealer",
1320
+ "=",
1321
+ true,
1322
+ {
1323
+ "type": "ISNULL",
1324
+ "position": "both",
1325
+ "defaultValue": 0,
1326
+ "defaultValueRight": 1
1327
+ },
1328
+ true
1329
+ ],
1330
+ "expectedSql": "ISNULL(\"AllowSubDealer\", 0) = ISNULL(1, 1)"
1331
+ }
1332
+ ]
1333
+ },
1334
+ {
1335
+ "name": "String operators, BETWEEN and escaping",
1336
+ "cases": [
1337
+ {
1338
+ "id": 11,
1339
+ "input": "FromDate Between '10-10-2021' AND '10-10-2022'",
1340
+ "filter": [
1341
+ "FromDate",
1342
+ "between",
1343
+ [
1344
+ "10-10-2021",
1345
+ "10-10-2022"
1346
+ ]
1347
+ ],
1348
+ "expectedSql": "\"FromDate\" BETWEEN N'10-10-2021' AND N'10-10-2022'"
1349
+ },
1350
+ {
1351
+ "id": 19,
1352
+ "input": "CompanyName like '{LeadDocument.CompanyID}' AND BranchName not like '{LeadDocument.BranchID}'",
1353
+ "filter": [
1354
+ [
1355
+ "CompanyName",
1356
+ "contains",
1357
+ "7"
1358
+ ],
1359
+ "and",
1360
+ [
1361
+ "BranchName",
1362
+ "notcontains",
1363
+ "42"
1364
+ ]
1365
+ ],
1366
+ "expectedSql": [
1367
+ "(ISNULL(CharIndEX(N'7',\"CompanyName\"), 0) > 0 )",
1368
+ "AND not(ISNULL(CharIndEX(N'42',\"BranchName\"), 0) > 0 )"
1369
+ ]
1370
+ },
1371
+ {
1372
+ "id": 54,
1373
+ "input": "CustomerName = 'O''Brien' AND Notes LIKE '%it''s%'",
1374
+ "filter": [
1375
+ [
1376
+ "CustomerName",
1377
+ "=",
1378
+ "O'Brien"
1379
+ ],
1380
+ "and",
1381
+ [
1382
+ "Notes",
1383
+ "contains",
1384
+ "it's"
1385
+ ]
1386
+ ],
1387
+ "expectedSql": [
1388
+ "\"CustomerName\" = N'O''Brien'",
1389
+ "AND (ISNULL(CharIndEX(N'it''s',\"Notes\"), 0) > 0 )"
1390
+ ],
1391
+ "note": "Single quotes in values must be escaped.",
1392
+ "skip": {
1393
+ "js": "JS sanitizer drops escaped quotes: 'O''Brien' becomes OBrien"
1394
+ }
1395
+ }
1396
+ ]
1397
+ },
1398
+ {
1399
+ "name": "Dropped by the JS converter (empty filter -> empty SQL)",
1400
+ "cases": [
1401
+ {
1402
+ "id": 2,
1403
+ "input": "GroupNo = {Employee.District} OR ISNULL(GroupNo,0) = 0 OR {Employee.District} = 0",
1404
+ "filter": [],
1405
+ "expectedSql": ""
1406
+ },
1407
+ {
1408
+ "id": 20,
1409
+ "input": "(RS2ID in ({SaleOrderStatusStmtGlobalRpt.StateID}) Or (ISNULL({SaleOrderStatusStmtGlobalRpt.StateID},0) =0)) And (RS3ID in (0,{SaleOrderStatusStmtGlobalRpt.RegionID}) Or ISNULL({SaleOrderStatusStmtGlobalRpt.RegionID},0) =0 )",
1410
+ "filter": [],
1411
+ "expectedSql": ""
1412
+ },
1413
+ {
1414
+ "id": 23,
1415
+ "input": "null = 0",
1416
+ "filter": [],
1417
+ "expectedSql": ""
1418
+ },
1419
+ {
1420
+ "id": 24,
1421
+ "input": "null = null",
1422
+ "filter": [],
1423
+ "expectedSql": ""
1424
+ },
1425
+ {
1426
+ "id": 25,
1427
+ "input": "null = {SaleOrderStatusStmtGlobalRpt.StateID}",
1428
+ "filter": [],
1429
+ "expectedSql": ""
1430
+ },
1431
+ {
1432
+ "id": 26,
1433
+ "input": "null = {SaleOrderStatusStmtGlobalRpt.RegionID}",
1434
+ "filter": [],
1435
+ "expectedSql": ""
1436
+ },
1437
+ {
1438
+ "id": 27,
1439
+ "input": "null = {LeadDocument.CompanyID}",
1440
+ "filter": [],
1441
+ "expectedSql": ""
1442
+ },
1443
+ {
1444
+ "id": 28,
1445
+ "input": "{LeadDocument.BranchID} = null",
1446
+ "filter": [],
1447
+ "expectedSql": ""
1448
+ },
1449
+ {
1450
+ "id": 29,
1451
+ "input": "{LeadDocument.AllowSubDealer} != null",
1452
+ "filter": [],
1453
+ "expectedSql": ""
1454
+ },
1455
+ {
1456
+ "id": 30,
1457
+ "input": "ID = {SaleOrderStatusStmtGlobalRpt.RegionID}",
1458
+ "filter": [],
1459
+ "expectedSql": ""
1460
+ },
1461
+ {
1462
+ "id": 50,
1463
+ "input": "ID IN ({SampleDoc.AuthFilterID})",
1464
+ "filter": [],
1465
+ "expectedSql": ""
1466
+ }
1467
+ ]
1468
+ }
1469
+ ]
1470
+ }