/
cg_test.sql
2879 lines (2529 loc) · 91.7 KB
/
cg_test.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
-- basic test table with an auto inc field
create table foo(
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
);
-- second test table with combination of fields
@attribute(bar_is_good=1)
create table bar(
id INTEGER NOT NULL PRIMARY KEY,
@attribute(collossal_cave='xyzzy')
name TEXT,
rate LONG INT,
type INTEGER,
size REAL @create(2)
);
-- test view that reads from the test tables
create view baz as select id, name, type from bar;
-- declare variables of the basic types
declare i0_nullable int;
declare i1_nullable int;
declare r0_nullable real;
declare l0_nullable long integer;
declare l1_nullable long integer;
declare b0_nullable bool;
declare t0_nullable text;
-- same types but not null variant
declare i2 int not null;
declare r2 real not null;
declare l2 long integer not null;
declare b2 bool not null;
declare t2 text not null;
-- TEST: assign eveything not null
-- Note: semantic analysis verifies no chance of
-- assigning nullable to not nullable
-- + i2 = 1;
set i2 := 1;
-- TEST: assign rhs not null
-- + cql_set_notnull(i1_nullable, 88);
set i1_nullable := 88;
-- TEST: assign everything nullable
-- + cql_set_nullable(i0_nullable, i1_nullable.is_null, i1_nullable.value);
set i0_nullable := i1_nullable;
-- TEST: assign NULL to nullable string
-- + cql_set_string_ref(&t0_nullable, NULL);
set t0_nullable := null;
-- + cql_set_string_ref(&t0_nullable, t2);
set t0_nullable := t2;
-- TEST: simple unary operators
-- + i2 = - - 1;
set i2 := - -1;
-- + cql_set_notnull(i0_nullable, - i2);
set i0_nullable := -i2;
-- + cql_set_null(i0_nullable);
set i0_nullable := -null;
-- + cql_set_nullable(i1_nullable, i0_nullable.is_null, - i0_nullable.value);
set i1_nullable := -i0_nullable;
-- + cql_set_notnull(r0_nullable, 2.2%);
set r0_nullable := 2.2;
-- + r2 = 3.5%;
set r2 := 3.5;
-- + cql_set_nullable(_tmp_n_bool_1, i0_nullable.is_null, ! i0_nullable.value);
-- + cql_set_nullable(_tmp_n_bool_0, _tmp_n_bool_1.is_null, ! _tmp_n_bool_1.value);
-- + cql_set_nullable(i1_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i1_nullable := NOT NOT i0_nullable;
-- + i2 = ! ! b2;
set i2 := NOT NOT b2;
-- TEST: not null arithmetic
-- + i2 = 1 * 3 + 5;
set i2 := 1 * 3 + 5;
-- TEST: everything in sight is nullable
-- + cql_combine_nullables(r0_nullable, r0_nullable.is_null, i1_nullable.is_null, r0_nullable.value * i1_nullable.value);
set r0_nullable := r0_nullable * i1_nullable;
-- TEST: right operand is not null
-- + cql_set_nullable(r0_nullable, r0_nullable.is_null, r0_nullable.value * i2);
set r0_nullable := r0_nullable * i2;
-- TEST: left operand is not null
-- + cql_set_nullable(i0_nullable, i1_nullable.is_null, 12 * i1_nullable.value);
set i0_nullable := 12 * i1_nullable;
-- TEST: an operaand is actually null
-- + cql_set_null(i0_nullable);
set i0_nullable := null * i1_nullable;
-- TEST: make sure the stacking is working correctly
-- + cql_combine_nullables(_tmp_n_double_1, r0_nullable.is_null, i1_nullable.is_null, r0_nullable.value * i1_nullable.value);
-- + cql_combine_nullables(_tmp_n_double_2, r0_nullable.is_null, i1_nullable.is_null, r0_nullable.value * i1_nullable.value);
-- + cql_combine_nullables(r0_nullable, _tmp_n_double_1.is_null, _tmp_n_double_2.is_null, _tmp_n_double_1.value + _tmp_n_double_2.value);
set r0_nullable := r0_nullable * i1_nullable + r0_nullable * i1_nullable;
-- TEST: a more complex stacking example
-- + cql_combine_nullables(_tmp_n_double_2, r0_nullable.is_null, i1_nullable.is_null, r0_nullable.value * i1_nullable.value);
-- + cql_combine_nullables(_tmp_n_double_3, r0_nullable.is_null, i0_nullable.is_null, r0_nullable.value * i0_nullable.value);
-- + cql_combine_nullables(_tmp_n_double_1, _tmp_n_double_2.is_null, _tmp_n_double_3.is_null, _tmp_n_double_2.value + _tmp_n_double_3.value);
-- + cql_combine_nullables(r0_nullable, _tmp_n_double_1.is_null, r0_nullable.is_null, _tmp_n_double_1.value + r0_nullable.value);
set r0_nullable := (r0_nullable * i1_nullable + r0_nullable * i0_nullable) + r0_nullable;
-- TEST: string assignment -- nasty string
-- + cql_set_string_ref(&t2, _literal%This_is_a_test_);
set t2 := "This is a \" \\ test '' \n \" ";
-- TEST: call an external procedure (type not known)
-- + printf("Hello, world\n");
call printf("Hello, world\n");
-- TEST: logical AND with short circuit
-- + i2 = r2 && l2;
set i2 := r2 and l2;
-- helper methods for the next test
declare function side_effect1() integer;
declare function side_effect2() integer;
-- TEST: the operands have side effects, the short circuit must not
-- do the evaluation of the side effect for the second arg if the first
-- returns false. This is the trickiest case because ti looks like it's
-- safe to use the (x && y) form because the operands are non-null.
-- it isn't though because there was expression work to get to the non-null
-- state. The Coalesce is important to this test for that reason.
-- + do {
-- + _tmp_n_int_3 = side_effect1();
-- + if (!_tmp_n_int_3.is_null) {
-- + _tmp_int_2 = _tmp_n_int_3.value;
-- + break;
-- + }
-- + _tmp_int_2 = 7;
-- + } while (0);
-- + if (!(_tmp_int_2)) {
-- + _tmp_bool_0 = 0;
-- + }
-- + else {
-- + _tmp_n_int_2 = side_effect2();
-- + if (!_tmp_n_int_2.is_null) {
-- + _tmp_int_1 = _tmp_n_int_2.value;
-- + break;
-- + }
-- + _tmp_int_1 = 5;
-- + } while (0);
-- + _tmp_bool_0 = !!(_tmp_int_1);
-- + }
-- + i2 = _tmp_bool_0;
set i2 := coalesce(side_effect1(), 7) and coalesce(side_effect2(), 5);
-- TEST: trival NULL on AND
-- + cql_set_null(_tmp_n_bool_0);
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := NULL and NULL;
-- TEST: logical AND with nullables
-- + if (cql_is_nullable_false(i0_nullable.is_null, i0_nullable.value))
-- + if (cql_is_nullable_false(i1_nullable.is_null, i1_nullable.value))
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := i0_nullable and i1_nullable;
-- TEST: logical AND with constant nulls
-- + if (cql_is_nullable_false(i1_nullable.is_null, i1_nullable.value))
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := NULL and i1_nullable;
-- TEST: logical AND with constant nulls
-- + if (cql_is_nullable_false(i0_nullable.is_null, i0_nullable.value))
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := i0_nullable and NULL;
-- TEST: logical OR with short circuit
-- + i2 = r2 || l2;
set i2 := r2 or l2;
-- TEST: complex side effect, looks safe but it isn't because of codegen
-- + do {
-- + _tmp_n_int_3 = side_effect1();
-- + if (!_tmp_n_int_3.is_null) {
-- + _tmp_int_2 = _tmp_n_int_3.value;
-- + break;
-- + }
-- + _tmp_int_2 = 7;
-- + } while (0);
-- + if (_tmp_int_2) {
-- + _tmp_bool_0 = 1;
-- + }
-- + else {
-- + do {
-- + _tmp_n_int_2 = side_effect2();
-- + if (!_tmp_n_int_2.is_null) {
-- + _tmp_int_1 = _tmp_n_int_2.value;
-- + break;
-- + }
-- + _tmp_int_1 = 5;
-- + } while (0);
-- + _tmp_bool_0 = !!(_tmp_int_1);
-- + }
-- + i2 = _tmp_bool_0;
set i2 := coalesce(side_effect1(), 7) or coalesce(side_effect2(), 5);
-- TEST: trival NULL on OR
-- + cql_set_null(_tmp_n_bool_0);
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := NULL or NULL;
-- TEST: logical OR with nullables
-- + cql_is_nullable_true(i0_nullable.is_null, i0_nullable.value)
-- + cql_is_nullable_true(i1_nullable.is_null, i1_nullable.value)
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := i0_nullable or i1_nullable;
-- TEST: logical OR with constant nulls
-- + cql_is_nullable_true(i1_nullable.is_null, i1_nullable.value)
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := NULL or i1_nullable;
-- TEST: logical OR with constant nulls
-- + cql_is_nullable_true(i0_nullable.is_null, i0_nullable.value)
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := i0_nullable or NULL;
-- TEST: is null basic test
-- + i2 = 1;
set i2 := null is null;
-- TEST: is null test non-null subexpression
-- + i2 = 0;
set i2 := (1+2*3) is null;
-- TEST: is null test general case
-- + cql_combine_nullables(_tmp_n_int_0, i0_nullable.is_null, i1_nullable.is_null, i0_nullable.value + i1_nullable.value);
-- + i2 = _tmp_n_int_0.is_null;
set i2 := (i0_nullable + i1_nullable) is null;
-- TEST: is not null basic test
-- + i2 = !1;
set i2 := null is not null;
-- TEST: is not null test non-null subexpression
-- + i2 = 1;
set i2 := (1+2*3) is not null;
-- TEST: is not null test general case
-- + cql_combine_nullables(_tmp_n_int_0, i0_nullable.is_null, i1_nullable.is_null, i0_nullable.value + i1_nullable.value);
-- + i2 = !_tmp_n_int_0.is_null;
set i2 := (i0_nullable + i1_nullable) is not null;
-- TEST: complex if/else pattern
-- Note: of interest because the embedded nullable
-- comparison requires statements to compute
-- + if (1) {
-- + i2 = 1;
-- + }
-- + else {
-- + cql_combine_nullables(_tmp_n_bool_0, i0_nullable.is_null, i1_nullable.is_null, i0_nullable.value == i1_nullable.value);
-- + if (cql_is_nullable_true(_tmp_n_bool_0.is_null, _tmp_n_bool_0.value)) {
-- + i2 = 2;
-- + }
-- + else {
-- + i2 = 3;
-- + }
-- + }
-- +4 {
-- +4 }
-- +2 else {
if 1 then
set i2 := 1;
else if i0_nullable == i1_nullable then
set i2 := 2;
else
set i2 := 3;
end if;
-- TEST: complex if/else pattern, embedded logical operation
-- Note: of interest because the embedded logical requires
-- statements to compute
-- validating the bits are are unique to this construct
-- + if (cql_is_nullable_true(i0_nullable.is_null, i0_nullable.value)) {
-- + if (cql_is_nullable_true(i1_nullable.is_null, i1_nullable.value)) {
-- + if (cql_is_nullable_true(_tmp_n_bool_0.is_null, _tmp_n_bool_0.value)) {
if 1 then
set i2 := 1;
else if i0_nullable or i1_nullable then
set i2 := 2;
else
set i2 := 3;
end if;
-- TEST: simple procedure with external call
-- + void test(cql_int32 i) {
-- + if (i) {
-- + puts("true");
create procedure test(i integer not null)
begin
if i then
call puts('true');
end if;
end;
-- TEST: simple between
-- + SET b2 := BETWEEN REWRITE _between_0_ := 1 CHECK (_between_0_ >= 0 AND _between_0_ <= 3);
-- + _between_0_ = 1;
-- + b2 = _between_0_ >= 0 && _between_0_ <= 3;
set b2 := 1 between 0 and 3;
-- TEST: between with some nullables
-- + SET i0_nullable := BETWEEN REWRITE _between_1_ := i1_nullable CHECK (_between_1_ >= i0_nullable AND _between_1_ <= r2);
-- + cql_set_nullable(_between_1_, i1_nullable.is_null, i1_nullable.value);
-- + cql_combine_nullables(_tmp_n_bool_2, _between_1_.is_null, i0_nullable.is_null, _between_1_.value >= i0_nullable.value);
-- + if (cql_is_nullable_false(_tmp_n_bool_2.is_null, _tmp_n_bool_2.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + }
-- + else {
-- + cql_set_nullable(_tmp_n_bool_1, _between_1_.is_null, _between_1_.value <= r2);
-- + if (cql_is_nullable_false(_tmp_n_bool_1.is_null, _tmp_n_bool_1.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + }
-- + else {
-- + cql_combine_nullables(_tmp_n_bool_0, _tmp_n_bool_2.is_null, _tmp_n_bool_1.is_null, 1);
-- + }
-- + }
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := i1_nullable between i0_nullable and r2;
-- TEST: between with different nullables
-- + SET i0_nullable := BETWEEN REWRITE _between_2_ := i1_nullable CHECK (_between_2_ >= r2 AND _between_2_ <= i0_nullable);
-- + cql_set_nullable(_between_2_, i1_nullable.is_null, i1_nullable.value);
-- + cql_set_nullable(_tmp_n_bool_2, _between_2_.is_null, _between_2_.value >= r2);
-- + if (cql_is_nullable_false(_tmp_n_bool_2.is_null, _tmp_n_bool_2.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + }
-- + else {
-- + cql_combine_nullables(_tmp_n_bool_1, _between_2_.is_null, i0_nullable.is_null, _between_2_.value <= i0_nullable.value);
-- + if (cql_is_nullable_false(_tmp_n_bool_1.is_null, _tmp_n_bool_1.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + }
-- + else {
-- + cql_combine_nullables(_tmp_n_bool_0, _tmp_n_bool_2.is_null, _tmp_n_bool_1.is_null, 1);
-- + }
-- + }
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := i1_nullable between r2 and i0_nullable;
-- TEST: simple not between
-- + SET b2 := BETWEEN REWRITE _between_3_ := 1 CHECK (_between_3_ < 0 OR _between_3_ > 3);
-- + _between_3_ = 1;
-- + b2 = _between_3_ < 0 || _between_3_ > 3;
set b2 := 1 not between 0 and 3;
-- TEST: not between with some nullables
-- + SET i0_nullable := BETWEEN REWRITE _between_4_ := i1_nullable CHECK (_between_4_ < i0_nullable OR _between_4_ > r2);
-- + cql_set_nullable(_between_4_, i1_nullable.is_null, i1_nullable.value);
-- + cql_combine_nullables(_tmp_n_bool_2, _between_4_.is_null, i0_nullable.is_null, _between_4_.value < i0_nullable.value);
-- + if (cql_is_nullable_true(_tmp_n_bool_2.is_null, _tmp_n_bool_2.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + }
-- + else {
-- + cql_set_nullable(_tmp_n_bool_1, _between_4_.is_null, _between_4_.value > r2);
-- + if (cql_is_nullable_true(_tmp_n_bool_1.is_null, _tmp_n_bool_1.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + }
-- + else {
-- + cql_combine_nullables(_tmp_n_bool_0, _tmp_n_bool_2.is_null, _tmp_n_bool_1.is_null, 0);
-- + }
-- + }
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := i1_nullable not between i0_nullable and r2;
-- TEST: not between with different nullables
-- + SET i0_nullable := BETWEEN REWRITE _between_5_ := i1_nullable CHECK (_between_5_ < r2 OR _between_5_ > i0_nullable);
-- + cql_set_nullable(_between_5_, i1_nullable.is_null, i1_nullable.value);
-- + cql_set_nullable(_tmp_n_bool_2, _between_5_.is_null, _between_5_.value < r2);
-- + if (cql_is_nullable_true(_tmp_n_bool_2.is_null, _tmp_n_bool_2.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + }
-- + else {
-- + cql_combine_nullables(_tmp_n_bool_1, _between_5_.is_null, i0_nullable.is_null, _between_5_.value > i0_nullable.value);
-- + if (cql_is_nullable_true(_tmp_n_bool_1.is_null, _tmp_n_bool_1.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + }
-- + else {
-- + cql_combine_nullables(_tmp_n_bool_0, _tmp_n_bool_2.is_null, _tmp_n_bool_1.is_null, 0);
-- + }
-- + }
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := i1_nullable not between r2 and i0_nullable;
-- TEST: out parameter test
-- + void out_test(cql_int32 *_Nonnull i, cql_nullable_int32 *_Nonnull ii) {
-- + *i = i2;
-- + cql_set_nullable(*ii, i0_nullable.is_null, i0_nullable.value);
-- + }
create procedure out_test(out i integer not null, out ii integer)
begin
set i := i2;
set ii := i0_nullable;
end;
-- TEST: force a cql_int64 variable to be pushed on the scratch stack
-- + cql_nullable_int64 longint_var;
declare longint_var long integer;
-- + cql_combine_nullables(_tmp_n_int64_1, l0_nullable.is_null, l1_nullable.is_null, l0_nullable.value + l1_nullable.value);
-- + cql_set_nullable(longint_var, _tmp_n_int64_1.is_null, _tmp_n_int64_1.value * 5);
set longint_var := (l0_nullable + l1_nullable) * 5;
-- TEST: make a cursor
-- + _rc_ = cql_prepare(_db_, &foo_cursor,
-- + "SELECT id, ? "
-- + "FROM foo "
-- + "WHERE id = ?"
-- + cql_multibind(&_rc_, _db_, &foo_cursor, 2,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, i2,
-- + CQL_DATA_TYPE_INT32, &i0_nullable);
-- + if (_rc_ != SQLITE_OK) { cql_error_trace(); goto cql_cleanup; }
declare foo_cursor cursor for select id, i2 from foo where id = i0_nullable;
-- TEST: fetch a cursor
-- + _rc_ = sqlite3_step(foo_cursor);
-- + _rc_ = sqlite3_step(foo_cursor);
-- + _foo_cursor_has_row_ = _rc_ == SQLITE_ROW;
-- + cql_multifetch(_rc_, foo_cursor, 2,
-- + CQL_DATA_TYPE_INT32, &i0_nullable,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, &i2);
-- + if (_rc_ != SQLITE_ROW && _rc_ != SQLITE_DONE) { cql_error_trace(); goto cql_cleanup; }
fetch foo_cursor into i0_nullable, i2;
-- TEST: test elementary cursor on select with no tables, still round trips through sqlite
declare col1 integer;
declare col2 real not null;
-- + _rc_ = cql_prepare(_db_, &basic_cursor,
declare basic_cursor cursor for select 1, 2.5;
open basic_cursor;
-- + cql_multifetch(_rc_, basic_cursor, 2,
-- + CQL_DATA_TYPE_INT32, &col1,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_DOUBLE, &col2);
fetch basic_cursor into col1, col2;
-- + cql_finalize_stmt(&basic_cursor);
close basic_cursor;
-- TEST: the most expensive way to swap two variables ever :)
declare arg1 integer not null;
declare arg2 integer not null;
set arg1 := 7;
set arg2 := 11;
-- + _rc_ = cql_prepare(_db_, &exchange_cursor,
-- + cql_multibind(&_rc_, _db_, &exchange_cursor, 2,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, arg2,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, arg1);
declare exchange_cursor cursor for select arg2, arg1;
open exchange_cursor;
-- + cql_multifetch(_rc_, exchange_cursor, 2,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, &arg1,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, &arg2);
fetch exchange_cursor into arg1, arg2;
-- + cql_finalize_stmt(&exchange_cursor);
close exchange_cursor;
-- TEST: simple nested select
-- + _rc_ = cql_prepare(_db_, &_temp_stmt,
-- + "SELECT ? + 1"
-- + cql_multibind(&_rc_, _db_, &_temp_stmt, 1,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, i2);
-- + if (_rc_ != SQLITE_OK) { cql_error_trace(); goto cql_cleanup; }
-- + _rc_ = sqlite3_step(_temp_stmt);
-- + if (_rc_ != SQLITE_ROW) { cql_error_trace(); goto cql_cleanup; }
-- + i2 = sqlite3_column_int(_temp_stmt, 0);
-- + cql_finalize_stmt(&_temp_stmt);
set i2 := (select i2+1);
-- TEST: nested select with nullable
-- validate just the different bit
-- + cql_multibind(&_rc_, _db_, &_temp_stmt, 1,
-- + CQL_DATA_TYPE_INT32, &i0_nullable);
set i0_nullable := (select i0_nullable+1);
-- TEST: tricky quoted text
-- this validates that the C escaping works right when making SQL
-- + "DELETE FROM bar WHERE name LIKE '\\\\ \" \\n'"
delete from bar where name like '\\ " \n';
-- TEST: binding an out parameter
-- + cql_multibind(&_rc_, _db_, &_temp_stmt, 1,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, *foo);
create procedure outparm_test(out foo integer not null)
begin
set foo := 1;
delete from bar where id = foo;
end;
-- TEST: a simple stored proc that throws
-- + if (_rc_ != SQLITE_OK) { cql_error_trace(); goto catch_start_1; }
-- + goto catch_end_1;
-- + catch_start_1: {
-- + printf("error\n");
-- + _rc_ = cql_best_error(_rc_thrown_);
-- + goto cql_cleanup;
-- + catch_end_1:
-- + _rc_ = SQLITE_OK;
-- + cql_cleanup:
create procedure throwing()
begin
begin try
delete from bar;
end try;
begin catch
call printf("error\n");
throw;
end catch;
end;
-- TEST: a simple case expression
-- + do {
-- + if (1) {
-- + i2 = 100;
-- + break;
-- + }
-- + if (2) {
-- + i2 = 200;
-- + break;
-- + }
-- + i2 = 300;
-- + } while (0);
set i2 := case when 1 then 100 when 2 then 200 when null then 500 else 300 end;
-- TEST: a simple in expression
-- + do {
-- + _tmp_int_% = 3;
-- + _tmp_bool_0 = 1;
-- + if (_tmp_int_% == 1) break;
-- + if (_tmp_int_% == 2) break;
-- + if (_tmp_int_% == 4) break;
-- + _tmp_bool_0 = 0;
-- + } while (0);
-- + i2 = _tmp_bool_0;
set i2 := 3 in (1, 2, null, 4);
-- TEST: in with nullables
-- + do {
-- + cql_set_nullable(_tmp_n_int_%, i1_nullable.is_null, i1_nullable.value);
-- + if (_tmp_n_int_%.is_null) {
-- + cql_set_null(_tmp_n_bool_0);
-- + break;
-- + }
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + if (_tmp_n_int_%.value == 1) break;
-- + if (_tmp_n_int_%.value == 2) break;
-- + if (cql_is_nullable_true(b0_nullable.is_null, _tmp_n_int_%.value == b0_nullable.value)) break;
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + } while (0);
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := i1_nullable in (1, 2, null, b0_nullable);
-- TEST: a simple not in expression
-- + do {
-- + _tmp_int_% = 3;
-- + _tmp_bool_0 = 0;
-- + if (_tmp_int_% == 1) break;
-- + if (_tmp_int_% == 2) break;
-- + if (_tmp_int_% == 4) break;
-- + _tmp_bool_0 = 1;
-- + } while (0);
-- + i2 = _tmp_bool_0;
set i2 := 3 not in (1, 2, null, 4);
-- TEST: not in with nullables
-- + do {
-- + cql_set_nullable(_tmp_n_int_%, i1_nullable.is_null, i1_nullable.value);
-- + if (_tmp_n_int_%.is_null) {
-- + cql_set_null(_tmp_n_bool_0);
-- + break;
-- + }
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + if (_tmp_n_int_%.value == 1) break;
-- + if (_tmp_n_int_%.value == 2) break;
-- + if (cql_is_nullable_true(b0_nullable.is_null, _tmp_n_int_%.value == b0_nullable.value)) break;
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + } while (0);
-- + cql_set_nullable(i0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set i0_nullable := i1_nullable not in (1, 2, null, b0_nullable);
-- TEST: between with strings
-- + SET b2 := BETWEEN REWRITE _between_6_ := 'b' CHECK (_between_6_ >= 'a' AND _between_6_ <= 'c');
-- + cql_set_string_ref(&_between_6_, _literal_2_b_);
-- + b2 = cql_string_compare(_between_6_, _literal_4_a_) >= 0 && cql_string_compare(_between_6_, _literal_3_c_) <= 0;
set b2 := 'b' between 'a' and 'c';
-- TEST: between with nullable strings right
-- + SET b0_nullable := BETWEEN REWRITE _between_7_ := 'b' CHECK (_between_7_ >= 'a' AND _between_7_ <= t0_nullable);
-- + cql_set_string_ref(&_between_7_, _literal_2_b_);
-- + if (!(cql_string_compare(_between_7_, _literal_4_a_) >= 0)) {
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + }
-- + else {
-- + cql_combine_nullables(_tmp_n_bool_1, !_between_7_, !t0_nullable, cql_string_compare(_between_7_, t0_nullable) <= 0);
-- + if (cql_is_nullable_false(_tmp_n_bool_1.is_null, _tmp_n_bool_1.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + }
-- + else {
-- + cql_set_nullable(_tmp_n_bool_0, _tmp_n_bool_1.is_null, 1);
-- + }
-- + }
-- + cql_set_nullable(b0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set b0_nullable := 'b' between 'a' and t0_nullable;
-- TEST: between with nullable strings left
-- + SET b0_nullable := BETWEEN REWRITE _between_8_ := 'b' CHECK (_between_8_ >= t0_nullable AND _between_8_ <= 'c');
-- + cql_set_string_ref(&_between_8_, _literal_2_b_);
-- + cql_combine_nullables(_tmp_n_bool_2, !_between_8_, !t0_nullable, cql_string_compare(_between_8_, t0_nullable) >= 0);
-- + if (cql_is_nullable_false(_tmp_n_bool_2.is_null, _tmp_n_bool_2.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + }
-- + else {
-- + if (!(cql_string_compare(_between_8_, _literal_3_c_) <= 0)) {
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + }
-- + else {
-- + cql_set_nullable(_tmp_n_bool_0, _tmp_n_bool_2.is_null, 1);
-- + }
-- + }
-- + cql_set_nullable(b0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set b0_nullable := 'b' between t0_nullable and 'c';
-- TEST: between with nullable strings null operand
-- + SET b0_nullable := BETWEEN REWRITE _between_9_ := 'b' CHECK (_between_9_ >= NULL AND _between_9_ <= 'c');
-- + cql_set_string_ref(&_between_9_, _literal_2_b_);
-- + cql_set_null(_tmp_n_bool_2);
-- + if (cql_is_nullable_false(_tmp_n_bool_2.is_null, _tmp_n_bool_2.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + }
-- + else {
-- + if (!(cql_string_compare(_between_9_, _literal_3_c_) <= 0)) {
-- + cql_set_notnull(_tmp_n_bool_0, 0);
-- + }
-- + else {
-- + cql_set_nullable(_tmp_n_bool_0, _tmp_n_bool_2.is_null, 1);
-- + }
-- + }
-- + cql_set_nullable(b0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set b0_nullable := 'b' between null and 'c';
-- TEST: not between with strings
-- + SET b2 := BETWEEN REWRITE _between_10_ := 'b' CHECK (_between_10_ < 'a' OR _between_10_ > 'c');
-- + cql_set_string_ref(&_between_10_, _literal_2_b_);
-- + b2 = cql_string_compare(_between_10_, _literal_4_a_) < 0 || cql_string_compare(_between_10_, _literal_3_c_) > 0;
set b2 := 'b' not between 'a' and 'c';
-- TEST: not between with nullable strings right
-- + SET b0_nullable := BETWEEN REWRITE _between_11_ := 'b' CHECK (_between_11_ < 'a' OR _between_11_ > t0_nullable);
-- + cql_set_string_ref(&_between_11_, _literal_2_b_);
-- + if (cql_string_compare(_between_11_, _literal_4_a_) < 0) {
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + }
-- + else {
-- + cql_combine_nullables(_tmp_n_bool_1, !_between_11_, !t0_nullable, cql_string_compare(_between_11_, t0_nullable) > 0);
-- + if (cql_is_nullable_true(_tmp_n_bool_1.is_null, _tmp_n_bool_1.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + }
-- + else {
-- + cql_set_nullable(_tmp_n_bool_0, _tmp_n_bool_1.is_null, 0);
-- + }
-- + }
-- + cql_set_nullable(b0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set b0_nullable := 'b' not between 'a' and t0_nullable;
-- TEST: not between with nullable strings left
-- + SET b0_nullable := BETWEEN REWRITE _between_12_ := 'b' CHECK (_between_12_ < t0_nullable OR _between_12_ > 'c');
-- + cql_set_string_ref(&_between_12_, _literal_2_b_);
-- + cql_combine_nullables(_tmp_n_bool_2, !_between_12_, !t0_nullable, cql_string_compare(_between_12_, t0_nullable) < 0);
-- + if (cql_is_nullable_true(_tmp_n_bool_2.is_null, _tmp_n_bool_2.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + }
-- + else {
-- + if (cql_string_compare(_between_12_, _literal_3_c_) > 0) {
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + }
-- + else {
-- + cql_set_nullable(_tmp_n_bool_0, _tmp_n_bool_2.is_null, 0);
-- + }
-- + }
-- + cql_set_nullable(b0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set b0_nullable := 'b' not between t0_nullable and 'c';
-- TEST: not between with nullable strings null operand
-- verify rewrite
-- + SET b0_nullable := BETWEEN REWRITE _between_13_ := 'b' CHECK (_between_13_ < NULL OR _between_13_ > 'c');
-- + cql_set_string_ref(&_between_%, _literal_%_b_);
-- + cql_set_null(_tmp_n_bool_2);
-- + if (cql_is_nullable_true(_tmp_n_bool_2.is_null, _tmp_n_bool_2.value)) {
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + }
-- + else {
-- + if (cql_string_compare(_between_%_, _literal_3_c_) > 0) {
-- + cql_set_notnull(_tmp_n_bool_0, 1);
-- + }
-- + else {
-- + cql_set_nullable(_tmp_n_bool_0, _tmp_n_bool_2.is_null, 0);
-- + }
-- + }
-- + cql_set_nullable(b0_nullable, _tmp_n_bool_0.is_null, _tmp_n_bool_0.value);
set b0_nullable := 'b' not between null and 'c';
-- TEST: this procedure will have a structured semantic type
-- + cql_string_literal(with_result_set_stored_procedure_name, "with_result_set");
-- + cql_code with_result_set(sqlite3 *_Nonnull _db_, sqlite3_stmt *_Nullable *_Nonnull _result_) {
-- + #define with_result_set_refs_offset cql_offsetof(with_result_set_row, name) // count = 1
-- + cql_int32 with_result_set_get_id(with_result_set_result_set_ref _Nonnull result_set, cql_int32 row) {
-- + cql_string_ref _Nullable with_result_set_get_name(with_result_set_result_set_ref _Nonnull result_set, cql_int32 row) {
-- + cql_bool with_result_set_get_rate_is_null(with_result_set_result_set_ref _Nonnull result_set, cql_int32 row) {
-- + cql_int64 with_result_set_get_rate_value(with_result_set_result_set_ref _Nonnull result_set, cql_int32 row) {
-- + cql_int32 with_result_set_get_type_value(with_result_set_result_set_ref _Nonnull result_set, cql_int32 row) {
-- + cql_int32 with_result_set_result_count(with_result_set_result_set_ref _Nonnull result_set) {
-- + CQL_WARN_UNUSED cql_code with_result_set_fetch_results(sqlite3 *_Nonnull _db_, with_result_set_result_set_ref _Nullable *_Nonnull result_set) {
-- + if (_rc_ == SQLITE_OK && !*_result_) _rc_ = SQLITE_ERROR;
create procedure with_result_set()
begin
select * from bar;
end;
-- TEST: grabs values from a view that is backed by a table
-- + cql_code select_from_view(sqlite3 *_Nonnull _db_, sqlite3_stmt *_Nullable *_Nonnull _result_) {
-- - .refs_count = 0,
-- - .refs_offset = 0,
-- + cql_int32 select_from_view_get_id(select_from_view_result_set_ref _Nonnull result_set, cql_int32 row) {
-- + cql_bool select_from_view_get_type_is_null(select_from_view_result_set_ref _Nonnull result_set, cql_int32 row) {
-- + cql_int32 select_from_view_get_type_value(select_from_view_result_set_ref _Nonnull result_set, cql_int32 row) {
-- + cql_int32 select_from_view_result_count(select_from_view_result_set_ref _Nonnull result_set) {
-- + CQL_WARN_UNUSED cql_code select_from_view_fetch_results(sqlite3 *_Nonnull _db_, select_from_view_result_set_ref _Nullable *_Nonnull result_set) {
create proc select_from_view()
begin
select id, type from baz;
end;
-- TEST: create dml for a view
-- + "CREATE VIEW MyView AS "
-- + "SELECT 1 AS f1, 2 AS f2, 3 AS f3"
create procedure make_view()
begin
create view MyView as select 1 as f1, 2 as f2, 3 as f3;
end;
-- TEST: code gen a simple create index statement
-- + "CREATE INDEX index_1 ON bar (id)"
create procedure make_index()
begin
create index index_1 on bar(id);
end;
-- TEST: create a proc with reader logic with more than one arg
-- + cql_code get_data(sqlite3 *_Nonnull _db_, sqlite3_stmt *_Nullable *_Nonnull _result_, cql_string_ref _Nonnull name_, cql_int32 id_) {
create procedure get_data(name_ text not null, id_ integer not null)
begin
select * from bar where id = id_ and name = name_;
end;
-- TEST: create a proc that uses the new cursor fetch strategy
-- then bind values from those implicit variables in a CQL statement
-- and also bind the _has_rows auto local as well
-- validate auto variable management
-- + #define easy_fetch_C_refs_offset cql_offsetof(easy_fetch_C_row, name) // count = 1
-- + easy_fetch_C_row C_ = { ._refs_count_ = 1, ._refs_offset_ = easy_fetch_C_refs_offset };
-- + sqlite3_stmt *C2 = NULL;
-- + cql_bool _C2_has_row_ = 0;
-- + C_._has_row_ = _rc_ == SQLITE_ROW;
-- + cql_multifetch(_rc_, C, 5,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, &C_.id,
-- + CQL_DATA_TYPE_STRING, &C_.name,
-- + CQL_DATA_TYPE_INT64, &C_.rate,
-- + CQL_DATA_TYPE_INT32, &C_.type,
-- + CQL_DATA_TYPE_DOUBLE, &C_.size);
-- + cql_multibind(&_rc_, _db_, &C2, 2,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_BOOL, C_._has_row_,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, C_.id);
-- + cql_finalize_stmt(&C);
-- + cql_teardown_row(C_);
-- + cql_finalize_stmt(&C2);
create proc easy_fetch()
begin
declare C cursor for select * from bar;
fetch C;
call printf("%d %s\n", C.id, C.name);
declare C2 cursor for select * from bar where C and id = C.id;
end;
-- TEST: safe not nullable assignment
-- + i2 = i0_nullable.value;
-- + i2 = 3;
set i2 := ifnull(i0_nullable, 3);
-- TEST: this works too, but the result might be nullable
-- + do {
-- + if (!i0_nullable.is_null) {
-- + cql_set_notnull(i0_nullable, i0_nullable.value);
-- + break;
-- + }
-- + cql_set_nullable(i0_nullable, i1_nullable.is_null, i1_nullable.value);
-- + } while (0);
set i0_nullable := ifnull(i0_nullable, i1_nullable);
-- TEST: create a proc that takes a nullable int and pass it a nullable int
-- this forces the case where the variable for the int has to be
-- reconstituted from the .value field
create proc copy_int(a int, out b int)
begin
set b := a;
end;
-- + copy_int(i0_nullable, &i1_nullable);
call copy_int(i0_nullable, i1_nullable);
-- TEST: try out last_insert_rowid()
-- + cql_set_notnull(row, sqlite3_last_insert_rowid(_db_));
-- - cql_cleanup
create proc insert_rowid_reader()
begin
declare row long integer;
set row := last_insert_rowid();
end;
-- TEST: try out changes()
-- + cql_set_notnull(ct, sqlite3_changes(_db_));
-- - cql_cleanup
create proc changes_reader()
begin
declare ct integer;
set ct := changes();
end;
-- TEST: try out printf expression
declare s text not null;
-- + _printf_result = sqlite3_mprintf("%d and %d", 1, 2);
-- + cql_string_release(s);
-- + s = cql_string_ref_new(_printf_result);
set s := printf('%d and %d', 1, 2);
-- + _printf_result = sqlite3_mprintf("%d and %d", 3, 4)
-- + cql_string_release(s);
-- + s = cql_string_ref_new(_printf_result);
set s := printf('%d and %d', 3, 4);
-- TEST: make sure that we use the canonical name for 's' in codegen not 'S'. Even though S is legal.
-- + cql_set_string_ref(&s, _literal%x_);
set S := 'x';
-- TEST: declare proc and call it
-- + /*
-- + DECLARE PROC xyzzy (id INTEGER) (A INTEGER NOT NULL);
-- + */
declare proc xyzzy(id integer) ( A integer not null );
-- + _rc_ = xyzzy(_db_, &xyzzy_cursor, _tmp_n_int_%);
-- + if (_rc_ != SQLITE_OK) { cql_error_trace(); goto cql_cleanup; }
create proc xyzzy_test()
begin
declare xyzzy_cursor cursor for call xyzzy(1);
end;
-- TEST: declare a simple proc with no dml
-- + /*
-- + DECLARE PROC plugh (id INTEGER);
-- + */
declare proc plugh(id integer);
-- TEST: create a proc that returns a mix of possible types
-- in a select
create proc complex_return()
begin
select cast(1 as bool) as _bool,
2 as _integer,
cast(3 as long integer) as _longint,
3.0 as _real,
'xyz' as _text,
cast(null as bool) as _nullable_bool;
end;
-- TEST: create a proc with a nested select within an in statement for hierarchical queries
create proc hierarchical_query(rate_ long integer not null, limit_ integer not null, offset_ integer not null)
begin
select *
from foo
where id in (
select id
from bar
where rate = rate_
order by name
limit limit_
offset offset_
)
order by id;
end;
-- TEST: create a proc with a nested select within a not in statement for hierarchical queries
create proc hierarchical_unmatched_query(rate_ long integer not null, limit_ integer not null, offset_ integer not null)
begin
select *
from foo
where id not in (
select id
from bar
where rate = rate_
order by name
limit limit_
offset offset_
)
order by id;
end;
-- TEST: create a proc with a compound select union form
create proc union_select()
begin
select 1 as A union select 2 as A;
end;
-- TEST: create a proc with a compound select union all form
create proc union_all_select()
begin
select 1 as A union all select 2 as A;
end;
-- TEST: create a valid union using not null columns and nullable matching
create proc union_all_with_nullable()
begin
select nullable('foo') as name
union all
select name from bar;
end;
-- TEST: create a simple with statement
create proc with_stmt_using_cursor()
begin
declare C cursor for
with X(a,b,c) as (select 1,2,3)
select * from X;
fetch C;
end;
-- TEST: with statement top level
create proc with_stmt()
begin
with X(a,b,c) as (select 1,2,3) select * from X;
end;
-- TEST: with recursive statement top level
create proc with_recursive_stmt()
begin
with recursive X(a,b,c) as (select 1,2,3 union all select 4,5,6) select * from X;
end;
-- TEST: parent procedure
create proc parent_proc()
begin
select 1 as one, 2 as two, 3 as three;
end;
-- TEST: child procedure
create proc parent_proc_child()
begin
select 4 as four, 5 as five, 6 as six;
end;
-- TEST: fetch nullable output parameter
-- + _C_has_row_ = _rc_ == SQLITE_ROW;
-- + cql_multifetch(_rc_, C, 1,
-- + CQL_DATA_TYPE_INT32, output);
-- + if (_rc_ != SQLITE_ROW && _rc_ != SQLITE_DONE) { cql_error_trace(); goto cql_cleanup; }
-- + *result = _C_has_row_;
create proc outint_nullable(out output integer, out result bool not null)
begin
declare C cursor for select 1;
fetch C into output;
set result := C;
END;
-- TEST: fetch not null output parameter
-- + cql_bool _C_has_row_ = 0;
-- + _C_has_row_ = _rc_ == SQLITE_ROW;
-- + cql_multifetch(_rc_, C, 1,
-- + CQL_DATA_TYPE_NOT_NULL | CQL_DATA_TYPE_INT32, output);
-- + if (_rc_ != SQLITE_ROW && _rc_ != SQLITE_DONE) { cql_error_trace(); goto cql_cleanup; }
-- + *result = _C_has_row_;