-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprogram.bat
More file actions
1019 lines (919 loc) · 25.5 KB
/
program.bat
File metadata and controls
1019 lines (919 loc) · 25.5 KB
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
(println
"SQLite version "
(sqlite-libversion)
" ("
(sqlite-libversion-number)
") with amalgamation version "
(sqlite-sourceid)
crlf
"Threadsafe: "
(sqlite-threadsafe))
(deffunction expect (?expected ?actual ?failure-message)
(if (eq ?expected ?actual) then (print ".") else (println crlf "FAILURE: " ?failure-message crlf tab "Expected: " ?expected crlf tab "Actual: " ?actual)))
(expect
0
(sqlite-memory-used)
"Expected Memory Used before usage to be 0")
(expect
0
(sqlite-memory-highwater)
"Expected Memory Highwater before setting to be 0")
(expect
DEFAULT_RECURSIVE_TRIGGERS
(sqlite-compileoption-get 10)
"Expected compileoption 10 to be DEFAULT_RECURSIVE_TRIGGERS")
(expect
TRUE
(sqlite-compileoption-used DEFAULT_RECURSIVE_TRIGGERS)
"Expected compileoption DEFAULT_RECURSIVE_TRIGGERS to have been used")
(defglobal ?*db* = (sqlite-open :memory:))
(expect
1000000000
(sqlite-limit ?*db* 0)
"Checking 0 limit")
(expect
1000000000
(sqlite-limit ?*db* SQLITE_LIMIT_LENGTH)
"Checking SQLITE_LIMIT_LENGTH limit")
(expect
1000000000
(sqlite-limit ?*db* 0 999999999)
"Setting 0 limit")
(expect
999999999
(sqlite-limit ?*db* 0)
"Checking 0 limit")
(expect
999999999
(sqlite-limit ?*db* SQLITE_LIMIT_LENGTH 999999998)
"Setting SQLITE_LIMIT_LENGTH limit")
(expect
999999998
(sqlite-limit ?*db* 0)
"Checking 0 limit")
(expect
999999998
(sqlite-limit ?*db* SQLITE_LIMIT_LENGTH)
"Checking SQLITE_LIMIT_LENGTH limit")
(expect
1000000000
(sqlite-limit ?*db* 1)
"Checking 1 limit")
(expect
1000000000
(sqlite-limit ?*db* SQLITE_LIMIT_SQL_LENGTH)
"Checking SQLITE_LIMIT_SQL_LENGTH limit")
(expect
2000
(sqlite-limit ?*db* 2)
"Checking 2 limit")
(expect
2000
(sqlite-limit ?*db* SQLITE_LIMIT_COLUMN)
"Checking SQLITE_LIMIT_COLUMN limit")
(expect
1000
(sqlite-limit ?*db* 3)
"Checking 3 limit")
(expect
1000
(sqlite-limit ?*db* SQLITE_LIMIT_EXPR_DEPTH)
"Checking SQLITE_LIMIT_EXPR_DEPTH limit")
(expect
500
(sqlite-limit ?*db* 4)
"Checking 4 limit")
(expect
500
(sqlite-limit ?*db* SQLITE_LIMIT_COMPOUND_SELECT)
"Checking SQLITE_LIMIT_COMPOUND_SELECT limit")
(expect
250000000
(sqlite-limit ?*db* 5)
"Checking 5 limit")
(expect
250000000
(sqlite-limit ?*db* SQLITE_LIMIT_VDBE_OP)
"Checking SQLITE_LIMIT_VDBE_OP limit")
(expect
127
(sqlite-limit ?*db* 6)
"Checking 6 limit")
(expect
127
(sqlite-limit ?*db* SQLITE_LIMIT_FUNCTION_ARG)
"Checking SQLITE_LIMIT_FUNCTION_ARG limit")
(expect
10
(sqlite-limit ?*db* 7)
"Checking 7 limit")
(expect
10
(sqlite-limit ?*db* SQLITE_LIMIT_ATTACHED)
"Checking SQLITE_LIMIT_ATTACHED limit")
(expect
50000
(sqlite-limit ?*db* 8)
"Checking 8 limit")
(expect
50000
(sqlite-limit ?*db* SQLITE_LIMIT_LIKE_PATTERN_LENGTH)
"Checking SQLITE_LIMIT_LIKE_PATTERN_LENGTH limit")
(expect
250000
(sqlite-limit ?*db* 9)
"Checking 9 limit")
(expect
250000
(sqlite-limit ?*db* SQLITE_LIMIT_VARIABLE_NUMBER)
"Checking SQLITE_LIMIT_VARIABLE_NUMBER limit")
(expect
1000
(sqlite-limit ?*db* 10)
"Checking 10 limit")
(expect
1000
(sqlite-limit ?*db* SQLITE_LIMIT_TRIGGER_DEPTH)
"Checking SQLITE_LIMIT_TRIGGER_DEPTH limit")
(expect
0
(sqlite-limit ?*db* 11)
"Checking 11 limit")
(expect
0
(sqlite-limit ?*db* SQLITE_LIMIT_WORKER_THREADS)
"Checking SQLITE_LIMIT_WORKER_THREADS limit")
(expect
TRUE
(sqlite-busy-timeout ?*db* 0)
"Had issue setting busy timeout")
(defglobal ?*stmt-o* = (sqlite-prepare ?*db* "SELECT ?1, ?2, ?3"))
(expect
"SELECT ?1, ?2, ?3"
(sqlite-sql ?*stmt-o*)
"Encountered an issue with sqlite-sql")
(expect
"SELECT NULL, NULL, NULL"
(sqlite-expanded-sql ?*stmt-o*)
"Encountered an issue with sqlite-expanded-sql")
(expect
FALSE
(sqlite-close ?*db*)
"Expected to not be able to close db connection yet")
(expect
"unable to close due to unfinalized statements or unfinished backups"
(sqlite-errmsg ?*db*)
"Expected specific error message from sqlite-errmsg")
(expect
TRUE
(sqlite-bind ?*stmt-o* (create$ "alpha" 42 3.14))
"Encountered issue with sqlite-bind")
(expect
"SELECT 'alpha', 42, 3.14"
(sqlite-expanded-sql ?*stmt-o*)
"Encountered an issue with sqlite-expanded-sql after binding")
(expect
TRUE
(sqlite-clear-bindings ?*stmt-o*)
"Encountered issue with sqlite-clear-bindings")
(expect
"SELECT NULL, NULL, NULL"
(sqlite-expanded-sql ?*stmt-o*)
"Encountered an issue with sqlite-expanded-sql")
(expect
TRUE
(sqlite-bind ?*stmt-o* (create$ "alpha" 42 3.14))
"Encountered issue with sqlite-bind")
(expect
0
(sqlite-data-count ?*stmt-o*)
"Expected 0 columns of data before first sqlite-step")
(expect
SQLITE_ROW
(sqlite-step ?*stmt-o*)
"Expected SQLITE_ROW for first sqlite-step")
(expect
(create$ "alpha" 42 3.14)
(sqlite-row-to-multifield ?*stmt-o*)
"Expected multifield of row")
(expect
3
(sqlite-data-count ?*stmt-o*)
"Expected 3 columns of data after first sqlite-step")
(expect
FALSE
(sqlite-column-database-name ?*stmt-o* 1)
"Expected FALSE when getting database name from column")
(expect
FALSE
(sqlite-column-table-name ?*stmt-o* 1)
"Expected FALSE when getting table name from column")
(expect
FALSE
(sqlite-column-origin-name ?*stmt-o* 1)
"Expected FALSE when getting origin name from column")
(expect
SQLITE_DONE
(sqlite-step ?*stmt-o*)
"Expected SQLITE_DONE for second sqlite-step")
(expect
0
(sqlite-data-count ?*stmt-o*)
"Expected 0 columns of data after SQLITE_DONE sqlite-step")
(expect
(create$ nil nil nil)
(sqlite-row-to-multifield ?*stmt-o*)
"Expected a multifield filled with the number of column nils from SQLITE_DONE perpared statement")
(expect
TRUE
(sqlite-reset ?*stmt-o*)
"Expected to be able to reset statement")
(expect
SQLITE_ROW
(sqlite-step ?*stmt-o*)
"Expected SQLITE_ROW for first sqlite-step")
(expect
SQLITE_DONE
(sqlite-step ?*stmt-o*)
"Expected SQLITE_DONE for second sqlite-step")
(expect
TRUE
(sqlite-reset ?*stmt-o*)
"Expected to be able to reset statement")
(expect
SQLITE_ROW
(sqlite-step ?*stmt-o*)
"Expected SQLITE_ROW for first sqlite-step")
(expect
TRUE
(sqlite-reset ?*stmt-o*)
"Expected to be able to reset statement")
(expect
SQLITE_ROW
(sqlite-step ?*stmt-o*)
"Expected SQLITE_ROW for first sqlite-step after reset")
(expect
3
(sqlite-column-count ?*stmt-o*)
"Expected 3 columns for sqlite-column-count")
(expect
SQLITE_TEXT
(sqlite-column-type ?*stmt-o* 0)
"Expected SQLITE_TEXT for column 0's type")
(expect
"?1"
(sqlite-column-name ?*stmt-o* 0)
"Expected ?1 for column 0's name")
(expect
SQLITE_INTEGER
(sqlite-column-type ?*stmt-o* 1)
"Expected SQLITE_INTEGER for column 1's type")
(expect
"?2"
(sqlite-column-name ?*stmt-o* 1)
"Expected ?2 for column 1's name")
(expect
SQLITE_FLOAT
(sqlite-column-type ?*stmt-o* 2)
"Expected SQLITE_FLOAT for column 2's type")
(expect
"?3"
(sqlite-column-name ?*stmt-o* 2)
"Expected ?3 for column 2's name")
(expect
SQLITE_NULL
(sqlite-column-type ?*stmt-o* 3)
"Expected SQLITE_NULL for column 3's type")
(expect
FALSE
(sqlite-column-name ?*stmt-o* 3)
"Expected FALSE and an error message for column 3's name")
(expect
TRUE
(sqlite-finalize ?*stmt-o*)
"Expected to be able to finalize ?*stmt-o*")
(println)
(defglobal ?*stmt-p* = (sqlite-prepare ?*db* "SELECT ?1, ?2"))
(expect
"SELECT ?1, ?2"
(sqlite-sql ?*stmt-p*)
"Encountered an issue with sqlite-sql")
(expect
"SELECT NULL, NULL"
(sqlite-expanded-sql ?*stmt-p*)
"Encountered an issue with sqlite-expanded-sql")
(expect
TRUE
(sqlite-bind ?*stmt-p* 1 "first")
"Encountered an issue with binding to position 1")
(expect
"SELECT 'first', NULL"
(sqlite-expanded-sql ?*stmt-p*)
"Encountered an issue with sqlite-expanded-sql")
(expect
TRUE
(sqlite-bind ?*stmt-p* 2 "second")
"Encountered an issue with binding to position 2")
(expect
"SELECT 'first', 'second'"
(sqlite-expanded-sql ?*stmt-p*)
"Encountered an issue with sqlite-expanded-sql")
(expect
TRUE
(sqlite-finalize ?*stmt-p*)
"Expected to be able to finalize ?*stmt-p*")
(println)
(defglobal ?*stmt-n* = (sqlite-prepare ?*db* "SELECT :x AS xx, :y AS yy"))
(expect
:x
(sqlite-bind-parameter-name ?*stmt-n* 1)
"Expected to get first bind parameter name")
(expect
:y
(sqlite-bind-parameter-name ?*stmt-n* 2)
"Expected to get second bind parameter name")
(expect
1
(sqlite-bind-parameter-index ?*stmt-n* :x)
"Expected to be able to get index of :x bind parameter name")
(expect
2
(sqlite-bind-parameter-index ?*stmt-n* :y)
"Expected to be able to get index of :y bind parameter name")
(expect
SQLITE_NULL
(sqlite-column-type ?*stmt-n* 0)
"Expected SQLITE_NULL for column 0's type")
(expect
"xx"
(sqlite-column-name ?*stmt-n* 0)
"Expected xx for column 0's name")
(expect
SQLITE_NULL
(sqlite-column-type ?*stmt-n* 1)
"Expected SQLITE_NULL for column 1's type")
(expect
"yy"
(sqlite-column-name ?*stmt-n* 1)
"Expected yy for column 1's name")
(expect
SQLITE_NULL
(sqlite-column-type ?*stmt-n* 2)
"Expected SQLITE_NULL for column 2's type")
(expect
FALSE
(sqlite-column-name ?*stmt-n* 2)
"Expected FALSE for column 2's name")
(expect
"SELECT :x AS xx, :y AS yy"
(sqlite-sql ?*stmt-n*)
"Something went wrong with sqlite-sql")
(expect
"SELECT NULL AS xx, NULL AS yy"
(sqlite-expanded-sql ?*stmt-n*)
"Something went wrong with sqlite-expanded-sql before binding")
(expect
TRUE
(sqlite-bind ?*stmt-n* :x "hello")
"Encountered an issue with binding to named parameter :x")
(expect
"SELECT 'hello' AS xx, NULL AS yy"
(sqlite-expanded-sql ?*stmt-n*)
"Something went wrong with sqlite-expanded-sql after first binding")
(expect
TRUE
(sqlite-bind ?*stmt-n* :y 123)
"Encountered an issue with binding to named parameter :y")
(expect
"SELECT 'hello' AS xx, 123 AS yy"
(sqlite-expanded-sql ?*stmt-n*)
"Something went wrong with sqlite-expanded-sql after second binding")
(expect
TRUE
(sqlite-reset ?*stmt-n*)
"Expected to be able to reset statement")
(expect
SQLITE_ROW
(sqlite-step ?*stmt-n*)
"Expected to be able to sqlite-step ?*stmt-n*")
(expect
SQLITE_TEXT
(sqlite-column-type ?*stmt-n* 0)
"Expected SQLITE_TEXT for column 0's type")
(expect
SQLITE_INTEGER
(sqlite-column-type ?*stmt-n* 1)
"Expected SQLITE_INTEGER for column 1's type")
(expect
SQLITE_NULL
(sqlite-column-type ?*stmt-n* 2)
"Expected SQLITE_NULL for column 2's type")
(expect
TRUE
(sqlite-finalize ?*stmt-n*)
"Expected to be able to finalize ?*stmt-n*")
(println)
(defglobal ?*stmt-m1* = (sqlite-prepare ?*db* "CREATE TABLE foos(id integer primary key autoincrement, name text)"))
(expect
SQLITE_DONE
(sqlite-step ?*stmt-m1*)
"Expected SQLITE_DONE from CREATE TABLE statement")
(expect 0
(sqlite-changes ?*db*)
"Expected no changes yet")
(expect 0
(sqlite-total-changes ?*db*)
"Expected no total-changes yet")
(expect 0
(sqlite-last-insert-rowid ?*db*)
"No idea what this should be")
(defglobal ?*stmt-m2* = (sqlite-prepare ?*db* "INSERT INTO foos (name) VALUES ('Foo baz'), ('Baz bat'), ('co cuz')"))
(expect
SQLITE_DONE
(sqlite-step ?*stmt-m2*)
"Expected SQLITE_DONE from INSERT INTO statement")
(expect 3
(sqlite-changes ?*db*)
"Expected 3 changes from first INSERT")
(expect 3
(sqlite-total-changes ?*db*)
"Expected 3 total-changes after first INSERT")
(expect 3
(sqlite-last-insert-rowid ?*db*)
"Last inserted rowid should be 3 after first 3 inserted records")
(defglobal ?*stmt-m3* = (sqlite-prepare ?*db* "INSERT INTO foos (name) VALUES ('one more')"))
(expect
SQLITE_DONE
(sqlite-step ?*stmt-m3*)
"Expected SQLITE_DONE from INSERT INTO statement")
(expect 1
(sqlite-changes ?*db*)
"Expected 1 changes from second INSERT")
(expect 4
(sqlite-total-changes ?*db*)
"Expected 4 total-changes after second INSERT")
(expect 4
(sqlite-last-insert-rowid ?*db*)
"Last inserted rowid should be 4 after second INSERT")
(defglobal ?*stmt-m4* = (sqlite-prepare ?*db* "SELECT * FROM foos WHERE id=? AND name LIKE ?"))
(expect
2
(sqlite-bind-parameter-count ?*stmt-m4*)
"Expected number of bind parameters to be 2")
(expect
TRUE
(sqlite-bind ?*stmt-m4* 1 1)
"Expected to be able to bind 1 to the first column id")
(expect
TRUE
(sqlite-bind ?*stmt-m4* 2 "%oo b%")
"Expected to be able to bind '%oo b%' to the first column name")
(expect
"SELECT * FROM foos WHERE id=? AND name LIKE ?"
(sqlite-sql ?*stmt-m4*)
"Issue when running sqlite-sql")
(expect
"SELECT * FROM foos WHERE id=1 AND name LIKE '%oo b%'"
(sqlite-expanded-sql ?*stmt-m4*)
"Expected id and LIKE to be replaced by bindings")
(expect
(create$ nil nil)
(sqlite-row-to-multifield ?*stmt-m4*)
"Expected column names from sqlite-row-to-multifield before sqlite-step")
(expect
SQLITE_ROW
(sqlite-step ?*stmt-m4*)
"Expected SQLITE_ROW from SELECT statement")
(expect
(create$ 1 "Foo baz")
(sqlite-row-to-multifield ?*stmt-m4*)
"Expected multifield of row")
(deftemplate row
(slot id)
(slot name))
(deftemplate @row
(slot @id)
(slot @name))
(deftemplate :row
(slot :id)
(slot :name))
(expect
(assert (row (id 1) (name "Foo baz")))
(sqlite-row-to-fact ?*stmt-m4* row)
"Expected fact of row")
(defglobal ?*stmt-m5* = (sqlite-prepare ?*db* "SELECT * FROM foos WHERE id=@id AND name LIKE @name"))
(defglobal ?*stmt-m6* = (sqlite-prepare ?*db* "SELECT * FROM foos WHERE id=:id AND name LIKE :name"))
(expect
TRUE
(sqlite-bind ?*stmt-m5* (assert (@row (@id 99) (@name "Some Name"))))
"Expected to be able to bind variables to a prepared statement via a fact")
(expect
"SELECT * FROM foos WHERE id=99 AND name LIKE 'Some Name'"
(sqlite-expanded-sql ?*stmt-m5*)
"Expected id and LIKE to be replaced by bindings")
(expect
TRUE
(sqlite-clear-bindings ?*stmt-m5*)
"Encountered issue with sqlite-clear-bindings for ?*stmt-m5*")
(expect
TRUE
(sqlite-bind ?*stmt-m6* (assert (:row (:id 99) (:name "Some Name"))))
"Expected to be able to bind variables to a prepared statement via a fact")
(expect
"SELECT * FROM foos WHERE id=99 AND name LIKE 'Some Name'"
(sqlite-expanded-sql ?*stmt-m6*)
"Expected id and LIKE to be replaced by bindings")
(expect
TRUE
(sqlite-clear-bindings ?*stmt-m6*)
"Encountered issue with sqlite-clear-bindings for ?*stmt-m6*")
(defclass ROW
(is-a USER)
(slot id)
(slot _name))
(defclass @ROW
(is-a USER)
(slot @id)
(slot @name))
(defclass :ROW
(is-a USER)
(slot :id)
(slot :name))
(defglobal ?*ins* = (make-instance of @ROW (@id 99) (@name "Some Name")))
(expect
TRUE
(sqlite-bind ?*stmt-m5* ?*ins*)
"Expected to be able to bind variables to a prepared statement via an instance")
(expect
"SELECT * FROM foos WHERE id=99 AND name LIKE 'Some Name'"
(sqlite-expanded-sql ?*stmt-m5*)
"Expected id and LIKE to be replaced by bindings from instance in ?*stmt-m5*")
(expect
TRUE
(sqlite-clear-bindings ?*stmt-m5*)
"Encountered issue with sqlite-clear-bindings for ?*stmt-m5*")
(expect
TRUE
(sqlite-bind ?*stmt-m5* (instance-address ?*ins*))
"Expected to be able to bind variables to a prepared statement via an instance")
(expect
"SELECT * FROM foos WHERE id=99 AND name LIKE 'Some Name'"
(sqlite-expanded-sql ?*stmt-m5*)
"Expected id and LIKE to be replaced by bindings from instance in ?*stmt-m5*")
(defglobal ?*ins* = (make-instance of :ROW (:id 99) (:name "Some Name")))
(expect
TRUE
(sqlite-bind ?*stmt-m6* ?*ins*)
"Expected to be able to bind variables to a prepared statement via an instance")
(expect
"SELECT * FROM foos WHERE id=99 AND name LIKE 'Some Name'"
(sqlite-expanded-sql ?*stmt-m6*)
"Expected id and LIKE to be replaced by bindings from instance in ?*stmt-m6*")
(expect
TRUE
(sqlite-clear-bindings ?*stmt-m6*)
"Encountered issue with sqlite-clear-bindings for ?*stmt-m6*")
(expect
TRUE
(sqlite-bind ?*stmt-m6* (instance-address ?*ins*))
"Expected to be able to bind variables to a prepared statement via an instance")
(expect
"SELECT * FROM foos WHERE id=99 AND name LIKE 'Some Name'"
(sqlite-expanded-sql ?*stmt-m6*)
"Expected id and LIKE to be replaced by bindings from instance in ?*stmt-m6*")
(defglobal ?*instance* = (sqlite-row-to-instance ?*stmt-m4* ROW))
(expect
1
(send ?*instance* get-id)
"Expected instance of row with id 1")
(expect
"Foo baz"
(send ?*instance* get-_name)
"Expected instance of row with name \"Foo baz\"")
(defglobal ?*instance* = (sqlite-row-to-instance ?*stmt-m4* ROW foo))
(expect
[foo]
(instance-name ?*instance*)
"Expected instance with name [foo]")
(expect
1
(send ?*instance* get-id)
"Expected instance of row with id 1")
(expect
"Foo baz"
(send ?*instance* get-_name)
"Expected instance of row with name \"Foo baz\"")
(defclass ROW2
(is-a USER)
(slot id)
(slot asdf))
(expect
TRUE
(sqlite-finalize ?*stmt-m5*)
"Expected to be able to finalize ?*stmt-m5*")
(expect
TRUE
(sqlite-finalize ?*stmt-m6*)
"Expected to be able to finalize ?*stmt-m6*")
(defglobal ?*instance* = (sqlite-row-to-instance ?*stmt-m4* ROW2 nil asdf))
(expect
1
(send ?*instance* get-id)
"Expected instance of row with id 1")
(expect
"Foo baz"
(send ?*instance* get-asdf)
"Expected instance of row with asdf \"Foo baz\"")
(expect
TRUE
(sqlite-db-exists ?*db* main)
"Expected database \"main\" to exist in ?*db*")
(expect
FALSE
(sqlite-db-exists ?*db* "temp")
"Expected database \"temp\" not to exist in ?*db*")
(expect
FALSE
(sqlite-db-exists ?*db* "asdf")
"Expected database \"asdf\" not to exist in ?*db*")
(expect
"main"
(sqlite-column-database-name ?*stmt-m4* 1)
"Expected database name for column to be \"main\"")
(expect
"foos"
(sqlite-column-table-name ?*stmt-m4* 1)
"Expected table name for column to be \"foos\"")
(expect
"name"
(sqlite-column-origin-name ?*stmt-m4* 1)
"Expected origin name for column to be \"name\"")
(expect
1
(sqlite-column ?*stmt-m4* 0)
"Expected value 1 for first column id")
(expect
"Foo baz"
(sqlite-column ?*stmt-m4* 1)
"Expected value 'Foo baz' for second column name")
(expect
TRUE
(sqlite-finalize ?*stmt-m1*)
"Expected to be able to finalize CREATE TABLE statement")
(expect
TRUE
(sqlite-reset ?*stmt-m2*)
"Expected to be able to reset INSERT statement before explaining with mode 1")
(expect
FALSE
(sqlite-stmt-isexplain ?*stmt-m2*)
"Expected isexplain to be FALSE before setting it")
(expect
TRUE
(sqlite-stmt-explain ?*stmt-m2* 1)
"Expected to be able to update INSERT statement into explain with mode 1")
(expect
"EXPLAIN"
(sqlite-stmt-isexplain ?*stmt-m2*)
"Expected isexplain to be EXPLAIN after setting it with mode 1")
(expect
SQLITE_ROW
(sqlite-step ?*stmt-m2*)
"Expected to be able to explain INSERT statement")
(expect
0
(sqlite-column ?*stmt-m2* 0)
"Expected to be able to read program counter from explain INSERT statement")
(expect
"Init"
(sqlite-column ?*stmt-m2* 1)
"Expected to be able to read name of operation from explain INSERT statement")
(expect
1
(sqlite-column ?*stmt-m2* 2)
"Expected to be able to read p1 from explain INSERT statement")
(expect
26
(sqlite-column ?*stmt-m2* 3)
"Expected to be able to read p2 from explain INSERT statement")
(expect
0
(sqlite-column ?*stmt-m2* 4)
"Expected to be able to read p3 from explain INSERT statement")
(expect
nil
(sqlite-column ?*stmt-m2* 5)
"Expected to be able to read p4 from explain INSERT statement")
(expect
0
(sqlite-column ?*stmt-m2* 6)
"Expected to be able to read p5 from explain INSERT statement")
(expect
nil
(sqlite-column ?*stmt-m2* 7)
"Expected to be able to read comment from explain INSERT statement")
(expect
TRUE
(sqlite-reset ?*stmt-m2*)
"Expected to be able to reset INSERT statement before explaining with mode 2")
(expect
TRUE
(sqlite-stmt-explain ?*stmt-m2* 2)
"Expected to be able to update INSERT statement into explain with mode 2")
(expect
"EXPLAIN QUERY PLAN"
(sqlite-stmt-isexplain ?*stmt-m2*)
"Expected isexplain to be EXPLAIN QUERY PLAN after setting it with mode 2")
(expect
SQLITE_ROW
(sqlite-step ?*stmt-m2*)
"Expected to be able to explain INSERT statement")
(expect
9
(sqlite-column ?*stmt-m2* 0)
"Expected to be able to read selectid from explain INSERT statement")
(expect
0
(sqlite-column ?*stmt-m2* 1)
"Expected to be able to read order from explain INSERT statement")
(expect
0
(sqlite-column ?*stmt-m2* 2)
"Expected to be able to read from from explain INSERT statement")
(expect
"SCAN 3-ROW VALUES CLAUSE"
(sqlite-column ?*stmt-m2* 3)
"Expected to be able to read description of how SQLite plans to execute the query from explain INSERT statement")
(expect
TRUE
(sqlite-finalize ?*stmt-m2*)
"Expected to be able to finalize INSERT statement")
(expect
TRUE
(sqlite-finalize ?*stmt-m3*)
"Expected to be able to finalize INSERT statement")
(expect
TRUE
(sqlite-finalize ?*stmt-m4*)
"Expected to be able to finalize SELECT statement")
(println)
(defglobal ?*db-in-memory* = (sqlite-open :memory:))
(expect
"main"
(sqlite-db-name ?*db-in-memory* 0)
"Something went wrong with sqlite-db-name")
(expect
"temp"
(sqlite-db-name ?*db-in-memory* 1)
"Something went wrong with sqlite-db-name")
(expect
FALSE
(sqlite-db-name ?*db-in-memory* 2)
"Something went wrong with sqlite-db-name")
(expect
FALSE
(sqlite-db-filename ?*db-in-memory* "main")
"Something went wrong with sqlite-db-filename getting main database from db-in-memory")
(expect
FALSE
(sqlite-db-filename ?*db-in-memory* "temp")
"Something went wrong with sqlite-db-filename getting temp database from db-in-memory")
(expect
TRUE
(sqlite-close ?*db-in-memory*)
"Expected to be able to close db-in-memory connection")
(defglobal ?*db-file* = (sqlite-open ./foo2.db))
(expect
"main"
(sqlite-db-name ?*db-file* 0)
"Something went wrong with sqlite-db-name")
(expect
"temp"
(sqlite-db-name ?*db-file* 1)
"Something went wrong with sqlite-db-name")
(expect
FALSE
(sqlite-db-name ?*db-file* 2)
"Something went wrong with sqlite-db-name")
(defglobal ?*filename* = (sqlite-db-filename ?*db-file* "main"))
(expect
"/foo2.db"
(sub-string (- (str-length ?*filename*) 7) (str-length ?*filename*) ?*filename*)
"Something went wrong with sqlite-db-filename when getting filename for main")
(expect
FALSE
(sqlite-db-filename ?*db-file* "temp")
"Something went wrong with sqlite-db-filename when getting filename for temp")
(defglobal ?*backup* = (sqlite-backup-init ?*db-file* "main" ?*db* "main"))
(defglobal ?*select* = (sqlite-prepare ?*db-file* "SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'"))
(expect
SQLITE_ROW
(sqlite-step ?*select*)
"Expected ?*select* to execute successfully and get number of tables")
(expect
0
(sqlite-column ?*select* 0)
"Expected ?*db-file* database to not have any tables yet")
(defglobal ?*pagecount* = (sqlite-backup-pagecount ?*backup*))
(defglobal ?*previous-pages* = (sqlite-backup-remaining ?*backup*))
(expect
?*pagecount*
?*previous-pages*
"Expected pagecount and number of pages remaining to be the same before stepping through backup")
(expect
SQLITE_DONE
(sqlite-backup-step ?*backup* -1)
"Expected negative number to backup all remaining pages")
(defglobal ?*new-pages* = (sqlite-backup-remaining ?*backup*))
(expect
0
?*new-pages*
"Expected no more remaining pages for backup")
(if (>= ?*previous-pages* ?*new-pages*) then (print ".") else (println crlf "FAILURE: expected previous pages to be bigger than new pages."))
(expect
TRUE
(sqlite-reset ?*select*)
"Expected to be able to reset ?*select*")
(expect
SQLITE_ROW
(sqlite-step ?*select*)
"Expected ?*select* to execute successfully and get number of tables after backup")
(expect
1
(sqlite-column ?*select* 0)
"Expected ?*db-file* database to have a single table after backup")
(expect
TRUE
(sqlite-finalize ?*select*)
"Expected to be able to finalize SELECT statement")
(expect
TRUE
(sqlite-backup-finish ?*backup*)
"Expected to be able to finish db-file backup")
(expect
TRUE
(sqlite-close ?*db-file*)
"Expected to be able to close db-file connection")
(expect
FALSE
(sqlite-db-readonly ?*db* "main")
"Expected main db in ?*db* to not be readonly")
(expect
FALSE
(sqlite-db-readonly ?*db* "temp")
"Expected main db in ?*db* to not have temp db")
(if (> (sqlite-memory-used) 0) then (print ".") else (println crlf "FAILURE: expected memory used to be greater than 0."))
(defglobal ?*previous-highwater* = (sqlite-memory-highwater TRUE))
(if (> ?*previous-highwater* (sqlite-memory-highwater TRUE)) then (print ".") else (println crlf "FAILURE: expected previous memory highwater to be greater what it is now."))
(expect
(sqlite-memory-used)
(sqlite-memory-highwater)
"Expected new highwater to equal memory used now")
(expect
TRUE
(sqlite-close ?*db*)
"Expected to be able to close db connection")
(defglobal ?*db-readonly* = (sqlite-open ./foo-readonly.db))
(expect
FALSE
(sqlite-db-readonly ?*db-readonly* "main")
"Expected main db in ?*db-readonly* to not be readonly")
(expect
TRUE
(sqlite-close ?*db-readonly*)
"Expected to be able to close ?*db-readonly* connection before re-opening as READONLY")
(defglobal ?*db-readonly* = (sqlite-open ./foo-readonly.db SQLITE_OPEN_READONLY))
(expect
TRUE
(sqlite-db-readonly ?*db-readonly* "main")
"Expected main db in ?*db-readonly* to be readonly")
(expect
TRUE
(sqlite-close ?*db-readonly*)
"Expected to be able to close ?*db-readonly* connection")
(defglobal ?*db-readonly2* = (sqlite-open ./foo-readonly2.db))
(expect
FALSE
(sqlite-db-readonly ?*db-readonly2* "main")
"Expected main db in ?*db-readonly2* to not be readonly")
(expect
TRUE
(sqlite-close ?*db-readonly2*)
"Expected to be able to close ?*db-readonly2* connection before re-opening as READONLY")
(defglobal ?*db-readonly2* = (sqlite-open ./foo-readonly2.db (create$ SQLITE_OPEN_READONLY)))
(expect