1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
6 ;;;; Purpose: Package definition for CLSQL Db2 interface
10 ;;;; This file is part of CLSQL.
12 ;;;; CLSQL users are granted the rights to distribute and use this software
13 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
14 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
15 ;;;; *************************************************************************
17 (in-package #:clsql-db2)
21 ;; Opaque pointer types
24 (uffi:def-foreign-type cli-handle :pointer-void)
25 (uffi:def-foreign-type cli-pointer :pointer-void)
26 (uffi:def-foreign-type cli-char :byte)
27 (uffi:def-foreign-type cli-ulen :unsigned-int)
28 (uffi:def-foreign-type cli-len :int)
29 (uffi:def-foreign-type cli-smallint :short)
30 (uffi:def-foreign-type cli-usmallint :unsigned-short)
33 (defvar +null-void-pointer+ (uffi:make-null-pointer :void))
34 (defvar +null-void-pointer-pointer+ (uffi:make-null-pointer :pointer-void))
36 ;;; Check an CLI return code for erroricity and signal a reasonably
37 ;;; informative condition if so.
39 ;;; ERRHP provides an error handle which can be used to find
40 ;;; subconditions; if it's not provided, subcodes won't be checked.
42 ;;; NULLS-OK says that a NULL-VALUE-RETURNED subcondition condition is
43 ;;; normal and needn't cause any signal. An error handle is required
44 ;;; to detect this subcondition, so it doesn't make sense to set ERRHP
45 ;;; unless NULLS-OK is set.
47 (defmacro def-cli-routine ((c-cli-symbol lisp-cli-fn) c-return &rest c-parms)
48 (let ((ll (mapcar (lambda (x) (declare (ignore x)) (gensym)) c-parms)))
49 `(let ((%lisp-cli-fn (uffi:def-function
50 (,c-cli-symbol ,(intern (concatenate 'string "%" (symbol-name lisp-cli-fn))))
52 :returning ,c-return)))
53 (defun ,lisp-cli-fn (,@ll &key database nulls-ok)
54 (let ((result (funcall %lisp-cli-fn ,@ll)))
60 (handle-oci-error :database database :nulls-ok nulls-ok))
62 (error 'sql-database-error :message "OCI No Data Found"))
63 (#.+oci-success-with-info+
64 (error 'sql-database-error :message "internal error: unexpected +oci-success-with-info"))
66 (error 'sql-database-error :message "OCI No Data"))
67 (#.+oci-invalid-handle+
68 (error 'sql-database-error :message "OCI Invalid Handle"))
70 (error 'sql-database-error :message "OCI Need Data"))
71 (#.+oci-still-executing+
72 (error 'sql-temporary-error :message "OCI Still Executing"))
74 (error 'sql-database-error :message "OCI Continue"))
76 (error 'sql-database-error :message "Check CLI_HOME and NLS settings."))
78 (error 'sql-database-error
80 (format nil "OCI unknown error, code=~A" result)))))))))
83 (defmacro def-raw-cli-routine
84 ((c-cli-symbol lisp-cli-fn) c-return &rest c-parms)
85 (let ((ll (mapcar (lambda (x) (declare (ignore x)) (gensym)) c-parms)))
86 `(let ((%lisp-cli-fn (uffi:def-function (,c-cli-symbol ,(intern (concatenate 'string "%" (symbol-name lisp-cli-fn))))
88 :returning ,c-return)))
89 (defun ,lisp-cli-fn (,@ll &key database nulls-ok)
90 (funcall %lisp-cli-fn ,@ll)))))
93 (def-cli-routine ("SQLAllocHandle" sql-allocate-handle)
95 (fHandleType cli-smallint)
97 (phOuput (* cli-handle)))
100 ;;; CLI Functions needed
113 ;;; SQLSetConnectAttr