this is library for chez-scheme connecting to ODBC datasources.
LGPLv3+
- Usage:
- (connect Datasource UID [PWD])
- (connect DSN)
Create an odbc connect to datasource.
Example:
(import (prefix (odbc dbi) dbi:))
;;Procedure connect
(define c (dbi:connect (getenv "DSN")))
- Usage:
- (cursor connect)
Alloc a cursor object, all queries go through cursor.
Example:
(define cs (dbi:cursor c))
- Usage:
- (query cursor sql)
Execute query.
Example:
(dbi:query cc "select now()")
- Usage:
- (commit connect)
- (rollback connect)
Commit/Rollback transactions on connection: connect
- Usage:
- (row-count cursor)
- (number-of-columns cursor)
- (col-defs cursor)
col-defs returns: vector of (column-name column-type column-size)
- Usage:
- (fetch-one cursor)
Fetches one row from result. Returns a vector of values. Example:
(let lp ((d (dbi:fetch-one cc)))
(if d
(begin
(format (current-output-port)
"~a\n" ;;(pretty-print)
d)
(lp (dbi:fetch-one cc))
)))
- Usage:
- (cursor-type-map-proc-set! cursor type-map-proc)
- type-map-proc is a proc takes an integer(sql-type) and returns a list:
(convert-code length convert-proc)
convert-code sql-type code is defined in (odbc types) as in sqlext.h and sql.h
length could be #f which means use column-definition’s length
convert-proc takes a bytevector and a length and returns data in desired type
Example:
(import (prefix (odbc dbi) dbi:) (odbc types)) (define DSN (getenv "DSN")) (define c (dbi:connect DSN)) (define cc (dbi:cursor c)) (define (timemap x) (if (pair? (memq x (list SQL_TYPE_TIME SQL_TYPE_DATE SQL_DATE SQL_TIME SQL_TIMESTAMP))) (list SQL_C_TIMESTAMP 200 bytevector-truncate!) (dbi:default-map-sql-type x))) (dbi:cursor-type-map-proc-set! cc timemap)
Chaos Eternal (c) 2016