r9527: add function declarations for prepared statements
[clsql.git] / db-mysql / mysql-api.lisp
index c14cb7d0f2c5afe321d30370fc723b5de46bdd7c..96d904c70900954e1b04548100b501d5d1159ac5 100644 (file)
@@ -2,13 +2,13 @@
 ;;;; *************************************************************************
 ;;;; FILE IDENTIFICATION
 ;;;;
-;;;; Name:          mysql.cl
+;;;; Name:          mysql-api.lisp
 ;;;; Purpose:       Low-level MySQL interface using UFFI
 ;;;; Programmers:   Kevin M. Rosenberg based on 
 ;;;;                Original code by Pierre R. Mai 
 ;;;; Date Started:  Feb 2002
 ;;;;
-;;;; $Id: mysql-api.lisp,v 1.3 2003/06/08 12:48:55 kevin Exp $
+;;;; $Id$
 ;;;;
 ;;;; This file, part of CLSQL, is Copyright (c) 2002 by Kevin M. Rosenberg
 ;;;; and Copyright (c) 1999-2001 by Pierre R. Mai
@@ -18,9 +18,6 @@
 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
 ;;;; *************************************************************************
 
-(eval-when (:compile-toplevel)
-  (declaim (optimize (debug 3) (speed 3) (safety 1) (compilation-speed 0))))
-
 (in-package #:mysql)
 
 ;;;; Modifications from original code
      (:blob 252)
      (:var-string 253)
      (:string 254)))
-  
-#-(or win32 mswindows)
+
+#+mysql-client-v3
 (uffi:def-struct mysql-field
     (name (* :char))
   (table (* :char))
   (flags :unsigned-int)
   (decimals :unsigned-int))
 
-;; structure changed in mysql 4.0.12, win32
-#+(or win32 mswindows)
+;; structure changed in mysql 4 client
+#+(and mysql-client-v4 (not mysql-client-v4.1))
 (uffi:def-struct mysql-field
     (name (* :char))
   (table (* :char))
   (org_table (* :char))
   (db (* :char))
   (def (* :char))
-  (length :unsigned-int)
-  (max-length :unsigned-int)
+  (length :unsigned-long)
+  (max-length :unsigned-long)
   (flags :unsigned-int)
   (decimals :unsigned-int)
   (type mysql-field-types))
 
+#+mysql-client-v4.1
+(uffi:def-struct mysql-field
+    (name (* :char))
+  (org_table (* :char))
+  (table (* :char))
+  (org_table (* :char))
+  (db (* :char))
+  (catalog_db (* :char))
+  (def (* :char))
+  (length :unsigned-long)
+  (max-length :unsigned-long)
+  (name-length :unsigned-int)
+  (org-name-length :unsigned-int)
+  (table-length :unsigned-int)
+  (org-table-length :unsigned-int)
+  (db-length :unsigned-int)
+  (catalog-length :unsigned-int)
+  (def-length :unsigned-int)
+  (flags :unsigned-int)
+  (decimals :unsigned-int)
+  (charsetnr :unsigned-int)
+  (type mysql-field-types))
+
 ;;; MYSQL-ROWS
 
 (uffi:def-array-pointer mysql-row (* :unsigned-char))
   (handle (:struct-pointer mysql-mysql))
   (eof mysql-bool))
 
+#+mysql-client-v4.1
+(uffi:def-struct mysql-bind
+    (length (* :unsigned-long))
+  (is-null (* :short))
+  (buffer :pointer-void)
+  (buffer-type :int)
+  (buffer-length :unsigned-long)
+  ;; remainder of structure is for internal use
+  )
+
 ;;;; The Foreign C routines
 (declaim (inline mysql-init))
 (uffi:def-function "mysql_init"
   :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)
 
 ;; Need to comment this out for LW 4.2.6
 ;; ? bug in LW version
-;;(declaim (inline mysql-real-connect))
+#-lispworks (declaim (inline mysql-real-connect))
 (uffi:def-function "mysql_real_connect"
     ((mysql (* mysql-mysql))
      (host :cstring)
      (db :cstring)
      (port :unsigned-int)
      (unix-socket :cstring)
-     (clientflag :unsigned-int))
+     (clientflag :unsigned-long))
   :module "mysql"
   :returning (* mysql-mysql))
 
   :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 :cstring)
 
-(declaim (inline mysql-get-client-info))
-(uffi:def-function "mysql_get_client_info"
-    ()
-  :module "mysql"
-  :returning :cstring)
-
 (declaim (inline mysql-get-host-info))
 (uffi:def-function "mysql_get_host_info"
     ((mysql (* mysql-mysql)))
   :module "clsql-mysql"
   :returning :unsigned-int)
 
+#+mysql-client-v4.1
+(uffi:def-foreign-type mysql-stmt-ptr :pointer-void)
+
+#+mysql-client-v4.1
+(uffi:def-function "mysql_stmt_init"
+    ((res (* mysql-mysql-res)))
+  :module "clsql-mysql"
+  :returning mysql-stmt-ptr)
+
+#+mysql-client-v4.1
+(uffi:def-function "mysql_stmt_bind_param"
+    ((stmt mysql-stmt-ptr)
+     (bind (* mysql-bind)))
+  :module "clsql-mysql"
+  :returning :short)
+
+#+mysql-client-v4.1
+(uffi:def-function "mysql_stmt_bind_result"
+    ((stmt mysql-stmt-ptr)
+     (bind (* mysql-bind)))
+  :module "clsql-mysql"
+  :returning :short)
+
+#+mysql-client-v4.1
+(uffi:def-function "mysql_stmt_execute"
+    ((stmt mysql-stmt-ptr))
+  :module "clsql-mysql"
+  :returning :int)
+
+#+mysql-client-v4.1
+(uffi:def-function "mysql_stmt_fetch"
+    ((stmt mysql-stmt-ptr))
+  :module "clsql-mysql"
+  :returning :int)
+
+#+mysql-client-v4.1
+(uffi:def-function "mysql_stmt_free_result"
+    ((stmt mysql-stmt-ptr))
+  :module "clsql-mysql"
+  :returning :short)
 
 ;;;; Equivalents of C Macro definitions for accessing various fields
 ;;;; in the internal MySQL Datastructures
   :module "clsql-mysql"
   :returning :void)
 
-
 (defun mysql-data-seek (res offset)
   (multiple-value-bind (high32 low32) (split-64-bit-integer offset)
     (clsql-mysql-data-seek res high32 low32)))