(linenum→info "unix/slp.c:2238")

gauche/0.8.12/test/dbidbd.scm

    1: ;;
    2: ;; Test dbi modules
    3: ;;  $Id: dbidbd.scm,v 1.4 2005/09/13 02:45:50 shirok Exp $
    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:       )
   17:   (test* "dbi-connect" '<null-connection>
   18:          (begin (set! conn (dbi-connect "dbi:null"))
   19:                 (and (dbi-open? conn)
   20:                      (class-name (class-of conn)))))
   21:   (test* "dbi-close (<dbi-connection>)" #f
   22:          (begin (dbi-close conn)
   23:                 (dbi-open? conn)))
   24: 
   25:   (test* "dbi-connect w/options" '("testdata;host=foo.biz;port=8088;noretry"
   26:                                    (("testdata" . #t)
   27:                                     ("host" . "foo.biz")
   28:                                     ("port" . "8088")
   29:                                     ("noretry" . #t))
   30:                                    (:username "anonymous" :password "sesame"))
   31:          (begin
   32:            (set! conn (dbi-connect "dbi:null:testdata;host=foo.biz;port=8088;noretry"
   33:                                    :username "anonymous" :password "sesame"))
   34:            (list (ref conn 'attr-string)
   35:                  (ref conn 'attr-alist)
   36:                  (ref conn 'options))))
   37: 
   38:   (test* "dbi-prepare" '<dbi-query>
   39:          (begin (set! query (dbi-prepare conn "select * from foo where x = ?"))
   40:                 (class-name (class-of query))))
   41: 
   42:   (test* "execute query" '("select * from foo where x = 'z'")
   43:          (coerce-to <list> (dbi-execute query "z")))
   44: 
   45:   (test* "execute query" '("select * from foo where x = 333")
   46:          (coerce-to <list> (dbi-execute query 333)))
   47: 
   48:   (test* "execute query" '("select * from foo where x = ''''")
   49:          (coerce-to <list> (dbi-execute query "'")))
   50: 
   51:   (test* "dbi-do" '("insert into foo values(2,3)")
   52:          (coerce-to <list> (dbi-do conn "insert into foo values (2, 3)")))
   53: 
   54:   (test* "dbi-do" '("insert into foo values('don''t know',NULL)")
   55:          (coerce-to <list>
   56:                     (dbi-do conn "insert into foo values (?, ?)" '()
   57:                             "don't know" #f)))
   58: 
   59:   (test* "<dbi-parameter-error>" '<dbi-parameter-error>
   60:          (guard (e (else (class-name (class-of e))))
   61:            (dbi-execute (dbi-prepare (dbi-connect "dbi:null")
   62:                                      "select * from foo where x = ?")
   63:                         1 2)))
   64: 
   65:   (test* "<dbi-parameter-error>" '<dbi-parameter-error>
   66:          (guard (e (else (class-name (class-of e))))
   67:            (dbi-execute (dbi-prepare (dbi-connect "dbi:null")
   68:                                      "select * from foo where x = ?"))))
   69: 
   70:   (test* "<dbi-parameter-error>" '<dbi-parameter-error>
   71:          (guard (e (else (class-name (class-of e))))
   72:            (dbi-execute (dbi-prepare (dbi-connect "dbi:null")
   73:                                      "select * from foo where x = 3")
   74:                         4)))
   75:   )
   76: 
   77: (test-section "testing conditions")
   78: 
   79: (test* "<dbi-nonexistent-driver-error>" "nosuchdriver"
   80:        (guard (e ((<dbi-nonexistent-driver-error> e)
   81:                   (ref e 'driver-name)))
   82:          (dbi-connect "dbi:nosuchdriver")))
   83: 
   84: 
   85: 
   86: 
   87: (test-end)
   88: 
   89: 
Syntax (Markdown)