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
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.
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 ;;;; *************************************************************************
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
))
27 (def-function "SQLAllocHandle"
29 (input-handle sql-handle
)
30 (*phenv sql-handle-ptr
))
35 (def-function "SQLAllocEnv"
36 ((*phenv sql-handle-ptr
) ; HENV FAR *phenv
39 :returning
:short
) ; RETCODE_SQL_API
42 (def-function "SQLAllocConnect"
43 ((henv sql-handle
) ; HENV henv
44 (*phdbc sql-handle-ptr
) ; HDBC FAR *phdbc
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
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
72 :returning
:short
) ; RETCODE_SQL_API
74 (def-function "SQLDisconnect"
75 ((hdbc sql-handle
)) ; HDBC hdbc
77 :returning
:short
) ; RETCODE_SQL_API
80 (def-function "SQLAllocStmt"
81 ((hdbc sql-handle
) ; HDBC hdbc
82 (*phstmt sql-handle-ptr
) ; HSTMT FAR *phstmt
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
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
103 :returning
:short
) ; RETCODE_SQL_API
105 (def-function "SQLExecute"
106 ((hstmt sql-handle
) ; HSTMT hstmt
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
117 :returning
:short
) ; RETCODE_SQL_API
119 (def-function "SQLFreeStmt"
120 ((hstmt sql-handle
) ; HSTMT hstmt
121 (fOption :short
)) ; UWORD fOption
123 :returning
:short
) ; RETCODE_SQL_API
125 (def-function "SQLCancel"
126 ((hstmt sql-handle
) ; HSTMT hstmt
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
142 :returning
:short
) ; RETCODE_SQL_API
144 (def-function "SQLNumResultCols"
145 ((hstmt sql-handle
) ; HSTMT hstmt
146 (*pccol
(* :short
)) ; SWORD FAR *pccol
149 :returning
:short
) ; RETCODE_SQL_API
151 (def-function "SQLRowCount"
152 ((hstmt sql-handle
) ; HSTMT hstmt
153 (*pcrow
(* :int
)) ; SDWORD FAR *pcrow
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
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
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
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
207 :returning
:short
) ; RETCODE_SQL_API
209 (def-function "SQLFetch"
210 ((hstmt sql-handle
) ; HSTMT hstmt
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)
221 :returning
:short
) ; RETCODE_SQL_API
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
233 :returning
:short
) ; RETCODE_SQL_API
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
249 :returning
:short
) ; RETCODE_SQL_API
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
261 :returning
:short
) ; RETCODE_SQL_API
263 (def-function "SQLParamData"
264 ((hstmt sql-handle
) ; HSTMT hstmt
265 (*prgbValue
:pointer-void
) ; PTR FAR *prgbValue
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
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
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
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
301 :returning
:short
) ; RETCODE_SQL_API
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
312 :returning
:short
) ; RETCODE_SQL_API
314 (def-function "SQLDataSources"
315 ((henv sql-handle
) ; HENV henv
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
325 :returning
:short
) ; RETCODE_SQL_API
327 (def-function "SQLFreeEnv"
328 ((henv sql-handle
) ; HSTMT hstmt
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
345 (def-struct sql-c-date
350 (def-struct sql-c-timestamp
361 (def-function "SQLSetEnvAttr"
362 ((henv sql-handle
) ; HENV henv
364 (*value
:pointer-void
)
369 (def-function "SQLGetEnvAttr"
370 ((henv sql-handle
) ; HENV henv
372 (*value
:pointer-void
)
374 (string-length-ptr (* :int
)))
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
))
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
)