factor/extra/db/sqlite/sqlite-tests.factor

92 lines
2.3 KiB
Factor
Raw Normal View History

2008-02-01 18:43:44 -05:00
USING: io io.files io.launcher kernel namespaces
2008-02-04 14:32:27 -05:00
prettyprint tools.test db.sqlite db sequences
continuations db.types ;
2008-02-01 18:43:44 -05:00
IN: temporary
: test.db "extra/db/sqlite/test.db" resource-path ;
[ ] [ [ test.db delete-file ] ignore-errors ] unit-test
2008-02-01 18:43:44 -05:00
2008-02-04 14:57:22 -05:00
[ ] [
test.db [
"create table person (name varchar(30), country varchar(30))" sql-command
"insert into person values('John', 'America')" sql-command
"insert into person values('Jane', 'New Zealand')" sql-command
] with-sqlite
] unit-test
2008-02-01 18:43:44 -05:00
2008-02-04 14:57:22 -05:00
[ { { "John" "America" } { "Jane" "New Zealand" } } ] [
test.db [
"select * from person" sql-query
] with-sqlite
] unit-test
2008-02-01 18:43:44 -05:00
2008-02-04 14:57:22 -05:00
[ { { "John" "America" } } ] [
test.db [
2008-02-01 18:43:44 -05:00
"select * from person where name = :name and country = :country"
<simple-statement> [
{ { ":name" "Jane" TEXT } { ":country" "New Zealand" TEXT } }
over do-bound-query
2008-02-01 18:43:44 -05:00
{ { "Jane" "New Zealand" } } =
[ "test fails" throw ] unless
2008-02-01 18:43:44 -05:00
{ { ":name" "John" TEXT } { ":country" "America" TEXT } }
swap do-bound-query
] with-disposal
2008-02-01 18:43:44 -05:00
] with-sqlite
] unit-test
2008-02-04 14:57:22 -05:00
[ { { "1" "John" "America" } { "2" "Jane" "New Zealand" } } ]
[ test.db [ "select rowid, * from person" sql-query ] with-sqlite ] unit-test
2008-02-01 18:43:44 -05:00
2008-02-04 14:57:22 -05:00
[ ] [
test.db [
2008-02-01 18:43:44 -05:00
"insert into person(name, country) values('Jimmy', 'Canada')"
sql-command
2008-02-01 18:43:44 -05:00
] with-sqlite
] unit-test
[
{
{ "1" "John" "America" }
{ "2" "Jane" "New Zealand" }
{ "3" "Jimmy" "Canada" }
}
] [ test.db [ "select rowid, * from person" sql-query ] with-sqlite ] unit-test
2008-02-01 18:43:44 -05:00
[
test.db [
2008-02-01 18:43:44 -05:00
[
"insert into person(name, country) values('Jose', 'Mexico')" sql-command
"insert into person(name, country) values('Jose', 'Mexico')" sql-command
2008-02-01 18:43:44 -05:00
"oops" throw
] with-transaction
] with-sqlite
] must-fail
2008-02-01 18:43:44 -05:00
[ 3 ] [
test.db [
"select * from person" sql-query length
2008-02-01 18:43:44 -05:00
] with-sqlite
] unit-test
[
] [
test.db [
2008-02-01 18:43:44 -05:00
[
"insert into person(name, country) values('Jose', 'Mexico')"
sql-command
"insert into person(name, country) values('Jose', 'Mexico')"
sql-command
2008-02-01 18:43:44 -05:00
] with-transaction
] with-sqlite
] unit-test
[ 5 ] [
test.db [
"select * from person" sql-query length
2008-02-01 18:43:44 -05:00
] with-sqlite
] unit-test