]>
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>
30 RETCODE SQL_API
SQLDataSources(
40 GENV_t FAR
* genv
= (GENV_t FAR
*)henv
;
42 if( henv
== SQL_NULL_HENV
)
44 return SQL_INVALID_HANDLE
;
48 if( cbDSNMax
< 0 || cbDescMax
< 0 )
50 PUSHSQLERR ( genv
->herr
, en_S1090
);
55 if( fDir
!= SQL_FETCH_FIRST
56 && fDir
!= SQL_FETCH_NEXT
)
58 PUSHSQLERR ( genv
->herr
, en_S1103
);
63 /*************************/
65 return SQL_NO_DATA_FOUND
;
68 RETCODE SQL_API
SQLDrivers(
73 SWORD FAR
* pcbDrvDesc
,
76 SWORD FAR
* pcbDrvAttr
)
78 GENV_t FAR
* genv
= (GENV_t FAR
*)henv
;
80 if( henv
== SQL_NULL_HENV
)
82 return SQL_INVALID_HANDLE
;
87 || cbDrvAttrMax
== 1 )
89 PUSHSQLERR ( genv
->herr
, en_S1090
);
94 if( fDir
!= SQL_FETCH_FIRST
95 || fDir
!= SQL_FETCH_NEXT
)
97 PUSHSQLERR ( genv
->herr
, en_S1103
);
102 /*********************/
107 RETCODE SQL_API
SQLGetInfo(
111 SWORD cbInfoValueMax
,
112 SWORD FAR
* pcbInfoValue
)
114 DBC_t FAR
* pdbc
= (DBC_t FAR
*)hdbc
;
116 STMT_t FAR
* pstmt
= NULL
;
119 RETCODE retcode
= SQL_SUCCESS
;
122 int size
= 0, len
= 0;
123 char buf
[16] = { '\0' };
125 if( hdbc
== SQL_NULL_HDBC
126 || pdbc
->henv
== SQL_NULL_HENV
)
128 return SQL_INVALID_HANDLE
;
131 if( cbInfoValueMax
< 0 )
133 PUSHSQLERR ( pdbc
->herr
, en_S1090
);
138 if( /* fInfoType < SQL_INFO_FIRST || */
139 ( fInfoType
> SQL_INFO_LAST
140 && fInfoType
< SQL_INFO_DRIVER_START
) )
142 PUSHSQLERR ( pdbc
->herr
, en_S1096
);
147 if( fInfoType
== SQL_ODBC_VER
)
149 sprintf( buf
, "%02d.%02d",
150 (ODBCVER
)>>8, 0x00FF&(ODBCVER
) );
153 if( rgbInfoValue
!= NULL
154 && cbInfoValueMax
> 0 )
158 if( len
< cbInfoValueMax
- 1 )
160 len
= cbInfoValueMax
- 1;
161 PUSHSQLERR ( pdbc
->herr
, en_01004
);
163 retcode
= SQL_SUCCESS_WITH_INFO
;
166 STRNCPY( rgbInfoValue
, buf
, len
);
167 ((char FAR
*)rgbInfoValue
)[len
] = '\0';
170 if( pcbInfoValue
!= NULL
)
172 *pcbInfoValue
= (SWORD
)len
;
178 if( pdbc
->state
== en_dbc_allocated
179 || pdbc
->state
== en_dbc_needdata
)
181 PUSHSQLERR ( pdbc
->herr
, en_08003
);
188 case SQL_DRIVER_HDBC
:
189 dword
= (DWORD
)(pdbc
->dhdbc
);
190 size
= sizeof(dword
);
193 case SQL_DRIVER_HENV
:
194 penv
= (ENV_t FAR
*)(pdbc
->henv
);
195 dword
= (DWORD
)(penv
->dhenv
);
196 size
= sizeof(dword
);
199 case SQL_DRIVER_HLIB
:
200 penv
= (ENV_t FAR
*)(pdbc
->henv
);
201 dword
= (DWORD
)(penv
->hdll
);
202 size
= sizeof(dword
);
205 case SQL_DRIVER_HSTMT
:
206 if( rgbInfoValue
!= NULL
)
208 pstmt
= *((STMT_t FAR
**)rgbInfoValue
);
211 for( tpstmt
= (STMT_t FAR
*)(pdbc
->hstmt
);
213 tpstmt
= tpstmt
->next
)
215 if( tpstmt
== pstmt
)
223 PUSHSQLERR ( pdbc
->herr
, en_S1009
);
228 dword
= (DWORD
)(pstmt
->dhstmt
);
229 size
= sizeof(dword
);
238 if( rgbInfoValue
!= NULL
)
240 *((DWORD
*)rgbInfoValue
) = dword
;
243 if( pcbInfoValue
!= NULL
)
245 *(pcbInfoValue
) = (SWORD
)size
;
251 hproc
= _iodbcdm_getproc( hdbc
, en_GetInfo
);
253 if( hproc
== SQL_NULL_HPROC
)
255 PUSHSQLERR ( pdbc
->herr
, en_IM001
);
260 CALL_DRIVER ( hdbc
, retcode
, hproc
, en_GetInfo
, (
268 retcode
= hproc(pdbc
->dhdbc
,
275 if( retcode
== SQL_ERROR
276 && fInfoType
== SQL_DRIVER_ODBC_VER
)
278 STRCPY( buf
, "01.00" );
280 if( rgbInfoValue
!= NULL
281 && cbInfoValueMax
> 0 )
285 if( len
< cbInfoValueMax
- 1 )
287 len
= cbInfoValueMax
- 1;
288 PUSHSQLERR ( pdbc
->herr
, en_01004
);
291 STRNCPY( rgbInfoValue
, buf
, len
);
292 ((char FAR
*)rgbInfoValue
)[len
] = '\0';
295 if( pcbInfoValue
!= NULL
)
297 *pcbInfoValue
= (SWORD
)len
;
300 /* what should we return in this case ???? */
306 RETCODE SQL_API
SQLGetFunctions(
309 UWORD FAR
* pfExists
)
311 DBC_t FAR
* pdbc
= (DBC_t FAR
*)hdbc
;
315 if( hdbc
== SQL_NULL_HDBC
)
317 return SQL_INVALID_HANDLE
;
320 if( fFunc
> SQL_EXT_API_LAST
)
322 PUSHSQLERR ( pdbc
->herr
, en_S1095
);
327 if( pdbc
->state
== en_dbc_allocated
328 || pdbc
->state
== en_dbc_needdata
)
330 PUSHSQLERR ( pdbc
->herr
, en_S1010
);
335 if( pfExists
== NULL
)
340 hproc
= _iodbcdm_getproc( hdbc
, en_GetFunctions
);
342 if( hproc
!= SQL_NULL_HPROC
)
344 CALL_DRIVER ( hdbc
, retcode
, hproc
, en_GetFunctions
, (
345 pdbc
->dhdbc
, fFunc
, pfExists
) )
348 retcode
= hproc( pdbc
->dhdbc
, fFunc
, pfExists
);
353 if( fFunc
== SQL_API_SQLSETPARAM
)
355 fFunc
= SQL_API_SQLBINDPARAMETER
;
358 if( fFunc
!= SQL_API_ALL_FUNCTIONS
)
360 hproc
= _iodbcdm_getproc( hdbc
, fFunc
);
362 if( hproc
== SQL_NULL_HPROC
)
364 *pfExists
= (UWORD
)0;
368 *pfExists
= (UWORD
)1;
374 for( fFunc
=0 ; fFunc
< 100; fFunc
++ )
376 hproc
= _iodbcdm_getproc( hdbc
, fFunc
);
378 if( hproc
== SQL_NULL_HPROC
)
380 pfExists
[fFunc
] = (UWORD
)0;
384 pfExists
[fFunc
] = (UWORD
)1;