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