]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/info.c
1 /** Information functions
3 Copyright (C) 1995 by Ke Jin <kejin@empress.com>
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.
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.
16 #include <../iodbc/iodbc.h>
18 #include <../iodbc/isql.h>
19 #include <../iodbc/isqlext.h>
21 #include <../iodbc/dlproc.h>
23 #include <../iodbc/herr.h>
24 #include <../iodbc/henv.h>
25 #include <../iodbc/hdbc.h>
26 #include <../iodbc/hstmt.h>
28 #include <../iodbc/itrace.h>
33 RETCODE SQL_API
SQLDataSources(
43 GENV_t FAR
* genv
= (GENV_t FAR
*)henv
;
45 if( henv
== SQL_NULL_HENV
)
47 return SQL_INVALID_HANDLE
;
51 if( cbDSNMax
< 0 || cbDescMax
< 0 )
53 PUSHSQLERR ( genv
->herr
, en_S1090
);
58 if( fDir
!= SQL_FETCH_FIRST
59 && fDir
!= SQL_FETCH_NEXT
)
61 PUSHSQLERR ( genv
->herr
, en_S1103
);
66 /*************************/
68 return SQL_NO_DATA_FOUND
;
71 RETCODE SQL_API
SQLDrivers(
76 SWORD FAR
* pcbDrvDesc
,
79 SWORD FAR
* pcbDrvAttr
)
81 GENV_t FAR
* genv
= (GENV_t FAR
*)henv
;
83 if( henv
== SQL_NULL_HENV
)
85 return SQL_INVALID_HANDLE
;
90 || cbDrvAttrMax
== 1 )
92 PUSHSQLERR ( genv
->herr
, en_S1090
);
97 if( fDir
!= SQL_FETCH_FIRST
98 || fDir
!= SQL_FETCH_NEXT
)
100 PUSHSQLERR ( genv
->herr
, en_S1103
);
105 /*********************/
110 RETCODE SQL_API
SQLGetInfo(
114 SWORD cbInfoValueMax
,
115 SWORD FAR
* pcbInfoValue
)
117 DBC_t FAR
* pdbc
= (DBC_t FAR
*)hdbc
;
119 STMT_t FAR
* pstmt
= NULL
;
122 RETCODE retcode
= SQL_SUCCESS
;
125 int size
= 0, len
= 0;
126 char buf
[16] = { '\0' };
128 if( hdbc
== SQL_NULL_HDBC
129 || pdbc
->henv
== SQL_NULL_HENV
)
131 return SQL_INVALID_HANDLE
;
134 if( cbInfoValueMax
< 0 )
136 PUSHSQLERR ( pdbc
->herr
, en_S1090
);
141 if( /* fInfoType < SQL_INFO_FIRST || */
142 ( fInfoType
> SQL_INFO_LAST
143 && fInfoType
< SQL_INFO_DRIVER_START
) )
145 PUSHSQLERR ( pdbc
->herr
, en_S1096
);
150 if( fInfoType
== SQL_ODBC_VER
)
152 sprintf( buf
, "%02d.%02d",
153 (ODBCVER
)>>8, 0x00FF&(ODBCVER
) );
156 if( rgbInfoValue
!= NULL
157 && cbInfoValueMax
> 0 )
161 if( len
< cbInfoValueMax
- 1 )
163 len
= cbInfoValueMax
- 1;
164 PUSHSQLERR ( pdbc
->herr
, en_01004
);
166 retcode
= SQL_SUCCESS_WITH_INFO
;
169 STRNCPY( rgbInfoValue
, buf
, len
);
170 ((char FAR
*)rgbInfoValue
)[len
] = '\0';
173 if( pcbInfoValue
!= NULL
)
175 *pcbInfoValue
= (SWORD
)len
;
181 if( pdbc
->state
== en_dbc_allocated
182 || pdbc
->state
== en_dbc_needdata
)
184 PUSHSQLERR ( pdbc
->herr
, en_08003
);
191 case SQL_DRIVER_HDBC
:
192 dword
= (DWORD
)(pdbc
->dhdbc
);
193 size
= sizeof(dword
);
196 case SQL_DRIVER_HENV
:
197 penv
= (ENV_t FAR
*)(pdbc
->henv
);
198 dword
= (DWORD
)(penv
->dhenv
);
199 size
= sizeof(dword
);
202 case SQL_DRIVER_HLIB
:
203 penv
= (ENV_t FAR
*)(pdbc
->henv
);
204 dword
= (DWORD
)(penv
->hdll
);
205 size
= sizeof(dword
);
208 case SQL_DRIVER_HSTMT
:
209 if( rgbInfoValue
!= NULL
)
211 pstmt
= *((STMT_t FAR
**)rgbInfoValue
);
214 for( tpstmt
= (STMT_t FAR
*)(pdbc
->hstmt
);
216 tpstmt
= tpstmt
->next
)
218 if( tpstmt
== pstmt
)
226 PUSHSQLERR ( pdbc
->herr
, en_S1009
);
231 dword
= (DWORD
)(pstmt
->dhstmt
);
232 size
= sizeof(dword
);
241 if( rgbInfoValue
!= NULL
)
243 *((DWORD
*)rgbInfoValue
) = dword
;
246 if( pcbInfoValue
!= NULL
)
248 *(pcbInfoValue
) = (SWORD
)size
;
254 hproc
= _iodbcdm_getproc( hdbc
, en_GetInfo
);
256 if( hproc
== SQL_NULL_HPROC
)
258 PUSHSQLERR ( pdbc
->herr
, en_IM001
);
263 CALL_DRIVER ( hdbc
, retcode
, hproc
, en_GetInfo
, (
271 retcode
= hproc(pdbc
->dhdbc
,
278 if( retcode
== SQL_ERROR
279 && fInfoType
== SQL_DRIVER_ODBC_VER
)
281 STRCPY( buf
, "01.00" );
283 if( rgbInfoValue
!= NULL
284 && cbInfoValueMax
> 0 )
288 if( len
< cbInfoValueMax
- 1 )
290 len
= cbInfoValueMax
- 1;
291 PUSHSQLERR ( pdbc
->herr
, en_01004
);
294 STRNCPY( rgbInfoValue
, buf
, len
);
295 ((char FAR
*)rgbInfoValue
)[len
] = '\0';
298 if( pcbInfoValue
!= NULL
)
300 *pcbInfoValue
= (SWORD
)len
;
303 /* what should we return in this case ???? */
309 RETCODE SQL_API
SQLGetFunctions(
312 UWORD FAR
* pfExists
)
314 DBC_t FAR
* pdbc
= (DBC_t FAR
*)hdbc
;
318 if( hdbc
== SQL_NULL_HDBC
)
320 return SQL_INVALID_HANDLE
;
323 if( fFunc
> SQL_EXT_API_LAST
)
325 PUSHSQLERR ( pdbc
->herr
, en_S1095
);
330 if( pdbc
->state
== en_dbc_allocated
331 || pdbc
->state
== en_dbc_needdata
)
333 PUSHSQLERR ( pdbc
->herr
, en_S1010
);
338 if( pfExists
== NULL
)
343 hproc
= _iodbcdm_getproc( hdbc
, en_GetFunctions
);
345 if( hproc
!= SQL_NULL_HPROC
)
347 CALL_DRIVER ( hdbc
, retcode
, hproc
, en_GetFunctions
, (
348 pdbc
->dhdbc
, fFunc
, pfExists
) )
351 retcode
= hproc( pdbc
->dhdbc
, fFunc
, pfExists
);
356 if( fFunc
== SQL_API_SQLSETPARAM
)
358 fFunc
= SQL_API_SQLBINDPARAMETER
;
361 if( fFunc
!= SQL_API_ALL_FUNCTIONS
)
363 hproc
= _iodbcdm_getproc( hdbc
, fFunc
);
365 if( hproc
== SQL_NULL_HPROC
)
367 *pfExists
= (UWORD
)0;
371 *pfExists
= (UWORD
)1;
377 for( fFunc
=0 ; fFunc
< 100; fFunc
++ )
379 hproc
= _iodbcdm_getproc( hdbc
, fFunc
);
381 if( hproc
== SQL_NULL_HPROC
)
383 pfExists
[fFunc
] = (UWORD
)0;
387 pfExists
[fFunc
] = (UWORD
)1;