r9959: more odbc v3 conversions
[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$
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 :pointer-void)
22 (def-foreign-type sql-handle-ptr '(* sql-handle))
23 (def-foreign-type string-ptr '(* :unsigned-char))
24 (def-type long-ptr-type '(* #.$ODBC-LONG-TYPE))
25
26 ;; odbc v3
27 (def-function "SQLAllocHandle"
28     ((handle-type :short)
29      (input-handle sql-handle)
30      (*phenv sql-handle-ptr))
31   :module "odbc"
32   :returning :short)
33
34 ;; deprecated
35 (def-function "SQLAllocEnv"
36     ((*phenv sql-handle-ptr)    ; HENV   FAR *phenv
37      )
38   :module "odbc"
39   :returning :short)              ; RETCODE_SQL_API
40
41 (def-function "SQLAllocConnect"
42     ((henv sql-handle)          ; HENV        henv
43      (*phdbc sql-handle-ptr)    ; HDBC   FAR *phdbc
44      )
45   :module "odbc"
46   :returning :short)              ; RETCODE_SQL_API
47
48 (def-function "SQLConnect"
49     ((hdbc sql-handle)          ; HDBC        hdbc
50      (*szDSN :cstring)        ; UCHAR  FAR *szDSN
51      (cbDSN :short)             ; SWORD       cbDSN
52      (*szUID :cstring)        ; UCHAR  FAR *szUID 
53      (cbUID :short)             ; SWORD       cbUID
54      (*szAuthStr :cstring)    ; UCHAR  FAR *szAuthStr
55      (cbAuthStr :short)         ; SWORD       cbAuthStr
56      )
57   :module "odbc"
58   :returning :short)              ; RETCODE_SQL_API
59
60 (def-function "SQLDriverConnect"
61     ((hdbc sql-handle)          ; HDBC        hdbc
62      (hwnd sql-handle)          ; SQLHWND     hwnd
63      (*szConnStrIn string-ptr)  ; UCHAR  FAR *szConnStrIn
64      (cbConnStrIn :short)       ; SWORD       cbConnStrIn
65      (*szConnStrOut string-ptr) ; UCHAR  FAR *szConnStrOut
66      (cbConnStrOutMax :short)   ; SWORD       cbConnStrOutMax
67      (*pcbConnStrOut :pointer-void)      ; SWORD  FAR *pcbConnStrOut
68      (fDriverCompletion :short) ; UWORD       fDriverCompletion
69      )
70   :module "odbc"
71   :returning :short)              ; RETCODE_SQL_API
72
73 (def-function "SQLDisconnect"
74     ((hdbc sql-handle))         ; HDBC        hdbc
75   :module "odbc"
76   :returning :short)              ; RETCODE_SQL_API
77   
78 (def-function "SQLAllocStmt"
79     ((hdbc sql-handle)          ; HDBC        hdbc
80      (*phstmt sql-handle-ptr)   ; HSTMT  FAR *phstmt
81      )
82   :module "odbc"
83   :returning :short)              ; RETCODE_SQL_API
84
85 (def-function "SQLGetInfo"
86     ((hdbc sql-handle)          ; HDBC        hdbc
87      (fInfoType :short)         ; UWORD       fInfoType
88      (rgbInfoValue :pointer-void)        ; PTR         rgbInfoValue
89      (cbInfoValueMax :short)    ; SWORD       cbInfoValueMax
90      (*pcbInfoValue :pointer-void)       ; SWORD  FAR *pcbInfoValue
91      )
92   :module "odbc"
93   :returning :short)              ; RETCODE_SQL_API
94
95 (def-function "SQLPrepare"
96     ((hstmt sql-handle)         ; HSTMT       hstmt
97      (*szSqlStr :cstring)     ; UCHAR  FAR *szSqlStr
98      (cbSqlStr :int)           ; SDWORD      cbSqlStr
99      )
100   :module "odbc"
101   :returning :short)              ; RETCODE_SQL_API
102
103 (def-function "SQLExecute"
104     ((hstmt sql-handle)         ; HSTMT       hstmt
105      )
106   :module "odbc"
107   :returning :short)              ; RETCODE_SQL_API
108
109 (def-function "SQLExecDirect"
110     ((hstmt sql-handle)         ; HSTMT       hstmt
111      (*szSqlStr :cstring)     ; UCHAR  FAR *szSqlStr
112      (cbSqlStr :int)           ; SDWORD      cbSqlStr
113      )
114   :module "odbc"
115   :returning :short)              ; RETCODE_SQL_API
116
117 (def-function "SQLFreeStmt"
118     ((hstmt sql-handle)         ; HSTMT       hstmt
119      (fOption :short))          ; UWORD       fOption
120   :module "odbc"
121   :returning :short)              ; RETCODE_SQL_API
122
123   (def-function "SQLCancel"
124       ((hstmt sql-handle)         ; HSTMT       hstmt
125        )
126     :module "odbc"
127   :returning :short)              ; RETCODE_SQL_API
128
129 (def-function "SQLError"
130     ((henv sql-handle)          ; HENV        henv
131      (hdbc sql-handle)          ; HDBC        hdbc
132      (hstmt sql-handle)         ; HSTMT       hstmt
133      (*szSqlState string-ptr)   ; UCHAR  FAR *szSqlState
134      (*pfNativeError (* :int))      ; SDWORD FAR *pfNativeError
135      (*szErrorMsg string-ptr)   ; UCHAR  FAR *szErrorMsg
136      (cbErrorMsgMax :short)     ; SWORD       cbErrorMsgMax
137      (*pcbErrorMsg (* :short))        ; SWORD  FAR *pcbErrorMsg
138      )
139   :module "odbc"
140   :returning :short)              ; RETCODE_SQL_API
141
142 (def-function "SQLNumResultCols"
143     ((hstmt sql-handle)         ; HSTMT       hstmt
144      (*pccol (* :short))              ; SWORD  FAR *pccol
145      )
146   :module "odbc"
147   :returning :short)              ; RETCODE_SQL_API
148
149 (def-function "SQLRowCount"
150     ((hstmt sql-handle)         ; HSTMT       hstmt
151      (*pcrow (* :int))              ; SDWORD FAR *pcrow
152      )
153   :module "odbc"
154   :returning :short)              ; RETCODE_SQL_API
155
156 (def-function "SQLDescribeCol"
157     ((hstmt sql-handle)         ; HSTMT       hstmt
158      (icol :short)              ; UWORD       icol
159      (*szColName string-ptr)    ; UCHAR  FAR *szColName
160      (cbColNameMax :short)      ; SWORD       cbColNameMax
161      (*pcbColName (* :short))         ; SWORD  FAR *pcbColName
162      (*pfSqlType (* :short))          ; SWORD  FAR *pfSqlType
163      (*pcbColDef (* #.$ODBC-ULONG-TYPE))          ; UDWORD FAR *pcbColDef
164      (*pibScale (* :short))           ; SWORD  FAR *pibScale
165      (*pfNullable (* :short))         ; SWORD  FAR *pfNullable
166      )
167   :module "odbc"
168   :returning :short)              ; RETCODE_SQL_API
169
170 (def-function "SQLColAttributes"
171     ((hstmt sql-handle)         ; HSTMT       hstmt
172      (icol :short)              ; UWORD       icol
173      (fDescType :short)         ; UWORD       fDescType
174      (rgbDesc string-ptr)             ; PTR         rgbDesc
175      (cbDescMax :short)         ; SWORD       cbDescMax
176      (*pcbDesc (* :short))            ; SWORD  FAR *pcbDesc
177      (*pfDesc (* :int))             ; SDWORD FAR *pfDesc
178      )
179   :module "odbc"
180   :returning :short)              ; RETCODE_SQL_API
181
182 (def-function "SQLColumns"
183     ((hstmt sql-handle)             ; HSTMT       hstmt
184      (*szTableQualifier :cstring) ; UCHAR  FAR *szTableQualifier
185      (cbTableQualifier :short)      ; SWORD       cbTableQualifier
186      (*szTableOwner :cstring)     ; UCHAR  FAR *szTableOwner
187      (cbTableOwner :short)          ; SWORD       cbTableOwner
188      (*szTableName :cstring)      ; UCHAR  FAR *szTableName
189      (cbTableName :short)           ; SWORD       cbTableName
190      (*szColumnName :cstring)     ; UCHAR  FAR *szColumnName
191      (cbColumnName :short)          ; SWORD       cbColumnName
192      )
193   :module "odbc"
194   :returning :short)              ; RETCODE_SQL_API
195
196 (def-function "SQLBindCol"
197     ((hstmt sql-handle)         ; HSTMT       hstmt
198      (icol :short)              ; UWORD       icol
199      (fCType :short)            ; SWORD       fCType
200      (rgbValue :pointer-void)            ; PTR         rgbValue
201      (cbValueMax :int)         ; SDWORD      cbValueMax
202      (*pcbValue (* :int))           ; SDWORD FAR *pcbValue
203      )
204   :module "odbc"
205   :returning :short)              ; RETCODE_SQL_API
206
207 (def-function "SQLFetch"
208     ((hstmt sql-handle)         ; HSTMT       hstmt
209      )
210   :module "odbc"
211   :returning :short)              ; RETCODE_SQL_API
212
213 (def-function "SQLTransact"
214     ((henv sql-handle)          ; HENV        henv
215      (hdbc sql-handle)          ; HDBC        hdbc
216      (fType :short)             ; UWORD       fType ($SQL_COMMIT or $SQL_ROLLBACK)
217      )
218   :module "odbc"
219   :returning :short)              ; RETCODE_SQL_API
220
221 ;; ODBC 2.0
222 (def-function "SQLDescribeParam"
223     ((hstmt sql-handle)         ; HSTMT       hstmt
224      (ipar :short)              ; UWORD       ipar
225      (*pfSqlType (* :short))          ; SWORD  FAR *pfSqlType
226      (*pcbColDef (* :unsigned-int))          ; UDWORD FAR *pcbColDef
227      (*pibScale (* :short))           ; SWORD  FAR *pibScale
228      (*pfNullable (* :short))         ; SWORD  FAR *pfNullable
229      )
230   :module "odbc"
231   :returning :short)              ; RETCODE_SQL_API
232
233 ;; ODBC 2.0
234 (def-function "SQLBindParameter"
235     ((hstmt sql-handle)         ; HSTMT       hstmt
236      (ipar :short)              ; UWORD       ipar
237      (fParamType :short)        ; SWORD       fParamType
238      (fCType :short)            ; SWORD       fCType
239      (fSqlType :short)          ; SWORD       fSqlType
240      (cbColDef :int)           ; UDWORD      cbColDef
241      (ibScale :short)           ; SWORD       ibScale
242      (rgbValue :pointer-void)            ; PTR         rgbValue
243      (cbValueMax :int)         ; SDWORD      cbValueMax
244      (*pcbValue :pointer-void)           ; SDWORD FAR *pcbValue
245      )
246   :module "odbc"
247   :returning :short)              ; RETCODE_SQL_API
248
249 ;; level 1
250 (def-function "SQLGetData"
251     ((hstmt sql-handle)         ; HSTMT       hstmt
252      (icol :short)              ; UWORD       icol
253      (fCType :short)            ; SWORD       fCType
254      (rgbValue :pointer-void)            ; PTR         rgbValue
255      (cbValueMax :int)         ; SDWORD      cbValueMax
256      (*pcbValue :pointer-void)           ; SDWORD FAR *pcbValue
257      )
258   :module "odbc"
259   :returning :short)              ; RETCODE_SQL_API
260
261 (def-function "SQLParamData"
262     ((hstmt sql-handle)         ; HSTMT       hstmt
263      (*prgbValue :pointer-void)          ; PTR    FAR *prgbValue
264      )
265   :module "odbc"
266   :returning :short)              ; RETCODE_SQL_API
267
268 (def-function "SQLPutData"
269     ((hstmt sql-handle)         ; HSTMT       hstmt
270      (rgbValue :pointer-void)            ; PTR         rgbValue
271      (cbValue :int)            ; SDWORD      cbValue
272      )
273   :module "odbc"
274   :returning :short)              ; RETCODE_SQL_API
275
276 (def-function "SQLGetConnectOption"
277     ((hdbc sql-handle)          ; HDBC        hdbc
278      (fOption :short)           ; UWORD       fOption
279      (pvParam :pointer-void)             ; PTR         pvParam
280      )
281   :module "odbc"
282   :returning :short)              ; RETCODE_SQL_API
283
284 (def-function "SQLSetConnectOption"
285     ((hdbc sql-handle)          ; HDBC        hdbc
286      (fOption :short)           ; UWORD       fOption
287      (vParam :int)             ; UDWORD      vParam
288      )
289   :module "odbc"
290   :returning :short)              ; RETCODE_SQL_API
291
292 (def-function "SQLSetPos"
293     ((hstmt sql-handle)         ; HSTMT       hstmt
294      (irow :short)              ; UWORD       irow
295      (fOption :short)           ; UWORD       fOption
296      (fLock :short)             ; UWORD       fLock
297      )
298   :module "odbc"
299   :returning :short)              ; RETCODE_SQL_API
300
301                                         ; level 2
302 (def-function "SQLExtendedFetch"
303     ((hstmt sql-handle)         ; HSTMT       hstmt
304      (fFetchType :short)        ; UWORD       fFetchType
305      (irow :int)               ; SDWORD      irow
306      (*pcrow :pointer-void)              ; UDWORD FAR *pcrow
307      (*rgfRowStatus :pointer-void)       ; UWORD  FAR *rgfRowStatus
308      )
309   :module "odbc"
310   :returning :short)              ; RETCODE_SQL_API
311
312 (def-function "SQLDataSources"
313     ((henv sql-handle)          ; HENV        henv
314      (fDirection :short)
315      (*szDSN string-ptr)        ; UCHAR  FAR *szDSN
316      (cbDSNMax :short)          ; SWORD       cbDSNMax
317      (*pcbDSN (* :short))             ; SWORD      *pcbDSN
318      (*szDescription string-ptr) ; UCHAR     *szDescription
319      (cbDescriptionMax :short)  ; SWORD       cbDescriptionMax
320      (*pcbDescription (* :short))     ; SWORD      *pcbDescription
321      )
322   :module "odbc"
323   :returning :short)              ; RETCODE_SQL_API
324
325 (def-function "SQLFreeEnv"
326     ((henv sql-handle)          ; HSTMT       hstmt
327      )
328   :module "odbc"
329   :returning :short)              ; RETCODE_SQL_API
330
331
332 ;;; foreign type definitions
333
334 ;;(defmacro %sql-len-data-at-exec (length) 
335 ;;  `(- $SQL_LEN_DATA_AT_EXEC_OFFSET ,length))
336
337
338 (def-struct sql-c-time 
339     (hour   :short)
340   (minute :short)
341   (second :short))
342
343 (def-struct sql-c-date
344     (year  :short)
345   (month :short)
346   (day   :short))
347   
348 (def-struct sql-c-timestamp
349     (year     :short)
350   (month    :short)
351   (day      :short)
352   (hour     :short)
353   (minute   :short)
354   (second   :short)
355   (fraction :int))
356
357 ;;; Added by KMR
358
359 (def-function "SQLSetEnvAttr"
360     ((henv sql-handle)          ; HENV        henv
361      (attr :int)
362      (*value :pointer-void)
363      (szLength :int))
364   :module "odbc"
365   :returning :short)
366
367 (def-function "SQLGetEnvAttr"
368     ((henv sql-handle)          ; HENV        henv
369      (attr :int)
370      (*value :pointer-void)
371      (szLength :int)
372      (string-length-ptr (* :int)))
373   :module "odbc"
374   :returning :short)
375
376 (def-function "SQLTables"
377     ((hstmt :pointer-void)
378      (catalog-name :pointer-void)
379      (catalog-name-length :short)
380      (schema-name :pointer-void)
381      (schema-name-length :short)
382      (table-name :pointer-void)
383      (table-name-length :short)
384      (table-type-name :pointer-void)
385      (table-type-name-length :short))
386   :returning :short)
387
388
389 (def-function "SQLStatistics"
390     ((hstmt :pointer-void)
391      (catalog-name :pointer-void)
392      (catalog-name-length :short)
393      (schema-name :pointer-void)
394      (schema-name-length :short)
395      (table-name :cstring)
396      (table-name-length :short)
397      (unique :short)
398      (reserved :short))
399   :returning :short)
400
401