]> git.saurik.com Git - wxWidgets.git/blame - src/iodbc/info.c
New toolbar event processing
[wxWidgets.git] / src / iodbc / info.c
CommitLineData
1a6944fd
RR
1/** Information functions
2
3 Copyright (C) 1995 by Ke Jin <kejin@empress.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14**/
15
16#include <../iodbc/iodbc.h>
17
18#include <../iodbc/isql.h>
19#include <../iodbc/isqlext.h>
20
21#include <../iodbc/dlproc.h>
22
23#include <../iodbc/herr.h>
24#include <../iodbc/henv.h>
25#include <../iodbc/hdbc.h>
26#include <../iodbc/hstmt.h>
27
28#include <../iodbc/itrace.h>
29
30RETCODE SQL_API SQLDataSources(
31 HENV henv,
32 UWORD fDir,
33 UCHAR FAR* szDSN,
34 SWORD cbDSNMax,
35 SWORD FAR* pcbDSN,
36 UCHAR FAR* szDesc,
37 SWORD cbDescMax,
38 SWORD FAR* pcbDesc )
39{
40 GENV_t FAR* genv = (GENV_t FAR*)henv;
41
42 if( henv == SQL_NULL_HENV )
43 {
44 return SQL_INVALID_HANDLE;
45 }
46
47 /* check argument */
48 if( cbDSNMax < 0 || cbDescMax < 0 )
49 {
50 PUSHSQLERR ( genv->herr, en_S1090 );
51
52 return SQL_ERROR;
53 }
54
55 if( fDir != SQL_FETCH_FIRST
56 && fDir != SQL_FETCH_NEXT )
57 {
58 PUSHSQLERR ( genv->herr, en_S1103 );
59
60 return SQL_ERROR;
61 }
62
63 /*************************/
64
65 return SQL_NO_DATA_FOUND;
66}
67
68RETCODE SQL_API SQLDrivers(
69 HENV henv,
70 UWORD fDir,
71 UCHAR FAR* szDrvDesc,
72 SWORD cbDrvDescMax,
73 SWORD FAR* pcbDrvDesc,
74 UCHAR FAR* szDrvAttr,
75 SWORD cbDrvAttrMax,
76 SWORD FAR* pcbDrvAttr )
77{
78 GENV_t FAR* genv = (GENV_t FAR*)henv;
79
80 if( henv == SQL_NULL_HENV )
81 {
82 return SQL_INVALID_HANDLE;
83 }
84
85 if( cbDrvDescMax < 0
86 || cbDrvAttrMax < 0
87 || cbDrvAttrMax == 1 )
88 {
89 PUSHSQLERR ( genv->herr, en_S1090 );
90
91 return SQL_ERROR;
92 }
93
94 if( fDir != SQL_FETCH_FIRST
95 || fDir != SQL_FETCH_NEXT )
96 {
97 PUSHSQLERR ( genv->herr, en_S1103 );
98
99 return SQL_ERROR;
100 }
101
102 /*********************/
103 return SQL_SUCCESS;
104}
105
106
107RETCODE SQL_API SQLGetInfo(
108 HDBC hdbc,
109 UWORD fInfoType,
110 PTR rgbInfoValue,
111 SWORD cbInfoValueMax,
112 SWORD FAR* pcbInfoValue )
113{
114 DBC_t FAR* pdbc = (DBC_t FAR*)hdbc;
115 ENV_t FAR* penv;
116 STMT_t FAR* pstmt = NULL;
117 STMT_t FAR* tpstmt;
118 HPROC hproc;
119 RETCODE retcode = SQL_SUCCESS;
120
121 DWORD dword;
122 int size = 0, len = 0;
123 char buf[16] = { '\0' };
124
125 if( hdbc == SQL_NULL_HDBC
126 || pdbc->henv == SQL_NULL_HENV )
127 {
128 return SQL_INVALID_HANDLE;
129 }
130
131 if( cbInfoValueMax < 0 )
132 {
133 PUSHSQLERR ( pdbc->herr, en_S1090 );
134
135 return SQL_ERROR;
136 }
137
138 if( /* fInfoType < SQL_INFO_FIRST || */
139 ( fInfoType > SQL_INFO_LAST
140 && fInfoType < SQL_INFO_DRIVER_START ) )
141 {
142 PUSHSQLERR ( pdbc->herr, en_S1096 );
143
144 return SQL_ERROR;
145 }
146
147 if( fInfoType == SQL_ODBC_VER )
148 {
149 sprintf( buf, "%02d.%02d",
150 (ODBCVER)>>8, 0x00FF&(ODBCVER) );
151
152
153 if( rgbInfoValue != NULL
154 && cbInfoValueMax > 0 )
155 {
156 len = STRLEN( buf );
157
158 if( len < cbInfoValueMax - 1 )
159 {
160 len = cbInfoValueMax - 1;
161 PUSHSQLERR ( pdbc->herr, en_01004 );
162
163 retcode = SQL_SUCCESS_WITH_INFO;
164 }
165
166 STRNCPY( rgbInfoValue, buf, len );
167 ((char FAR*)rgbInfoValue)[len] = '\0';
168 }
169
170 if( pcbInfoValue != NULL )
171 {
172 *pcbInfoValue = (SWORD)len;
173 }
174
175 return retcode;
176 }
177
178 if( pdbc->state == en_dbc_allocated
179 || pdbc->state == en_dbc_needdata )
180 {
181 PUSHSQLERR ( pdbc->herr, en_08003 );
182
183 return SQL_ERROR;
184 }
185
186 switch( fInfoType )
187 {
188 case SQL_DRIVER_HDBC:
189 dword = (DWORD)(pdbc->dhdbc);
190 size = sizeof(dword);
191 break;
192
193 case SQL_DRIVER_HENV:
194 penv = (ENV_t FAR*)(pdbc->henv);
195 dword = (DWORD)(penv->dhenv);
196 size = sizeof(dword);
197 break;
198
199 case SQL_DRIVER_HLIB:
200 penv = (ENV_t FAR*)(pdbc->henv);
201 dword = (DWORD)(penv->hdll);
202 size = sizeof(dword);
203 break;
204
205 case SQL_DRIVER_HSTMT:
206 if( rgbInfoValue != NULL )
207 {
208 pstmt = *((STMT_t FAR**)rgbInfoValue);
209 }
210
211 for( tpstmt = (STMT_t FAR*)(pdbc->hstmt);
212 tpstmt != NULL;
213 tpstmt = tpstmt->next )
214 {
215 if( tpstmt == pstmt )
216 {
217 break;
218 }
219 }
220
221 if( tpstmt == NULL )
222 {
223 PUSHSQLERR ( pdbc->herr, en_S1009 );
224
225 return SQL_ERROR;
226 }
227
228 dword = (DWORD)(pstmt->dhstmt);
229 size = sizeof(dword);
230 break;
231
232 default:
233 break;
234 }
235
236 if( size )
237 {
238 if( rgbInfoValue != NULL )
239 {
240 *((DWORD*)rgbInfoValue) = dword;
241 }
242
243 if( pcbInfoValue != NULL )
244 {
245 *(pcbInfoValue) = (SWORD)size;
246 }
247
248 return SQL_SUCCESS;
249 }
250
251 hproc = _iodbcdm_getproc( hdbc, en_GetInfo );
252
253 if( hproc == SQL_NULL_HPROC )
254 {
255 PUSHSQLERR ( pdbc->herr, en_IM001 );
256
257 return SQL_ERROR;
258 }
259
260 CALL_DRIVER ( hdbc, retcode, hproc, en_GetInfo, (
261 pdbc->dhdbc,
262 fInfoType,
263 rgbInfoValue,
264 cbInfoValueMax,
265 pcbInfoValue ) )
266
267#if 0
268 retcode = hproc(pdbc->dhdbc,
269 fInfoType,
270 rgbInfoValue,
271 cbInfoValueMax,
272 pcbInfoValue );
273#endif
274
275 if( retcode == SQL_ERROR
276 && fInfoType == SQL_DRIVER_ODBC_VER )
277 {
278 STRCPY( buf, "01.00" );
279
280 if( rgbInfoValue != NULL
281 && cbInfoValueMax > 0 )
282 {
283 len = STRLEN( buf );
284
285 if( len < cbInfoValueMax - 1 )
286 {
287 len = cbInfoValueMax - 1;
288 PUSHSQLERR ( pdbc->herr, en_01004 );
289 }
290
291 STRNCPY( rgbInfoValue, buf, len );
292 ((char FAR*)rgbInfoValue)[len] = '\0';
293 }
294
295 if( pcbInfoValue != NULL )
296 {
297 *pcbInfoValue = (SWORD)len;
298 }
299
300 /* what should we return in this case ???? */
301 }
302
303 return retcode;
304}
305
306RETCODE SQL_API SQLGetFunctions(
307 HDBC hdbc,
308 UWORD fFunc,
309 UWORD FAR* pfExists )
310{
311 DBC_t FAR* pdbc = (DBC_t FAR*)hdbc;
312 HPROC hproc;
313 RETCODE retcode;
314
315 if( hdbc == SQL_NULL_HDBC )
316 {
317 return SQL_INVALID_HANDLE;
318 }
319
320 if( fFunc > SQL_EXT_API_LAST )
321 {
322 PUSHSQLERR ( pdbc->herr, en_S1095 );
323
324 return SQL_ERROR;
325 }
326
327 if( pdbc->state == en_dbc_allocated
328 || pdbc->state == en_dbc_needdata )
329 {
330 PUSHSQLERR ( pdbc->herr, en_S1010 );
331
332 return SQL_ERROR;
333 }
334
335 if( pfExists == NULL )
336 {
337 return SQL_SUCCESS;
338 }
339
340 hproc = _iodbcdm_getproc( hdbc, en_GetFunctions );
341
342 if( hproc != SQL_NULL_HPROC )
343 {
344 CALL_DRIVER ( hdbc, retcode, hproc, en_GetFunctions, (
345 pdbc->dhdbc, fFunc, pfExists ) )
346
347#if 0
348 retcode = hproc( pdbc->dhdbc, fFunc, pfExists );
349#endif
350 return retcode;
351 }
352
353 if( fFunc == SQL_API_SQLSETPARAM )
354 {
355 fFunc = SQL_API_SQLBINDPARAMETER;
356 }
357
358 if( fFunc != SQL_API_ALL_FUNCTIONS )
359 {
360 hproc = _iodbcdm_getproc( hdbc, fFunc );
361
362 if( hproc == SQL_NULL_HPROC )
363 {
364 *pfExists = (UWORD)0;
365 }
366 else
367 {
368 *pfExists = (UWORD)1;
369 }
370
371 return SQL_SUCCESS;
372 }
373
374 for( fFunc=0 ; fFunc < 100; fFunc ++ )
375 {
376 hproc = _iodbcdm_getproc( hdbc, fFunc );
377
378 if( hproc == SQL_NULL_HPROC )
379 {
380 pfExists[fFunc] = (UWORD)0;
381 }
382 else
383 {
384 pfExists[fFunc] = (UWORD)1;
385 }
386 }
387
388 return SQL_SUCCESS;
389}