X-Git-Url: http://git.kpe.io/?p=clsql.git;a=blobdiff_plain;f=db-mysql%2Fmysql-api.lisp;h=39af26f02add0b6c128957947042b2f4d445a86c;hp=96d904c70900954e1b04548100b501d5d1159ac5;hb=ae8a67aac10c0b2ccff4a14a13667d75c074eeed;hpb=fa8bab0b07d9aa9f1c546920971f41252434e285 diff --git a/db-mysql/mysql-api.lisp b/db-mysql/mysql-api.lisp index 96d904c..39af26f 100644 --- a/db-mysql/mysql-api.lisp +++ b/db-mysql/mysql-api.lisp @@ -4,8 +4,8 @@ ;;;; ;;;; Name: mysql-api.lisp ;;;; Purpose: Low-level MySQL interface using UFFI -;;;; Programmers: Kevin M. Rosenberg based on -;;;; Original code by Pierre R. Mai +;;;; Programmers: Kevin M. Rosenberg based on +;;;; Original code by Pierre R. Mai ;;;; Date Started: Feb 2002 ;;;; ;;;; $Id$ @@ -27,13 +27,13 @@ ;;;; that are used in a few routines. ;;;; - Removed all references to interiors of C-structions, this will ;;;; increase robustness when MySQL's internal structures change. - + ;;;; Type definitions ;;; Basic Types (uffi:def-foreign-type mysql-socket :int) -(uffi:def-foreign-type mysql-bool :char) +(uffi:def-foreign-type mysql-bool :byte) (uffi:def-foreign-type mysql-byte :unsigned-char) (uffi:def-enum mysql-net-type @@ -104,7 +104,8 @@ (:long-blob 251) (:blob 252) (:var-string 253) - (:string 254))) + (:string 254) + (:geometry 255))) #+mysql-client-v3 (uffi:def-struct mysql-field @@ -131,10 +132,10 @@ (decimals :unsigned-int) (type mysql-field-types)) -#+mysql-client-v4.1 +#+(or mysql-client-v4.1 mysql-client-v5) (uffi:def-struct mysql-field (name (* :char)) - (org_table (* :char)) + (org_name (* :char)) (table (* :char)) (org_table (* :char)) (db (* :char)) @@ -154,6 +155,18 @@ (charsetnr :unsigned-int) (type mysql-field-types)) + +(uffi:def-struct mysql-time + (year :unsigned-int) + (month :unsigned-int) + (day :unsigned-int) + (hour :unsigned-int) + (minute :unsigned-int) + (second :unsigned-int) + (second-part :unsigned-long) + (neg mysql-bool) + (time-type :int)) + ;;; MYSQL-ROWS (uffi:def-array-pointer mysql-row (* :unsigned-char)) @@ -207,7 +220,7 @@ :read-default-group)) (uffi:def-enum mysql-status - (:ready + (:ready :get-result :use-result)) @@ -263,31 +276,36 @@ (handle (:struct-pointer mysql-mysql)) (eof mysql-bool)) -#+mysql-client-v4.1 +#+(or mysql-client-v4.1 mysql-client-v5) +(uffi:def-enum mysql-field-types + (:ready + :get-result + :use-result)) + +#+(or mysql-client-v4.1 mysql-client-v5) (uffi:def-struct mysql-bind (length (* :unsigned-long)) - (is-null (* :short)) + (is-null (* mysql-bool)) (buffer :pointer-void) (buffer-type :int) (buffer-length :unsigned-long) - ;; remainder of structure is for internal use - ) + ;; internal use + (inter_buffer (* :unsigned-char)) + (offset :unsigned-long) + (internal-length :unsigned-long) + (param-number :unsigned-int) + (pack-length :unsigned-int) + (is-signed mysql-bool) + (long-data-used mysql-bool) + (internal-is-null mysql-bool) + (store-param-func :pointer-void) + (fetch-result :pointer-void) + (skip-result :pointer-void)) ;;;; The Foreign C routines (declaim (inline mysql-init)) (uffi:def-function "mysql_init" ((mysql (* mysql-mysql))) - :module "mysql" - :returning (* mysql-mysql)) - -#-mysql-client-v4 -(declaim (inline mysql-connect)) -#-mysql-client-v4 -(uffi:def-function "mysql_connect" - ((mysql (* mysql-mysql)) - (host :cstring) - (user :cstring) - (passwd :cstring)) :module "mysql" :returning (* mysql-mysql)) @@ -337,24 +355,6 @@ :module "mysql" :returning :int) -#-mysql-client-v4 -(declaim (inline mysql-create-db)) -#-mysql-client-v4 -(uffi:def-function "mysql_create_db" - ((mysql (* mysql-mysql)) - (db :cstring)) - :module "mysql" - :returning :int) - -#-mysql-client-v4 -(declaim (inline mysql-drop-db)) -#-mysql-client-v4 -(uffi:def-function "mysql_drop_db" - ((mysql (* mysql-mysql)) - (db :cstring)) - :module "mysql" - :returning :int) - (declaim (inline mysql-shutdown)) (uffi:def-function "mysql_shutdown" ((mysql (* mysql-mysql))) @@ -512,8 +512,8 @@ (declaim (inline mysql-escape-string)) (uffi:def-function "mysql_escape_string" - ((to :cstring) - (from :cstring) + ((to (* :unsigned-char)) + (from (* :unsigned-char)) (length :unsigned-int)) :module "mysql" :returning :unsigned-int) @@ -531,47 +531,93 @@ :module "clsql-mysql" :returning :unsigned-int) -#+mysql-client-v4.1 +#+(or mysql-client-v4.1 mysql-client-v5) (uffi:def-foreign-type mysql-stmt-ptr :pointer-void) -#+mysql-client-v4.1 +#+(or mysql-client-v4.1 mysql-client-v5) (uffi:def-function "mysql_stmt_init" ((res (* mysql-mysql-res))) :module "clsql-mysql" :returning mysql-stmt-ptr) -#+mysql-client-v4.1 +#+(or mysql-client-v4.1 mysql-client-v5) +(uffi:def-function "mysql_stmt_prepare" + ((stmt mysql-stmt-ptr) + (query :cstring) + (length :unsigned-long)) + :module "clsql-mysql" + :returning :int) + +#+(or mysql-client-v4.1 mysql-client-v5) +(uffi:def-function "mysql_stmt_param_count" + ((stmt mysql-stmt-ptr)) + :module "clsql-mysql" + :returning :unsigned-int) + +#+(or mysql-client-v4.1 mysql-client-v5) (uffi:def-function "mysql_stmt_bind_param" ((stmt mysql-stmt-ptr) (bind (* mysql-bind))) :module "clsql-mysql" :returning :short) -#+mysql-client-v4.1 +#+(or mysql-client-v4.1 mysql-client-v5) (uffi:def-function "mysql_stmt_bind_result" ((stmt mysql-stmt-ptr) (bind (* mysql-bind))) :module "clsql-mysql" :returning :short) -#+mysql-client-v4.1 +#+(or mysql-client-v4.1 mysql-client-v5) +(uffi:def-function "mysql_stmt_result_metadata" + ((stmt mysql-stmt-ptr)) + :module "clsql-mysql" + :returning (* mysql-mysql-res)) + + +#+(or mysql-client-v4.1 mysql-client-v5) (uffi:def-function "mysql_stmt_execute" ((stmt mysql-stmt-ptr)) :module "clsql-mysql" :returning :int) -#+mysql-client-v4.1 +#+(or mysql-client-v4.1 mysql-client-v5) +(uffi:def-function "mysql_stmt_store_result" + ((stmt mysql-stmt-ptr)) + :module "clsql-mysql" + :returning :int) + +#+(or mysql-client-v4.1 mysql-client-v5) (uffi:def-function "mysql_stmt_fetch" ((stmt mysql-stmt-ptr)) :module "clsql-mysql" :returning :int) -#+mysql-client-v4.1 +#+(or mysql-client-v4.1 mysql-client-v5) (uffi:def-function "mysql_stmt_free_result" ((stmt mysql-stmt-ptr)) :module "clsql-mysql" :returning :short) +#+(or mysql-client-v4.1 mysql-client-v5) +(uffi:def-function "mysql_stmt_close" + ((stmt mysql-stmt-ptr)) + :module "clsql-mysql" + :returning :short) + +#+(or mysql-client-v4.1 mysql-client-v5) +(uffi:def-function "mysql_stmt_errno" + ((stmt mysql-stmt-ptr)) + :module "clsql-mysql" + :returning :unsigned-int) + +#+(or mysql-client-v4.1 mysql-client-v5) +(uffi:def-function "mysql_stmt_error" + ((stmt mysql-stmt-ptr)) + :module "clsql-mysql" + :returning :cstring) + + ;;;; Equivalents of C Macro definitions for accessing various fields ;;;; in the internal MySQL Datastructures @@ -615,11 +661,11 @@ (declaim (inline mysql-num-fields)) -(uffi:def-function "mysql_num_fields" +(uffi:def-function "mysql_num_fields" ((res (* mysql-mysql-res))) :returning :unsigned-int :module "mysql") - + (declaim (inline clsql-mysql-eof)) (uffi:def-function ("mysql_eof" clsql-mysql-eof) ((res (* mysql-mysql-res)))