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