]> gitweb.factorcode.org Git - factor.git/blob - basis/db/sqlite/sqlite-tests.factor
Fix permission bits
[factor.git] / basis / db / sqlite / sqlite-tests.factor
1 USING: io io.files io.launcher kernel namespaces
2 prettyprint tools.test db.sqlite db sequences
3 continuations db.types db.tuples unicode.case ;
4 IN: db.sqlite.tests
5
6 : db-path "test.db" temp-file ;
7 : test.db db-path sqlite-db ;
8
9 [ ] [ [ db-path delete-file ] ignore-errors ] unit-test
10
11 [ ] [
12     test.db [
13         "create table person (name varchar(30), country varchar(30))" sql-command
14         "insert into person values('John', 'America')" sql-command
15         "insert into person values('Jane', 'New Zealand')" sql-command
16     ] with-db
17 ] unit-test
18
19
20 [ { { "John" "America" } { "Jane" "New Zealand" } } ] [
21     test.db [
22         "select * from person" sql-query
23     ] with-db
24 ] unit-test
25
26 [ { { "1" "John" "America" } { "2" "Jane" "New Zealand" } } ]
27 [ test.db [ "select rowid, * from person" sql-query ] with-db ] unit-test
28
29 [ ] [
30     test.db [
31         "insert into person(name, country) values('Jimmy', 'Canada')"
32         sql-command
33     ] with-db
34 ] unit-test
35
36 [
37     {
38         { "1" "John" "America" }
39         { "2" "Jane" "New Zealand" }
40         { "3" "Jimmy" "Canada" }
41     }
42 ] [ test.db [ "select rowid, * from person" sql-query ] with-db ] unit-test
43
44 [
45     test.db [
46         [
47             "insert into person(name, country) values('Jose', 'Mexico')" sql-command
48             "insert into person(name, country) values('Jose', 'Mexico')" sql-command
49             "oops" throw
50         ] with-transaction
51     ] with-db
52 ] must-fail
53
54 [ 3 ] [
55     test.db [
56         "select * from person" sql-query length
57     ] with-db
58 ] unit-test
59
60 [ ] [
61     test.db [
62         [
63             "insert into person(name, country) values('Jose', 'Mexico')"
64             sql-command
65             "insert into person(name, country) values('Jose', 'Mexico')"
66             sql-command
67         ] with-transaction
68     ] with-db
69 ] unit-test
70
71 [ 5 ] [
72     test.db [
73         "select * from person" sql-query length
74     ] with-db
75 ] unit-test