r9001: Initial port to UFFI of SQL-ODBC
[clsql.git] / db-odbc / odbc-ff-interface.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Package: odbc -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:     odbc-ff-interface.lisp
6 ;;;; Purpose:  Function definitions for UFFI interface to ODBC
7 ;;;; Author:   Kevin M. Rosenberg
8 ;;;;
9 ;;;; $Id: odbc-package.lisp 7061 2003-09-07 06:34:45Z kevin $
10 ;;;;
11 ;;;; This file, part of CLSQL, is Copyright (c) 2004 by Kevin M. Rosenberg
12 ;;;; and Copyright (C) Paul Meurer 1999 - 2001. All rights reserved.
13 ;;;;
14 ;;;; CLSQL users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (in-package #:odbc)
20
21 (def-foreign-type sql-handle (* :void))
22 (def-foreign-type sql-handle-ptr (* sql-handle))
23 (def-foreign-type string-ptr (* :void))
24
25 (def-type long-ptr-type '(* :long))
26
27
28 (def-function "SQLAllocEnv"
29     ((*phenv sql-handle-ptr)    ; HENV   FAR *phenv
30      )
31   :module :odbc
32   :returning :short)              ; RETCODE_SQL_API
33
34 (def-function "SQLAllocConnect"
35     ((henv sql-handle)          ; HENV        henv
36      (*phdbc sql-handle-ptr)    ; HDBC   FAR *phdbc
37      )
38   :module :odbc
39   :returning :short)              ; RETCODE_SQL_API
40
41 (def-function "SQLConnect"
42     ((hdbc sql-handle)          ; HDBC        hdbc
43      (*szDSN string-ptr)        ; UCHAR  FAR *szDSN
44      (cbDSN :short)             ; SWORD       cbDSN
45      (*szUID string-ptr)        ; UCHAR  FAR *szUID 
46      (cbUID :short)             ; SWORD       cbUID
47      (*szAuthStr string-ptr)    ; UCHAR  FAR *szAuthStr
48      (cbAuthStr :short)         ; SWORD       cbAuthStr
49      )
50   :module :odbc
51   :returning :short)              ; RETCODE_SQL_API
52
53 (def-function "SQLDriverConnect"
54     ((hdbc sql-handle)          ; HDBC        hdbc
55      (hwnd sql-handle)          ; SQLHWND     hwnd
56      (*szConnStrIn string-ptr)  ; UCHAR  FAR *szConnStrIn
57      (cbConnStrIn :short)       ; SWORD       cbConnStrIn
58      (*szConnStrOut string-ptr) ; UCHAR  FAR *szConnStrOut
59      (cbConnStrOutMax :short)   ; SWORD       cbConnStrOutMax
60      (*pcbConnStrOut :pointer-void)      ; SWORD  FAR *pcbConnStrOut
61      (fDriverCompletion :short) ; UWORD       fDriverCompletion
62      )
63   :module :odbc
64   :returning :short)              ; RETCODE_SQL_API
65
66 (def-function "SQLDisconnect"
67     ((hdbc sql-handle))         ; HDBC        hdbc
68   :module :odbc
69   :returning :short)              ; RETCODE_SQL_API
70   
71 (def-function "SQLAllocStmt"
72     ((hdbc sql-handle)          ; HDBC        hdbc
73      (*phstmt sql-handle-ptr)   ; HSTMT  FAR *phstmt
74      )
75   :module :odbc
76   :returning :short)              ; RETCODE_SQL_API
77
78 (def-function "SQLGetInfo"
79     ((hdbc sql-handle)          ; HDBC        hdbc
80      (fInfoType :short)         ; UWORD       fInfoType
81      (rgbInfoValue :pointer-void)        ; PTR         rgbInfoValue
82      (cbInfoValueMax :short)    ; SWORD       cbInfoValueMax
83      (*pcbInfoValue :pointer-void)       ; SWORD  FAR *pcbInfoValue
84      )
85   :module :odbc
86   :returning :short)              ; RETCODE_SQL_API
87
88 (def-function "SQLPrepare"
89     ((hstmt sql-handle)         ; HSTMT       hstmt
90      (*szSqlStr string-ptr)     ; UCHAR  FAR *szSqlStr
91      (cbSqlStr :long)           ; SDWORD      cbSqlStr
92      )
93   :module :odbc
94   :returning :short)              ; RETCODE_SQL_API
95
96 (def-function "SQLExecute"
97     ((hstmt sql-handle)         ; HSTMT       hstmt
98      )
99   :module :odbc
100   :returning :short)              ; RETCODE_SQL_API
101
102 (def-function "SQLExecDirect"
103     ((hstmt sql-handle)         ; HSTMT       hstmt
104      (*szSqlStr string-ptr)     ; UCHAR  FAR *szSqlStr
105      (cbSqlStr :long)           ; SDWORD      cbSqlStr
106      )
107   :module :odbc
108   :returning :short)              ; RETCODE_SQL_API
109
110 (def-function "SQLFreeStmt"
111     ((hstmt sql-handle)         ; HSTMT       hstmt
112      (fOption :short))          ; UWORD       fOption
113   :module :odbc
114   :returning :short)              ; RETCODE_SQL_API
115
116   (def-function "SQLCancel"
117       ((hstmt sql-handle)         ; HSTMT       hstmt
118        )
119     :module :odbc
120   :returning :short)              ; RETCODE_SQL_API
121
122 (def-function "SQLError"
123     ((henv sql-handle)          ; HENV        henv
124      (hdbc sql-handle)          ; HDBC        hdbc
125      (hstmt sql-handle)         ; HSTMT       hstmt
126      (*szSqlState string-ptr)   ; UCHAR  FAR *szSqlState
127      (*pfNativeError :pointer-void)      ; SDWORD FAR *pfNativeError
128      (*szErrorMsg string-ptr)   ; UCHAR  FAR *szErrorMsg
129      (cbErrorMsgMax :short)     ; SWORD       cbErrorMsgMax
130      (*pcbErrorMsg :pointer-void)        ; SWORD  FAR *pcbErrorMsg
131      )
132   :module :odbc
133   :returning :short)              ; RETCODE_SQL_API
134
135 (def-function "SQLNumResultCols"
136     ((hstmt sql-handle)         ; HSTMT       hstmt
137      (*pccol :pointer-void)              ; SWORD  FAR *pccol
138      )
139   :module :odbc
140   :returning :short)              ; RETCODE_SQL_API
141
142 (def-function "SQLRowCount"
143     ((hstmt sql-handle)         ; HSTMT       hstmt
144      (*pcrow :pointer-void)              ; SDWORD FAR *pcrow
145      )
146   :module :odbc
147   :returning :short)              ; RETCODE_SQL_API
148
149 (def-function "SQLDescribeCol"
150     ((hstmt sql-handle)         ; HSTMT       hstmt
151      (icol :short)              ; UWORD       icol
152      (*szColName string-ptr)    ; UCHAR  FAR *szColName
153      (cbColNameMax :short)      ; SWORD       cbColNameMax
154      (*pcbColName :pointer-void)         ; SWORD  FAR *pcbColName
155      (*pfSqlType :pointer-void)          ; SWORD  FAR *pfSqlType
156      (*pcbColDef :pointer-void)          ; UDWORD FAR *pcbColDef
157      (*pibScale :pointer-void)           ; SWORD  FAR *pibScale
158      (*pfNullable :pointer-void)         ; SWORD  FAR *pfNullable
159      )
160   :module :odbc
161   :returning :short)              ; RETCODE_SQL_API
162
163 (def-function "SQLColAttributes"
164     ((hstmt sql-handle)         ; HSTMT       hstmt
165      (icol :short)              ; UWORD       icol
166      (fDescType :short)         ; UWORD       fDescType
167      (rgbDesc :pointer-void)             ; PTR         rgbDesc
168      (cbDescMax :short)         ; SWORD       cbDescMax
169      (*pcbDesc :pointer-void)            ; SWORD  FAR *pcbDesc
170      (*pfDesc :pointer-void)             ; SDWORD FAR *pfDesc
171      )
172   :module :odbc
173   :returning :short)              ; RETCODE_SQL_API
174
175 (def-function "SQLColumns"
176     ((hstmt sql-handle)             ; HSTMT       hstmt
177      (*szTableQualifier string-ptr) ; UCHAR  FAR *szTableQualifier
178      (cbTableQualifier :short)      ; SWORD       cbTableQualifier
179      (*szTableOwner string-ptr)     ; UCHAR  FAR *szTableOwner
180      (cbTableOwner :short)          ; SWORD       cbTableOwner
181      (*szTableName string-ptr)      ; UCHAR  FAR *szTableName
182      (cbTableName :short)           ; SWORD       cbTableName
183      (*szColumnName string-ptr)     ; UCHAR  FAR *szColumnName
184      (cbColumnName :short)          ; SWORD       cbColumnName
185      )
186   :module :odbc
187   :returning :short)              ; RETCODE_SQL_API
188
189 (def-function "SQLBindCol"
190     ((hstmt sql-handle)         ; HSTMT       hstmt
191      (icol :short)              ; UWORD       icol
192      (fCType :short)            ; SWORD       fCType
193      (rgbValue :pointer-void)            ; PTR         rgbValue
194      (cbValueMax :long)         ; SDWORD      cbValueMax
195      (*pcbValue :pointer-void)           ; SDWORD FAR *pcbValue
196      )
197   :module :odbc
198   :returning :short)              ; RETCODE_SQL_API
199
200 (def-function "SQLFetch"
201     ((hstmt sql-handle)         ; HSTMT       hstmt
202      )
203   :module :odbc
204   :returning :short)              ; RETCODE_SQL_API
205
206 (def-function "SQLTransact"
207     ((henv sql-handle)          ; HENV        henv
208      (hdbc sql-handle)          ; HDBC        hdbc
209      (fType :short)             ; UWORD       fType ($SQL_COMMIT or $SQL_ROLLBACK)
210      )
211   :module :odbc
212   :returning :short)              ; RETCODE_SQL_API
213
214 ;; ODBC 2.0
215 (def-function "SQLDescribeParam"
216     ((hstmt sql-handle)         ; HSTMT       hstmt
217      (ipar :short)              ; UWORD       ipar
218      (*pfSqlType :pointer-void)          ; SWORD  FAR *pfSqlType
219      (*pcbColDef :pointer-void)          ; UDWORD FAR *pcbColDef
220      (*pibScale :pointer-void)           ; SWORD  FAR *pibScale
221      (*pfNullable :pointer-void)         ; SWORD  FAR *pfNullable
222      )
223   :module :odbc
224   :returning :short)              ; RETCODE_SQL_API
225
226 ;; ODBC 2.0
227 (def-function "SQLBindParameter"
228     ((hstmt sql-handle)         ; HSTMT       hstmt
229      (ipar :short)              ; UWORD       ipar
230      (fParamType :short)        ; SWORD       fParamType
231      (fCType :short)            ; SWORD       fCType
232      (fSqlType :short)          ; SWORD       fSqlType
233      (cbColDef :long)           ; UDWORD      cbColDef
234      (ibScale :short)           ; SWORD       ibScale
235      (rgbValue :pointer-void)            ; PTR         rgbValue
236      (cbValueMax :long)         ; SDWORD      cbValueMax
237      (*pcbValue :pointer-void)           ; SDWORD FAR *pcbValue
238      )
239   :module :odbc
240   :returning :short)              ; RETCODE_SQL_API
241
242 ;; level 1
243 (def-function "SQLGetData"
244     ((hstmt sql-handle)         ; HSTMT       hstmt
245      (icol :short)              ; UWORD       icol
246      (fCType :short)            ; SWORD       fCType
247      (rgbValue :pointer-void)            ; PTR         rgbValue
248      (cbValueMax :long)         ; SDWORD      cbValueMax
249      (*pcbValue :pointer-void)           ; SDWORD FAR *pcbValue
250      )
251   :module :odbc
252   :returning :short)              ; RETCODE_SQL_API
253
254 (def-function "SQLParamData"
255     ((hstmt sql-handle)         ; HSTMT       hstmt
256      (*prgbValue :pointer-void)          ; PTR    FAR *prgbValue
257      )
258   :module :odbc
259   :returning :short)              ; RETCODE_SQL_API
260
261 (def-function "SQLPutData"
262     ((hstmt sql-handle)         ; HSTMT       hstmt
263      (rgbValue :pointer-void)            ; PTR         rgbValue
264      (cbValue :long)            ; SDWORD      cbValue
265      )
266   :module :odbc
267   :returning :short)              ; RETCODE_SQL_API
268
269 (def-function "SQLGetConnectOption"
270     ((hdbc sql-handle)          ; HDBC        hdbc
271      (fOption :short)           ; UWORD       fOption
272      (pvParam :pointer-void)             ; PTR         pvParam
273      )
274   :module :odbc
275   :returning :short)              ; RETCODE_SQL_API
276
277 (def-function "SQLSetConnectOption"
278     ((hdbc sql-handle)          ; HDBC        hdbc
279      (fOption :short)           ; UWORD       fOption
280      (vParam :long)             ; UDWORD      vParam
281      )
282   :module :odbc
283   :returning :short)              ; RETCODE_SQL_API
284
285 (def-function "SQLSetPos"
286     ((hstmt sql-handle)         ; HSTMT       hstmt
287      (irow :short)              ; UWORD       irow
288      (fOption :short)           ; UWORD       fOption
289      (fLock :short)             ; UWORD       fLock
290      )
291   :module :odbc
292   :returning :short)              ; RETCODE_SQL_API
293
294                                         ; level 2
295 (def-function "SQLExtendedFetch"
296     ((hstmt sql-handle)         ; HSTMT       hstmt
297      (fFetchType :short)        ; UWORD       fFetchType
298      (irow :long)               ; SDWORD      irow
299      (*pcrow :pointer-void)              ; UDWORD FAR *pcrow
300      (*rgfRowStatus :pointer-void)       ; UWORD  FAR *rgfRowStatus
301      )
302   :module :odbc
303   :returning :short)              ; RETCODE_SQL_API
304
305 (def-function "SQLDataSources"
306     ((henv sql-handle)          ; HENV        henv
307      (fDirection :short)
308      (*szDSN string-ptr)        ; UCHAR  FAR *szDSN
309      (cbDSNMax :short)          ; SWORD       cbDSNMax
310      (*pcbDSN :pointer-void)             ; SWORD      *pcbDSN
311      (*szDescription string-ptr) ; UCHAR     *szDescription
312      (cbDescriptionMax :short)  ; SWORD       cbDescriptionMax
313      (*pcbDescription :pointer-void)     ; SWORD      *pcbDescription
314      )
315   :module :odbc
316   :returning :short)              ; RETCODE_SQL_API
317
318 (def-function "SQLFreeEnv"
319     ((henv sql-handle)          ; HSTMT       hstmt
320      )
321   :module :odbc
322   :returning :short)              ; RETCODE_SQL_API
323
324
325 ;;; foreign type definitions
326
327 ;;(defmacro %sql-len-data-at-exec (length) 
328 ;;  `(- $SQL_LEN_DATA_AT_EXEC_OFFSET ,length))
329
330
331 (def-struct sql-c-time 
332     (hour   :short)
333   (minute :short)
334   (second :short))
335
336 (def-struct sql-c-date
337     (year  :short)
338     (month :short)
339     (day   :short))
340   
341 (def-struct sql-c-timestamp
342     (year     :short)
343     (month    :short)
344     (day      :short)
345     (hour     :short)
346     (minute   :short)
347     (second   :short)
348     (fraction :long))
349