1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: Package definition for CLSQL Db2 interface
8 ;;;; This file is part of CLSQL.
10 ;;;; CLSQL users are granted the rights to distribute and use this software
11 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
12 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
13 ;;;; *************************************************************************
15 (in-package #:clsql-db2)
19 ;; Opaque pointer types
22 (uffi:def-foreign-type cli-handle :pointer-void)
23 (uffi:def-foreign-type cli-pointer :pointer-void)
24 (uffi:def-foreign-type cli-char :byte)
25 (uffi:def-foreign-type cli-ulen :unsigned-int)
26 (uffi:def-foreign-type cli-len :int)
27 (uffi:def-foreign-type cli-smallint :short)
28 (uffi:def-foreign-type cli-usmallint :unsigned-short)
31 (defvar +null-void-pointer+ (uffi:make-null-pointer :void))
32 (defvar +null-void-pointer-pointer+ (uffi:make-null-pointer :pointer-void))
34 ;;; Check an CLI return code for erroricity and signal a reasonably
35 ;;; informative condition if so.
37 ;;; ERRHP provides an error handle which can be used to find
38 ;;; subconditions; if it's not provided, subcodes won't be checked.
40 ;;; NULLS-OK says that a NULL-VALUE-RETURNED subcondition condition is
41 ;;; normal and needn't cause any signal. An error handle is required
42 ;;; to detect this subcondition, so it doesn't make sense to set ERRHP
43 ;;; unless NULLS-OK is set.
45 (defmacro def-cli-routine ((c-cli-symbol lisp-cli-fn) c-return &rest c-parms)
46 (let ((ll (mapcar (lambda (x) (declare (ignore x)) (gensym)) c-parms)))
47 `(let ((%lisp-cli-fn (uffi:def-function
48 (,c-cli-symbol ,(intern (concatenate 'string "%" (symbol-name lisp-cli-fn))))
50 :returning ,c-return)))
51 (defun ,lisp-cli-fn (,@ll &key database nulls-ok)
52 (let ((result (funcall %lisp-cli-fn ,@ll)))
56 (#.SQL_SUCCESS_WITH_INFO
57 (format *standard-output* "sucess with info")
60 (error 'sql-database-error
63 (format nil "DB2 error" result)))
65 (error 'sql-database-error
67 (format nil "DB2 unknown error, code=~A" result)))))))))
70 (defmacro def-raw-cli-routine
71 ((c-cli-symbol lisp-cli-fn) c-return &rest c-parms)
72 (let ((ll (mapcar (lambda (x) (declare (ignore x)) (gensym)) c-parms)))
73 `(let ((%lisp-cli-fn (uffi:def-function (,c-cli-symbol ,(intern (concatenate 'string "%" (symbol-name lisp-cli-fn))))
75 :returning ,c-return)))
76 (defun ,lisp-cli-fn (,@ll &key database nulls-ok)
77 (funcall %lisp-cli-fn ,@ll)))))
80 (def-cli-routine ("SQLAllocHandle" sql-alloc-handle)
82 (fHandleType cli-smallint)
84 (phOuput (* cli-handle)))
86 (def-cli-routine ("SQLConnect" sql-connect)
90 (server-len cli-smallint)
92 (user-len cli-smallint)
94 (passwd-len cli-smallint))
97 ;;; CLI Functions needed
110 ;;; SQLSetConnectAttr