-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-test.r3
324 lines (261 loc) · 9.48 KB
/
ci-test.r3
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
Rebol [
title: "SQLite extension test"
needs: 3.13.1 ;; using system/options/modules as extension location
]
print ["Running test on Rebol build:" mold to-block system/build]
system/options/quiet: false
system/options/log/rebol: 4
if CI?: any [
"true" = get-env "CI"
"true" = get-env "GITHUB_ACTIONS"
"true" = get-env "TRAVIS"
"true" = get-env "CIRCLECI"
"true" = get-env "GITLAB_CI"
][
;; configure modules location for the CI test
system/options/modules: dirize to-rebol-file any [
get-env 'REBOL_MODULES_DIR
what-dir
]
;; make sure that we load a fresh extension
try [system/modules/sqlite: none]
]
sqlite: import 'sqlite
? sqlite
recycle/torture ; make sure that recycle issues are catched
print sqlite/info
with sqlite [
db: open %test.db
;? db
print info/of db
trace db 3 ;= SQLITE_TRACE_STMT or SQLITE_TRACE_PROFILE
print as-green "^/Testing that EXEC throws an error on invalid query"
print try [ exec db "INVALID" ]
exec db {
BEGIN TRANSACTION;
/* delete any tables used in the test */
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
DROP TABLE IF EXISTS Cars;
DROP TABLE IF EXISTS Authors;
DROP TABLE IF EXISTS Genres;
/* ---------------------------------- */
CREATE TABLE Cars(Id INTEGER PRIMARY KEY, Name TEXT, Price INTEGER);
INSERT INTO "Cars" VALUES(1,'Audi',52642);
INSERT INTO "Cars" VALUES(2,'Mercedes',57127);
INSERT INTO "Cars" VALUES(3,'Skoda',9000);
INSERT INTO "Cars" VALUES(4,'Volvo',29000);
INSERT INTO "Cars" VALUES(5,'Bentley',350000);
INSERT INTO "Cars" VALUES(6,'Citroen',21000);
INSERT INTO "Cars" VALUES(7,'Hummer',41400);
CREATE TABLE IF NOT EXISTS Authors (
author_id INTEGER PRIMARY KEY,
first_name TEXT,
family_name TEXT NOT NULL,
date_of_birth TEXT,
date_of_death TEXT
);
CREATE TABLE IF NOT EXISTS Genres (
genre_id INTEGER PRIMARY KEY,
name TEXT NOT NULL
);
COMMIT;}
exec db {INSERT INTO "Cars" VALUES(null,'Hummer',null);}
exec db "SELECT last_insert_rowid();"
exec db "SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"
exec db "SELECT * FROM Cars ORDER BY name"
exec db "SELECT hex(randomblob(16));"
stmt: prepare db "SELECT * FROM Cars ORDER BY name"
;? stmt
print info/of stmt
probe step stmt
finalize stmt
print info/of stmt
print as-green "^/Random bin generator..."
stmt: prepare db {select randomblob(16)}
name: columns stmt
loop 4 [
print [name #"=" step stmt]
reset stmt
]
finalize stmt
print as-green "^/Using prepared statements and input values..."
stmt: prepare db "SELECT * FROM Cars WHERE Price > ? ORDER BY name"
cols: columns stmt
? cols
probe step/with/rows stmt [20000] 100
probe step/with/rows stmt [40000.0] 100
finalize stmt
stmt: prepare db "SELECT * FROM Cars WHERE Name LIKE :pattern ORDER BY name"
probe step/with/rows stmt ["H%"] 100
; testing an input where index is not at its head
name: next "xA_di"
probe step/with/rows stmt reduce [name] 100
finalize stmt
print as-green "^/Testing STRICT keyword..."
exec db {CREATE TABLE t1(a ANY) STRICT;}
exec db {INSERT INTO t1 VALUES('000123');}
exec db {SELECT typeof(a), quote(a) FROM t1;} ;-- result: text '000123'
exec db {CREATE TABLE t2(a ANY);}
exec db {INSERT INTO t2 VALUES('000123');}
exec db {SELECT typeof(a), quote(a) FROM t2;} ;-- result: integer 123
print-horizontal-line
trace db 1 ;= SQLITE_TRACE_STMT
probe eval db [{INSERT INTO Genres (name) VALUES (?)} "Fantasy" "Science Fiction" "French Poetry" "Crime"]
probe eval db [{INSERT INTO Genres (name) VALUES (?)} "Comedy"]
last-id: sqlite/last-insert-id db
? last-id
print-horizontal-line
print as-yellow "Using eval command with string as a query..."
probe eval db sql: {SELECT * FROM Genres}
probe eval db [{SELECT * FROM Genres}] ;; in block, but no parameters
probe eval db [:sql] ;; in block as a word, but no parameters
;; also test, if query works when not at its head position
probe eval db next {XSELECT * FROM Genres}
probe eval db reduce [next {XSELECT * FROM Genres}]
print-horizontal-line
print as-yellow "Using prepared statement with eval..."
stmt-genres-like!: prepare db {SELECT Name FROM Genres WHERE Name LIKE :pattern}
probe eval db stmt-genres-like!
probe eval db [stmt-genres-like! "F%"]
probe eval db [stmt-genres-like! "C%"]
finalize stmt-genres-like!
print as-yellow "Using already finalized statement throws an error..."
print try [eval db [stmt-genres-like! "F%"]]
print-horizontal-line
print as-yellow "Using eval command with parameters in blocks..."
probe eval db [
{INSERT INTO Authors (first_name, family_name, date_of_birth, date_of_death) VALUES (?,?,?,?)}
["Patrick" "Rothfuss" "1973-06-06" none ]
["Ben" "Bova" "1932-11-08" none ]
["Isaac" "Asimov" "1920-01-02" "1992-04-06"]
["Bob" "Billings" ] ;; missing values are NULL
["Jim" "Jones" "1971-12-16" ] ;; missing values are NULL
]
probe eval db "SELECT family_name, date_of_birth FROM Authors"
print-horizontal-line
print as-yellow "Testing constraint error..."
;; family_name cannot be NULL, so there must be an error:
print try [
eval db [
{INSERT INTO Authors (first_name, family_name, date_of_birth, date_of_death) VALUES (?,?,?,?)}
"Jim" none "1971-12-16" none
]
]
print-horizontal-line
print as-yellow "Getting authors one by one..."
stmt: prepare db "SELECT * FROM Authors"
while [rec: step stmt] [ probe rec ]
finalize stmt
print as-green "^/Shutting down.."
print info
close db
probe shutdown
probe shutdown ; no-op
probe initialize
print info
print "SQLite tests done."
]
;------------------------------------------------------------------------------------------------
print-horizontal-line
print as-yellow "SQLITE SCHEME TESTS"
print-horizontal-line
import %sqlite-scheme.reb
if exists? %chinook.db [
db: open/new sqlite:chinook.db
probe read insert db {SELECT
InvoiceId,
BillingAddress,
date(InvoiceDate) InvoiceDate,
Total
FROM
invoices
WHERE
InvoiceDate NOT BETWEEN '2009-01-03' AND '2013-12-01'
ORDER BY
InvoiceDate;
}
]
;open sqlite:new.db ;; would throw an error, if the file ./new.db does not exists
;open sqlite:/home/oldes/new.db ;; used full path to the DB file
print-horizontal-line
prin as-yellow "Testing an error message, when trying to open a database using not existing dir."
print try [open/new sqlite:not-exists/dir]
;; Create a new DB file in the current dir, if it does not exists, and open it
db: open/new sqlite:new.db
;; Allow verbose SQLite traces...
modify db 'trace-level 3 ;= SQLITE_TRACE_STMT or SQLITE_TRACE_PROFILE
;; Execute multiple queries at once...
write db {
BEGIN TRANSACTION;
/* delete any tables used in the test */
DROP TABLE IF EXISTS t1;
DROP TABLE IF EXISTS t2;
DROP TABLE IF EXISTS Cars;
DROP TABLE IF EXISTS Contacts;
/* ---------------------------------- */
CREATE TABLE Cars(Id INTEGER PRIMARY KEY, Name TEXT, Price INTEGER);
INSERT INTO "Cars" VALUES(1,'Audi',52642);
INSERT INTO "Cars" VALUES(2,'Mercedes',57127);
INSERT INTO "Cars" VALUES(3,'Skoda',9000);
INSERT INTO "Cars" VALUES(4,'Volvo',29000);
INSERT INTO "Cars" VALUES(5,'Bentley',350000);
INSERT INTO "Cars" VALUES(6,'Citroen',21000);
INSERT INTO "Cars" VALUES(7,'Hummer',41400);
INSERT INTO "Cars" VALUES(NULL,'Audi',52642);
INSERT INTO "Cars" VALUES(NULL,'Mercedes',57127);
INSERT INTO "Cars" VALUES(NULL,'Skoda',9000);
INSERT INTO "Cars" VALUES(NULL,'Volvo',29000);
INSERT INTO "Cars" VALUES(NULL,'Bentley',350000);
INSERT INTO "Cars" VALUES(NULL,'Citroen',21000);
INSERT INTO "Cars" VALUES(NULL,'Hummer',41400);
INSERT INTO "Cars" VALUES(NULL,'Audi',52642);
INSERT INTO "Cars" VALUES(NULL,'Mercedes',57127);
INSERT INTO "Cars" VALUES(NULL,'Skoda',9000);
INSERT INTO "Cars" VALUES(NULL,'Volvo',29000);
INSERT INTO "Cars" VALUES(NULL,'Bentley',350000);
INSERT INTO "Cars" VALUES(NULL,'Citroen',21000);
INSERT INTO "Cars" VALUES(NULL,'Hummer',41400);
INSERT INTO "Cars" VALUES(NULL,'Audi',52642);
INSERT INTO "Cars" VALUES(NULL,'Mercedes',57127);
INSERT INTO "Cars" VALUES(NULL,'Skoda',9000);
INSERT INTO "Cars" VALUES(NULL,'Volvo',29000);
INSERT INTO "Cars" VALUES(NULL,'Bentley',350000);
INSERT INTO "Cars" VALUES(NULL,'Citroen',21000);
INSERT INTO "Cars" VALUES(NULL,'Hummer',41400);
INSERT INTO "Cars" VALUES(NULL,'Audi',52642);
INSERT INTO "Cars" VALUES(NULL,'Mercedes',57127);
INSERT INTO "Cars" VALUES(NULL,'Skoda',9000);
INSERT INTO "Cars" VALUES(NULL,'Volvo',29000);
INSERT INTO "Cars" VALUES(NULL,'Bentley',350000);
INSERT INTO "Cars" VALUES(NULL,'Citroen',21000);
INSERT INTO "Cars" VALUES(NULL,'Hummer',41400);
CREATE TABLE Contacts (
email TEXT PRIMARY KEY,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL
);
INSERT INTO "Contacts" VALUES('oceane.pacome@corporate.com', 'Océane', 'Pacôme');
INSERT INTO "Contacts" VALUES('Oldes@corporate.com','Oldes', 'Huhuman');
COMMIT;
}
print-horizontal-line
prin as-yellow "Testing an error message of the invalid query."
print try [insert db "INVALID_QUERY"]
print-horizontal-line
insert db "SELECT * FROM Cars" ;; Prepares a statement
print as-yellow "Resolving 10 rows one by one..."
loop 10 [probe take db]
print as-yellow "Resolving 5 rows at once..."
probe read/part db 5
print as-yellow "Resolving the rest of rows..."
probe read db
print-horizontal-line
print as-yellow "Resolving 4 random hexadecimal blobs"
insert db "SELECT hex(randomblob(16)), hex(randomblob(16)), hex(randomblob(16)), hex(randomblob(16))"
probe read db
print-horizontal-line
print as-yellow "Resolving all data using PICK action"
probe pick db "SELECT * FROM Contacts"
print as-yellow "DONE"
;quit