(module oracle-test mzscheme
(require (lib "time.ss" "srfi" "19"))
(require (planet "sqli.scm" ("oesterholt" "sqlid.plt" 1 2)))
(require (planet "sqld-oracle.scm" ("oesterholt" "sqlid.plt" 1 2)))
(define (displayp . args)
(define (p args)
(if (null? args)
(newline)
(begin
(display (car args))
(p (cdr args)))))
(p args))
(define (main . argv)
(let* (
(connect_string (if (null? argv) "scott/tiger" (car argv)))
(sqld (sqld-oracle-new connect_string))
(sqli (sqli-connect sqld))
(results (sqli-query sqli "CREATE TABLE test (name varchar(2000),age numeric(4),nice numeric(1),dt timestamp)"))
(i 0))
(displayp results)
(displayp (sqli-error? sqli) " - " (sqli-error-message sqli))
(displayp (sqli-version) " - " (sqli-driver-name sqld) " - " (sqli-driver-version sqld))
(do
((a (sqli-fetchrow sqli) (sqli-fetchrow sqli)))
((eq? a #f) #t)
(display a))
(displayp)
(sqli-begin sqli)
(do
((i 1 (+ i 1)))
((> i 10) #t)
(sqli-query sqli "INSERT INTO test VALUES ($1, $2, $3, $4)" (string-append "row'" (number->string i)) i #t (current-date)))
(sqli-commit sqli)
(set! results (sqli-query sqli "SELECT * FROM test"))
(displayp (sqli-error? sqli) " - " (sqli-error-message sqli))
(displayp (sqli-fetchall sqli))
(displayp)
(sqli-begin sqli)
(sqli-query sqli "INSERT INTO test VALUES ('joost',42,$1,$2);SELEKT * FROM test" 1 (current-date))
(displayp (sqli-error? sqli) " - " (sqli-error-message sqli))
(if (sqli-error? sqli)
(sqli-rollback sqli)
(sqli-commit sqli))
(sqli-register sqli 'select
"SELECT $1 FROM test WHERE age $2 $3"
(let ((c 0))
(lambda (a)
(begin
(set! c (+ c 1))
(list c (car a))))))
(displayp sqli)
(displayp (sqli-exec sqli 'select 'name '> 2))
(displayp (sqli-fetch sqli 10))
(sqli-register sqli 'select-convert
"SELECT * FROM test WHERE age=10"
'string 'integer 'boolean 'date)
(displayp sqli)
(displayp (sqli-exec sqli 'select-convert))
(displayp (sqli-fetchall sqli))
(let ((clos (sqli-closure sqli)))
(displayp (clos 'exec 'select 'age '<= 2))
(displayp (clos 'fetchall))
(clos 'register 'count "SELECT COUNT(name) FROM test"
(lambda (row) (car row)))
(clos 'exec 'count) (displayp (clos 'fetchrow))
(clos 'register 'and "SELECT nice FROM test"
(lambda (row)
(let ((b (clos 'convert (car row) 'boolean)))
(list b))))
(displayp (clos 'exec 'and))
(displayp (clos 'fetchall))
(clos 'query "INSERT INTO test VALUES ('false',0,$1)" #f)
(displayp (clos 'exec 'and))
(displayp (clos 'fetchall))
(clos 'hithere "errors"))
(displayp sqli)
(displayp (sqli-exec sqli 'and))
(displayp (sqli-fetchall sqli))
(sqli-disconnect sqli)
0))
(provide main))