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))
32 ;; ODBC3 version of SQLFreeStmt, SQLFreeConnect, and SSQLFreeStmt
33 (def-function "SQLFreeHandle"
34 ((handle-type :short) ; HandleType
35 (input-handle sql-handle)) ; Handle
37 :returning :short) ; RETCODE_SQL_API
41 (def-function "SQLAllocEnv"
42 ((*phenv sql-handle-ptr) ; HENV FAR *phenv
45 :returning :short) ; RETCODE_SQL_API
48 (def-function "SQLAllocConnect"
49 ((henv sql-handle) ; HENV henv
50 (*phdbc sql-handle-ptr) ; HDBC FAR *phdbc
53 :returning :short) ; RETCODE_SQL_API
55 (def-function "SQLConnect"
56 ((hdbc sql-handle) ; HDBC hdbc
57 (*szDSN :cstring) ; UCHAR FAR *szDSN
58 (cbDSN :short) ; SWORD cbDSN
59 (*szUID :cstring) ; UCHAR FAR *szUID
60 (cbUID :short) ; SWORD cbUID
61 (*szAuthStr :cstring) ; UCHAR FAR *szAuthStr
62 (cbAuthStr :short) ; SWORD cbAuthStr
65 :returning :short) ; RETCODE_SQL_API
67 (def-function "SQLDriverConnect"
68 ((hdbc sql-handle) ; HDBC hdbc
69 (hwnd sql-handle) ; SQLHWND hwnd
70 (*szConnStrIn :cstring) ; UCHAR FAR *szConnStrIn
71 (cbConnStrIn :short) ; SWORD cbConnStrIn
72 (*szConnStrOut string-ptr) ; UCHAR FAR *szConnStrOut
73 (cbConnStrOutMax :short) ; SWORD cbConnStrOutMax
74 (*pcbConnStrOut :pointer-void) ; SWORD FAR *pcbConnStrOut
75 (fDriverCompletion :short) ; UWORD fDriverCompletion
78 :returning :short) ; RETCODE_SQL_API
80 (def-function "SQLDisconnect"
81 ((hdbc sql-handle)) ; HDBC hdbc
83 :returning :short) ; RETCODE_SQL_API
87 (def-function "SQLFreeConnect"
88 ((hdbc sql-handle)) ; HDBC hdbc
90 :returning :short) ; RETCODE_SQL_API
93 (def-function "SQLAllocStmt"
94 ((hdbc sql-handle) ; HDBC hdbc
95 (*phstmt sql-handle-ptr) ; HSTMT FAR *phstmt
98 :returning :short) ; RETCODE_SQL_API
100 (def-function "SQLGetInfo"
101 ((hdbc sql-handle) ; HDBC hdbc
102 (fInfoType :short) ; UWORD fInfoType
103 (rgbInfoValue :pointer-void) ; PTR rgbInfoValue
104 (cbInfoValueMax :short) ; SWORD cbInfoValueMax
105 (*pcbInfoValue :pointer-void) ; SWORD FAR *pcbInfoValue
108 :returning :short) ; RETCODE_SQL_API
110 (def-function "SQLPrepare"
111 ((hstmt sql-handle) ; HSTMT hstmt
112 (*szSqlStr :cstring) ; UCHAR FAR *szSqlStr
113 (cbSqlStr :int) ; SDWORD cbSqlStr
116 :returning :short) ; RETCODE_SQL_API
118 (def-function "SQLExecute"
119 ((hstmt sql-handle) ; HSTMT hstmt
122 :returning :short) ; RETCODE_SQL_API
124 (def-function "SQLExecDirect"
125 ((hstmt sql-handle) ; HSTMT hstmt
126 (*szSqlStr :cstring) ; UCHAR FAR *szSqlStr
127 (cbSqlStr :int) ; SDWORD cbSqlStr
130 :returning :short) ; RETCODE_SQL_API
132 (def-function "SQLFreeStmt"
133 ((hstmt sql-handle) ; HSTMT hstmt
134 (fOption :short)) ; UWORD fOption
136 :returning :short) ; RETCODE_SQL_API
138 (def-function "SQLCancel"
139 ((hstmt sql-handle) ; HSTMT hstmt
142 :returning :short) ; RETCODE_SQL_API
144 (def-function "SQLError"
145 ((henv sql-handle) ; HENV henv
146 (hdbc sql-handle) ; HDBC hdbc
147 (hstmt sql-handle) ; HSTMT hstmt
148 (*szSqlState string-ptr) ; UCHAR FAR *szSqlState
149 (*pfNativeError (* :int)) ; SDWORD FAR *pfNativeError
150 (*szErrorMsg string-ptr) ; UCHAR FAR *szErrorMsg
151 (cbErrorMsgMax :short) ; SWORD cbErrorMsgMax
152 (*pcbErrorMsg (* :short)) ; SWORD FAR *pcbErrorMsg
155 :returning :short) ; RETCODE_SQL_API
157 (def-function "SQLNumResultCols"
158 ((hstmt sql-handle) ; HSTMT hstmt
159 (*pccol (* :short)) ; SWORD FAR *pccol
162 :returning :short) ; RETCODE_SQL_API
164 (def-function "SQLRowCount"
165 ((hstmt sql-handle) ; HSTMT hstmt
166 (*pcrow (* :int)) ; SDWORD FAR *pcrow
169 :returning :short) ; RETCODE_SQL_API
171 (def-function "SQLDescribeCol"
172 ((hstmt sql-handle) ; HSTMT hstmt
173 (icol :short) ; UWORD icol
174 (*szColName string-ptr) ; UCHAR FAR *szColName
175 (cbColNameMax :short) ; SWORD cbColNameMax
176 (*pcbColName (* :short)) ; SWORD FAR *pcbColName
177 (*pfSqlType (* :short)) ; SWORD FAR *pfSqlType
178 (*pcbColDef (* #.$ODBC-ULONG-TYPE)) ; UDWORD FAR *pcbColDef
179 (*pibScale (* :short)) ; SWORD FAR *pibScale
180 (*pfNullable (* :short)) ; SWORD FAR *pfNullable
183 :returning :short) ; RETCODE_SQL_API
185 (def-function "SQLColAttributes"
186 ((hstmt sql-handle) ; HSTMT hstmt
187 (icol :short) ; UWORD icol
188 (fDescType :short) ; UWORD fDescType
189 (rgbDesc string-ptr) ; PTR rgbDesc
190 (cbDescMax :short) ; SWORD cbDescMax
191 (*pcbDesc (* :short)) ; SWORD FAR *pcbDesc
192 (*pfDesc (* :int)) ; SDWORD FAR *pfDesc
195 :returning :short) ; RETCODE_SQL_API
197 (def-function "SQLColumns"
198 ((hstmt sql-handle) ; HSTMT hstmt
199 (*szTableQualifier :cstring) ; UCHAR FAR *szTableQualifier
200 (cbTableQualifier :short) ; SWORD cbTableQualifier
201 (*szTableOwner :cstring) ; UCHAR FAR *szTableOwner
202 (cbTableOwner :short) ; SWORD cbTableOwner
203 (*szTableName :cstring) ; UCHAR FAR *szTableName
204 (cbTableName :short) ; SWORD cbTableName
205 (*szColumnName :cstring) ; UCHAR FAR *szColumnName
206 (cbColumnName :short) ; SWORD cbColumnName
209 :returning :short) ; RETCODE_SQL_API
211 (def-function "SQLBindCol"
212 ((hstmt sql-handle) ; HSTMT hstmt
213 (icol :short) ; UWORD icol
214 (fCType :short) ; SWORD fCType
215 (rgbValue :pointer-void) ; PTR rgbValue
216 (cbValueMax :int) ; SDWORD cbValueMax
217 (*pcbValue (* :int)) ; SDWORD FAR *pcbValue
220 :returning :short) ; RETCODE_SQL_API
222 (def-function "SQLFetch"
223 ((hstmt sql-handle) ; HSTMT hstmt
226 :returning :short) ; RETCODE_SQL_API
228 (def-function "SQLTransact"
229 ((henv sql-handle) ; HENV henv
230 (hdbc sql-handle) ; HDBC hdbc
231 (fType :short) ; UWORD fType ($SQL_COMMIT or $SQL_ROLLBACK)
234 :returning :short) ; RETCODE_SQL_API
237 (def-function "SQLDescribeParam"
238 ((hstmt sql-handle) ; HSTMT hstmt
239 (ipar :short) ; UWORD ipar
240 (*pfSqlType (* :short)) ; SWORD FAR *pfSqlType
241 (*pcbColDef (* :unsigned-int)) ; UDWORD FAR *pcbColDef
242 (*pibScale (* :short)) ; SWORD FAR *pibScale
243 (*pfNullable (* :short)) ; SWORD FAR *pfNullable
246 :returning :short) ; RETCODE_SQL_API
249 (def-function "SQLBindParameter"
250 ((hstmt sql-handle) ; HSTMT hstmt
251 (ipar :short) ; UWORD ipar
252 (fParamType :short) ; SWORD fParamType
253 (fCType :short) ; SWORD fCType
254 (fSqlType :short) ; SWORD fSqlType
255 (cbColDef :int) ; UDWORD cbColDef
256 (ibScale :short) ; SWORD ibScale
257 (rgbValue :pointer-void) ; PTR rgbValue
258 (cbValueMax :int) ; SDWORD cbValueMax
259 (*pcbValue :pointer-void) ; SDWORD FAR *pcbValue
262 :returning :short) ; RETCODE_SQL_API
265 (def-function "SQLGetData"
266 ((hstmt sql-handle) ; HSTMT hstmt
267 (icol :short) ; UWORD icol
268 (fCType :short) ; SWORD fCType
269 (rgbValue :pointer-void) ; PTR rgbValue
270 (cbValueMax :int) ; SDWORD cbValueMax
271 (*pcbValue :pointer-void) ; SDWORD FAR *pcbValue
274 :returning :short) ; RETCODE_SQL_API
276 (def-function "SQLParamData"
277 ((hstmt sql-handle) ; HSTMT hstmt
278 (*prgbValue :pointer-void) ; PTR FAR *prgbValue
281 :returning :short) ; RETCODE_SQL_API
283 (def-function "SQLPutData"
284 ((hstmt sql-handle) ; HSTMT hstmt
285 (rgbValue :pointer-void) ; PTR rgbValue
286 (cbValue :int) ; SDWORD cbValue
289 :returning :short) ; RETCODE_SQL_API
291 (def-function "SQLGetConnectOption"
292 ((hdbc sql-handle) ; HDBC hdbc
293 (fOption :short) ; UWORD fOption
294 (pvParam :pointer-void) ; PTR pvParam
297 :returning :short) ; RETCODE_SQL_API
299 (def-function "SQLSetConnectOption"
300 ((hdbc sql-handle) ; HDBC hdbc
301 (fOption :short) ; UWORD fOption
302 (vParam :int) ; UDWORD vParam
305 :returning :short) ; RETCODE_SQL_API
307 (def-function "SQLSetPos"
308 ((hstmt sql-handle) ; HSTMT hstmt
309 (irow :short) ; UWORD irow
310 (fOption :short) ; UWORD fOption
311 (fLock :short) ; UWORD fLock
314 :returning :short) ; RETCODE_SQL_API
317 (def-function "SQLExtendedFetch"
318 ((hstmt sql-handle) ; HSTMT hstmt
319 (fFetchType :short) ; UWORD fFetchType
320 (irow :int) ; SDWORD irow
321 (*pcrow :pointer-void) ; UDWORD FAR *pcrow
322 (*rgfRowStatus :pointer-void) ; UWORD FAR *rgfRowStatus
325 :returning :short) ; RETCODE_SQL_API
327 (def-function "SQLDataSources"
328 ((henv sql-handle) ; HENV henv
330 (*szDSN string-ptr) ; UCHAR FAR *szDSN
331 (cbDSNMax :short) ; SWORD cbDSNMax
332 (*pcbDSN (* :short)) ; SWORD *pcbDSN
333 (*szDescription string-ptr) ; UCHAR *szDescription
334 (cbDescriptionMax :short) ; SWORD cbDescriptionMax
335 (*pcbDescription (* :short)) ; SWORD *pcbDescription
338 :returning :short) ; RETCODE_SQL_API
340 (def-function "SQLFreeEnv"
341 ((henv sql-handle) ; HSTMT hstmt
344 :returning :short) ; RETCODE_SQL_API
347 ;;; foreign type definitions
349 ;;(defmacro %sql-len-data-at-exec (length)
350 ;; `(- $SQL_LEN_DATA_AT_EXEC_OFFSET ,length))
353 (def-struct sql-c-time
358 (def-struct sql-c-date
363 (def-struct sql-c-timestamp
374 (def-function "SQLSetEnvAttr"
375 ((henv sql-handle) ; HENV henv
377 (*value :pointer-void)
382 (def-function "SQLGetEnvAttr"
383 ((henv sql-handle) ; HENV henv
385 (*value :pointer-void)
387 (string-length-ptr (* :int)))
391 (def-function "SQLTables"
392 ((hstmt :pointer-void)
393 (catalog-name :pointer-void)
394 (catalog-name-length :short)
395 (schema-name :pointer-void)
396 (schema-name-length :short)
397 (table-name :pointer-void)
398 (table-name-length :short)
399 (table-type-name :pointer-void)
400 (table-type-name-length :short))
405 (def-function "SQLStatistics"
406 ((hstmt :pointer-void)
407 (catalog-name :pointer-void)
408 (catalog-name-length :short)
409 (schema-name :pointer-void)
410 (schema-name-length :short)
411 (table-name :cstring)
412 (table-name-length :short)