Skip to content

ChaosEternal/chez-odbc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

Chez-odbc

this is library for chez-scheme connecting to ODBC datasources.

License

LGPLv3+

Usage

Procedures

Procedure: connect

  • 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")))

Procedure: cursor

  • Usage:
    • (cursor connect)

Alloc a cursor object, all queries go through cursor.

Example:

(define cs (dbi:cursor c))

Procedure: query

  • Usage:
    • (query cursor sql)

Execute query.

Example:

(dbi:query cc "select now()")

Procedure: commit, rollback

  • Usage:
    • (commit connect)
    • (rollback connect)

Commit/Rollback transactions on connection: connect

Procedure: row-count, number-of-columns, col-defs

  • Usage:
    • (row-count cursor)
    • (number-of-columns cursor)
    • (col-defs cursor)

col-defs returns: vector of (column-name column-type column-size)

Procedure: fetch-one

  • 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))
	   )))

Procedure: cursor-type-map-proc-set!

  • 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)
        

Copyright

Chaos Eternal (c) 2016

About

Odbc library for Chez-Scheme

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages