; chicken-scheme MySQL query procedure ; ; To build as a standalone shared library: ; CSC_OPTIONS=`mysql_config --include --libs` chicken-install -n ; ; To use: ; (require-library mysql-client) ; (define mysql (make-mysql-connection "host" "user" "pass" "schema")) ; (define fetch (mysql "select * from messages")) ; (fetch) ; ; Provide password as #f to use the password from the .my.cnf ; options file (/home/user/.my.cnf). ; ; Example .my.cnf: ; ; [client] ; user=root ; password=secret ; ; Note how MySQL (NULL) values are represented when ; returned in an array of string pointers: ; A (NULL) value is represented by a string containing ; a 0x04 0x00 char sequence. (define (make-mysql-connection host user pass database) (define mysql-c (make-mysql-c-connection host user pass database)) (set-finalizer! mysql-c (lambda(x) (close-mysql-c-connection mysql-c-conn))) (define (mysql-query sql) (define result-c (mysql-c-query mysql-c sql)) (define (fetch-c)(let ((row (mysql-c-fetch-row result-c))) (if (> (length row) 0) row #f))) (set-finalizer! result-c (lambda(x) (mysql-c-free-result result-c))) fetch-c) mysql-query) (foreign-declare "#include \"mysql.h\"") (define mysql-c-fetch-row (foreign-lambda* c-string-list* ((c-pointer result)) #<