sqli-oo.scm
(module sqli-oo mzscheme
	(require (planet "roos.scm" ("oesterholt" "roos.plt" 1 0)))
	(require (lib "time.ss" "srfi" "19"))
	(require "sqli.scm")
	(provide sqli-oo
		 (all-from (planet "roos.scm" ("oesterholt" "roos.plt" 1 0))))

(def-class 
  (this (sqli-oo driver))
  (supers)
  (private
   (define handle #f)

   (define (check-handle)
     (if (eq? handle #f)
	 (error "sqli-oo: not a valid sqli handle")))
   )
  (public

   (define (connect) 
     (if (eq? handle #f)
	 (set! handle (sqli-connect driver))
	 (error "sqli-oo: already connected; disconnect first")))

   (define (disconnect)
     (if (eq? handle #f)
	 (error "sqli-oo: not connected; connect first")
	 (begin
	   (sqli-disconnect handle)
	   (set! handle #f))))

   (define (query query . args)
     (check-handle)
     (apply sqli-query (cons handle (cons query args))))

   (define (register name query . conversion-function)
     (check-handle)
     (apply sqli-register (cons handle (cons name (cons query conversion-function)))))

   (define (exec name . args)
     (check-handle)
     (apply sqli-exec (cons handle (cons name args))))

   (define (begin-work)
     (check-handle)
     (sqli-begin handle))

   (define (commit)
     (check-handle)
     (sqli-commit handle))

   (define (rollback)
     (check-handle)
     (sqli-rollback handle))

   (define (fetch rows)
     (check-handle)
     (sqli-fetch handle rows))

   (define (fetchrow)
     (check-handle)
     (sqli-fetchrow handle))

   (define (fetchall)
     (check-handle)
     (sqli-fetchall handle))

   (define (error?)
     (check-handle)
     (sqli-error? handle))

   (define (error-message)
     (check-handle)
     (sqli-error-message handle))

   (define (errmsg)
     (check-handle)
     (sqli-error-message handle))

   (define (driver-name)
     (driver 'name))

   (define (driver-version)
     (driver 'version))

   (define (version)
     (sqli-version))


   (define (->date string-from-db)
     (check-handle)
     (sqli-convert handle string-from-db 'date))

   (define (->bool string-from-db)
     (check-handle)
     (sqli-convert handle string-from-db 'boolean))

   (define (->boolean string-from-db)
     (check-handle)
     (sqli-convert handle string-from-db 'boolean))

   (define (->integer string-from-db)
     (check-handle)
     (sqli-convert handle string-from-db 'integer))

   (define (->number string-from-db)
     (check-handle)
     (sqli-convert handle string-from-db 'number))

   (define (->symbol string-from-db)
     (check-handle)
     (sqli-convert handle string-from-db 'symbol))

   (define (->scheme-data string-from-db)
     (check-handle)
     (sqli-convert handle string-from-db 'scheme-object))
     
   (define (->scheme-object string-from-db)
     (check-handle)
     (sqli-convert handle string-from-db 'scheme-object))

   (define (->string string-from-db)
     (check-handle)
     (sqli-convert handle string-from-db 'string))

   (define (->var string-from-db var)
     (cond 
      ((srfi:date? var)    (->date string-from-db))
      ((boolean? var) (->boolean string-from-db))
      ((number? var)  (if (exact? var)
			  (->integer string-from-db)
			  (->number  string-from-db)))
      ((symbol? var)  (->symbol string-from-db))
      ((string? var)  (->string string-from-db))
      (else           (->scheme-object string-from-db))))
   
   )
  (constructor)
  )
  
)