forked from shirok/Gauche
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbidbd.scm
83 lines (63 loc) · 2.85 KB
/
dbidbd.scm
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
;;
;; Test dbi modules
;;
(use gauche.test)
(use gauche.sequence)
(test-start "dbi/dbd")
(use dbi)
(test-module 'dbi)
(test-section "testing with dbd-null")
(let ([conn #f]
[query #f])
(test* "dbi-connect" '<null-connection>
(begin (set! conn (dbi-connect "dbi:null"))
(and (dbi-open? conn)
(class-name (class-of conn)))))
(test* "dbi-close (<dbi-connection>)" #f
(begin (dbi-close conn)
(dbi-open? conn)))
(test* "dbi-connect w/options" '("testdata;host=foo.biz;port=8088;noretry"
(("testdata" . #t)
("host" . "foo.biz")
("port" . "8088")
("noretry" . #t))
(:username "anonymous" :password "sesame"))
(begin
(set! conn (dbi-connect "dbi:null:testdata;host=foo.biz;port=8088;noretry"
:username "anonymous" :password "sesame"))
(list (ref conn 'attr-string)
(ref conn 'attr-alist)
(ref conn 'options))))
(test* "dbi-prepare" '<dbi-query>
(begin (set! query (dbi-prepare conn "select * from foo where x = ?"))
(class-name (class-of query))))
(test* "execute query" '("select * from foo where x = 'z'")
(coerce-to <list> (dbi-execute query "z")))
(test* "execute query" '("select * from foo where x = 333")
(coerce-to <list> (dbi-execute query 333)))
(test* "execute query" '("select * from foo where x = ''''")
(coerce-to <list> (dbi-execute query "'")))
(test* "dbi-do" '("insert into foo values(2,3)")
(coerce-to <list> (dbi-do conn "insert into foo values (2, 3)")))
(test* "dbi-do" '("insert into foo values('don''t know',NULL)")
(coerce-to <list>
(dbi-do conn "insert into foo values (?, ?)" '()
"don't know" #f)))
(test* "<dbi-parameter-error>" (test-error <dbi-parameter-error>)
(dbi-execute (dbi-prepare (dbi-connect "dbi:null")
"select * from foo where x = ?")
1 2))
(test* "<dbi-parameter-error>" (test-error <dbi-parameter-error>)
(dbi-execute (dbi-prepare (dbi-connect "dbi:null")
"select * from foo where x = ?")))
(test* "<dbi-parameter-error>" (test-error <dbi-parameter-error>)
(dbi-execute (dbi-prepare (dbi-connect "dbi:null")
"select * from foo where x = 3")
4))
)
(test-section "testing conditions")
(test* "<dbi-nonexistent-driver-error>" "nosuchdriver"
(guard (e [(<dbi-nonexistent-driver-error> e)
(ref e 'driver-name)])
(dbi-connect "dbi:nosuchdriver")))
(test-end)