| 1 |
;; |
| 2 |
;; Test dbi modules |
| 3 |
;; |
| 4 |
|
| 5 |
(use gauche.test) |
| 6 |
(use gauche.sequence) |
| 7 |
|
| 8 |
(test-start "dbi/dbd") |
| 9 |
(use dbi) |
| 10 |
(test-module 'dbi) |
| 11 |
|
| 12 |
(test-section "testing with dbd-null") |
| 13 |
|
| 14 |
(let ([conn #f] |
| 15 |
[query #f]) |
| 16 |
(test* "dbi-connect" '<null-connection> |
| 17 |
(begin (set! conn (dbi-connect "dbi:null")) |
| 18 |
(and (dbi-open? conn) |
| 19 |
(class-name (class-of conn))))) |
| 20 |
(test* "dbi-close (<dbi-connection>)" #f |
| 21 |
(begin (dbi-close conn) |
| 22 |
(dbi-open? conn))) |
| 23 |
|
| 24 |
(test* "dbi-connect w/options" '("testdata;host=foo.biz;port=8088;noretry" |
| 25 |
(("testdata" . #t) |
| 26 |
("host" . "foo.biz") |
| 27 |
("port" . "8088") |
| 28 |
("noretry" . #t)) |
| 29 |
(:username "anonymous" :password "sesame")) |
| 30 |
(begin |
| 31 |
(set! conn (dbi-connect "dbi:null:testdata;host=foo.biz;port=8088;noretry" |
| 32 |
:username "anonymous" :password "sesame")) |
| 33 |
(list (ref conn 'attr-string) |
| 34 |
(ref conn 'attr-alist) |
| 35 |
(ref conn 'options)))) |
| 36 |
|
| 37 |
(test* "dbi-prepare" '<dbi-query> |
| 38 |
(begin (set! query (dbi-prepare conn "select * from foo where x = ?")) |
| 39 |
(class-name (class-of query)))) |
| 40 |
|
| 41 |
(test* "execute query" '("select * from foo where x = 'z'") |
| 42 |
(coerce-to <list> (dbi-execute query "z"))) |
| 43 |
|
| 44 |
(test* "execute query" '("select * from foo where x = 333") |
| 45 |
(coerce-to <list> (dbi-execute query 333))) |
| 46 |
|
| 47 |
(test* "execute query" '("select * from foo where x = ''''") |
| 48 |
(coerce-to <list> (dbi-execute query "'"))) |
| 49 |
|
| 50 |
(test* "dbi-do" '("insert into foo values(2,3)") |
| 51 |
(coerce-to <list> (dbi-do conn "insert into foo values (2, 3)"))) |
| 52 |
|
| 53 |
(test* "dbi-do" '("insert into foo values('don''t know',NULL)") |
| 54 |
(coerce-to <list> |
| 55 |
(dbi-do conn "insert into foo values (?, ?)" '() |
| 56 |
"don't know" #f))) |
| 57 |
|
| 58 |
(test* "<dbi-parameter-error>" (test-error <dbi-parameter-error>) |
| 59 |
(dbi-execute (dbi-prepare (dbi-connect "dbi:null") |
| 60 |
"select * from foo where x = ?") |
| 61 |
1 2)) |
| 62 |
|
| 63 |
(test* "<dbi-parameter-error>" (test-error <dbi-parameter-error>) |
| 64 |
(dbi-execute (dbi-prepare (dbi-connect "dbi:null") |
| 65 |
"select * from foo where x = ?"))) |
| 66 |
|
| 67 |
(test* "<dbi-parameter-error>" (test-error <dbi-parameter-error>) |
| 68 |
(dbi-execute (dbi-prepare (dbi-connect "dbi:null") |
| 69 |
"select * from foo where x = 3") |
| 70 |
4)) |
| 71 |
) |
| 72 |
|
| 73 |
(test-section "testing conditions") |
| 74 |
|
| 75 |
(test* "<dbi-nonexistent-driver-error>" "nosuchdriver" |
| 76 |
(guard (e [(<dbi-nonexistent-driver-error> e) |
| 77 |
(ref e 'driver-name)]) |
| 78 |
(dbi-connect "dbi:nosuchdriver"))) |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
(test-end) |