2008-02-01 18:43:44 -05:00
|
|
|
USING: io io.files io.launcher kernel namespaces
|
|
|
|
prettyprint tools.test db.sqlite db db.sql sequences
|
|
|
|
continuations ;
|
|
|
|
IN: temporary
|
|
|
|
|
|
|
|
! "sqlite3 -init test.txt test.db"
|
|
|
|
|
2008-02-03 16:06:31 -05:00
|
|
|
IN: scratchpad
|
2008-02-01 18:43:44 -05:00
|
|
|
: test.db "extra/db/sqlite/test.db" resource-path ;
|
|
|
|
|
2008-02-03 16:06:31 -05:00
|
|
|
IN: temporary
|
2008-02-01 18:43:44 -05:00
|
|
|
: (create-db) ( -- str )
|
|
|
|
[
|
|
|
|
"sqlite3 -init " %
|
2008-02-03 16:06:31 -05:00
|
|
|
test.db %
|
2008-02-01 18:43:44 -05:00
|
|
|
" " %
|
|
|
|
test.db %
|
|
|
|
] "" make ;
|
|
|
|
|
|
|
|
: create-db ( -- ) (create-db) run-process drop ;
|
|
|
|
|
|
|
|
[ ] [ test.db delete-file ] unit-test
|
|
|
|
|
|
|
|
[ ] [ create-db ] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
{ "John" "America" }
|
|
|
|
{ "Jane" "New Zealand" }
|
|
|
|
}
|
2008-02-03 00:28:33 -05:00
|
|
|
] [
|
2008-02-03 16:06:31 -05:00
|
|
|
test.db [
|
2008-02-03 00:28:33 -05:00
|
|
|
"select * from person" sql-query
|
|
|
|
] with-sqlite
|
|
|
|
] unit-test
|
2008-02-01 18:43:44 -05:00
|
|
|
|
|
|
|
[
|
|
|
|
{ { "John" "America" } }
|
|
|
|
] [
|
2008-02-03 16:06:31 -05:00
|
|
|
test.db [
|
2008-02-01 18:43:44 -05:00
|
|
|
"select * from person where name = :name and country = :country"
|
2008-02-03 00:28:33 -05:00
|
|
|
<simple-statement> [
|
|
|
|
{ { ":name" "Jane" } { ":country" "New Zealand" } }
|
|
|
|
over do-bound-query
|
2008-02-01 18:43:44 -05:00
|
|
|
|
2008-02-03 00:28:33 -05:00
|
|
|
{ { "Jane" "New Zealand" } } =
|
|
|
|
[ "test fails" throw ] unless
|
2008-02-01 18:43:44 -05:00
|
|
|
|
2008-02-03 00:28:33 -05:00
|
|
|
{ { ":name" "John" } { ":country" "America" } }
|
|
|
|
swap do-bound-query
|
|
|
|
] with-disposal
|
2008-02-01 18:43:44 -05:00
|
|
|
] with-sqlite
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
{ "1" "John" "America" }
|
|
|
|
{ "2" "Jane" "New Zealand" }
|
|
|
|
}
|
2008-02-03 00:28:33 -05:00
|
|
|
] [ test.db [ "select rowid, * from person" sql-query ] with-sqlite ] unit-test
|
2008-02-01 18:43:44 -05:00
|
|
|
|
|
|
|
[
|
|
|
|
] [
|
2008-02-03 16:06:31 -05:00
|
|
|
test.db [
|
2008-02-01 18:43:44 -05:00
|
|
|
"insert into person(name, country) values('Jimmy', 'Canada')"
|
2008-02-03 00:28:33 -05:00
|
|
|
sql-command
|
2008-02-01 18:43:44 -05:00
|
|
|
] with-sqlite
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
{
|
|
|
|
{ "1" "John" "America" }
|
|
|
|
{ "2" "Jane" "New Zealand" }
|
|
|
|
{ "3" "Jimmy" "Canada" }
|
|
|
|
}
|
2008-02-03 00:28:33 -05:00
|
|
|
] [ test.db [ "select rowid, * from person" sql-query ] with-sqlite ] unit-test
|
2008-02-01 18:43:44 -05:00
|
|
|
|
|
|
|
[
|
2008-02-03 16:06:31 -05:00
|
|
|
test.db [
|
2008-02-01 18:43:44 -05:00
|
|
|
[
|
2008-02-03 00:28:33 -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
|
|
|
|
] unit-test-fails
|
|
|
|
|
|
|
|
[ 3 ] [
|
2008-02-03 16:06:31 -05:00
|
|
|
test.db [
|
2008-02-03 00:28:33 -05:00
|
|
|
"select * from person" sql-query length
|
2008-02-01 18:43:44 -05:00
|
|
|
] with-sqlite
|
|
|
|
] unit-test
|
|
|
|
|
|
|
|
[
|
|
|
|
] [
|
2008-02-03 16:06:31 -05:00
|
|
|
test.db [
|
2008-02-01 18:43:44 -05:00
|
|
|
[
|
2008-02-03 00:28:33 -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 ] [
|
2008-02-03 16:06:31 -05:00
|
|
|
test.db [
|
2008-02-03 00:28:33 -05:00
|
|
|
"select * from person" sql-query length
|
2008-02-01 18:43:44 -05:00
|
|
|
] with-sqlite
|
|
|
|
] unit-test
|