1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Package: odbc -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
5 ;;;; Name: odbc-ff-interface.lisp
6 ;;;; Purpose: Function definitions for UFFI interface to ODBC
7 ;;;; Author: Kevin M. Rosenberg
9 ;;;; This file, part of CLSQL, is Copyright (c) 2004 by Kevin M. Rosenberg
10 ;;;; and Copyright (C) Paul Meurer 1999 - 2001. All rights reserved.
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 ;;;; *************************************************************************
19 (def-foreign-type sql-handle :pointer-void)
20 (def-foreign-type sql-handle-ptr (* sql-handle))
21 (def-foreign-type string-ptr (* :unsigned-char))
22 (def-type long-ptr-type (* #.$ODBC-LONG-TYPE))
25 (def-function "SQLAllocHandle"
27 (input-handle sql-handle)
28 (*phenv sql-handle-ptr))
33 (def-function "SQLAllocEnv"
34 ((*phenv sql-handle-ptr) ; HENV FAR *phenv
37 :returning :short) ; RETCODE_SQL_API
40 (def-function "SQLAllocConnect"
41 ((henv sql-handle) ; HENV henv
42 (*phdbc sql-handle-ptr) ; HDBC FAR *phdbc
45 :returning :short) ; RETCODE_SQL_API
47 (def-function "SQLConnect"
48 ((hdbc sql-handle) ; HDBC hdbc
49 (*szDSN :cstring) ; UCHAR FAR *szDSN
50 (cbDSN :short) ; SWORD cbDSN
51 (*szUID :cstring) ; UCHAR FAR *szUID
52 (cbUID :short) ; SWORD cbUID
53 (*szAuthStr :cstring) ; UCHAR FAR *szAuthStr
54 (cbAuthStr :short) ; SWORD cbAuthStr
57 :returning :short) ; RETCODE_SQL_API
59 (def-function "SQLDriverConnect"
60 ((hdbc sql-handle) ; HDBC hdbc
61 (hwnd sql-handle) ; SQLHWND hwnd
62 (*szConnStrIn :cstring) ; UCHAR FAR *szConnStrIn
63 (cbConnStrIn :short) ; SWORD cbConnStrIn
64 (*szConnStrOut string-ptr) ; UCHAR FAR *szConnStrOut
65 (cbConnStrOutMax :short) ; SWORD cbConnStrOutMax
66 (*pcbConnStrOut :pointer-void) ; SWORD FAR *pcbConnStrOut
67 (fDriverCompletion :short) ; UWORD fDriverCompletion
70 :returning :short) ; RETCODE_SQL_API
72 (def-function "SQLDisconnect"
73 ((hdbc sql-handle)) ; HDBC hdbc
75 :returning :short) ; RETCODE_SQL_API
78 (def-function "SQLAllocStmt"
79 ((hdbc sql-handle) ; HDBC hdbc
80 (*phstmt sql-handle-ptr) ; HSTMT FAR *phstmt
83 :returning :short) ; RETCODE_SQL_API
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
93 :returning :short) ; RETCODE_SQL_API
95 (def-function "SQLPrepare"
96 ((hstmt sql-handle) ; HSTMT hstmt
97 (*szSqlStr :cstring) ; UCHAR FAR *szSqlStr
98 (cbSqlStr :int) ; SDWORD cbSqlStr
101 :returning :short) ; RETCODE_SQL_API
103 (def-function "SQLExecute"
104 ((hstmt sql-handle) ; HSTMT hstmt
107 :returning :short) ; RETCODE_SQL_API
109 (def-function "SQLExecDirect"
110 ((hstmt sql-handle) ; HSTMT hstmt
111 (*szSqlStr :cstring) ; UCHAR FAR *szSqlStr
112 (cbSqlStr :int) ; SDWORD cbSqlStr
115 :returning :short) ; RETCODE_SQL_API
117 (def-function "SQLFreeStmt"
118 ((hstmt sql-handle) ; HSTMT hstmt
119 (fOption :short)) ; UWORD fOption
121 :returning :short) ; RETCODE_SQL_API
123 (def-function "SQLCancel"
124 ((hstmt sql-handle) ; HSTMT hstmt
127 :returning :short) ; RETCODE_SQL_API
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
140 :returning :short) ; RETCODE_SQL_API
142 (def-function "SQLNumResultCols"
143 ((hstmt sql-handle) ; HSTMT hstmt
144 (*pccol (* :short)) ; SWORD FAR *pccol
147 :returning :short) ; RETCODE_SQL_API
149 (def-function "SQLRowCount"
150 ((hstmt sql-handle) ; HSTMT hstmt
151 (*pcrow (* :int)) ; SDWORD FAR *pcrow
154 :returning :short) ; RETCODE_SQL_API
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
168 :returning :short) ; RETCODE_SQL_API
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
180 :returning :short) ; RETCODE_SQL_API
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
194 :returning :short) ; RETCODE_SQL_API
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
205 :returning :short) ; RETCODE_SQL_API
207 (def-function "SQLFetch"
208 ((hstmt sql-handle) ; HSTMT hstmt
211 :returning :short) ; RETCODE_SQL_API
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)
219 :returning :short) ; RETCODE_SQL_API
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
231 :returning :short) ; RETCODE_SQL_API
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
247 :returning :short) ; RETCODE_SQL_API
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
259 :returning :short) ; RETCODE_SQL_API
261 (def-function "SQLParamData"
262 ((hstmt sql-handle) ; HSTMT hstmt
263 (*prgbValue :pointer-void) ; PTR FAR *prgbValue
266 :returning :short) ; RETCODE_SQL_API
268 (def-function "SQLPutData"
269 ((hstmt sql-handle) ; HSTMT hstmt
270 (rgbValue :pointer-void) ; PTR rgbValue
271 (cbValue :int) ; SDWORD cbValue
274 :returning :short) ; RETCODE_SQL_API
276 (def-function "SQLGetConnectOption"
277 ((hdbc sql-handle) ; HDBC hdbc
278 (fOption :short) ; UWORD fOption
279 (pvParam :pointer-void) ; PTR pvParam
282 :returning :short) ; RETCODE_SQL_API
284 (def-function "SQLSetConnectOption"
285 ((hdbc sql-handle) ; HDBC hdbc
286 (fOption :short) ; UWORD fOption
287 (vParam :int) ; UDWORD vParam
290 :returning :short) ; RETCODE_SQL_API
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
299 :returning :short) ; RETCODE_SQL_API
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
310 :returning :short) ; RETCODE_SQL_API
312 (def-function "SQLDataSources"
313 ((henv sql-handle) ; HENV henv
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
323 :returning :short) ; RETCODE_SQL_API
325 (def-function "SQLFreeEnv"
326 ((henv sql-handle) ; HSTMT hstmt
329 :returning :short) ; RETCODE_SQL_API
332 ;;; foreign type definitions
334 ;;(defmacro %sql-len-data-at-exec (length)
335 ;; `(- $SQL_LEN_DATA_AT_EXEC_OFFSET ,length))
338 (def-struct sql-c-time
343 (def-struct sql-c-date
348 (def-struct sql-c-timestamp
359 (def-function "SQLSetEnvAttr"
360 ((henv sql-handle) ; HENV henv
362 (*value :pointer-void)
367 (def-function "SQLGetEnvAttr"
368 ((henv sql-handle) ; HENV henv
370 (*value :pointer-void)
372 (string-length-ptr (* :int)))
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))
390 (def-function "SQLStatistics"
391 ((hstmt :pointer-void)
392 (catalog-name :pointer-void)
393 (catalog-name-length :short)
394 (schema-name :pointer-void)
395 (schema-name-length :short)
396 (table-name :cstring)
397 (table-name-length :short)