]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/info.c
6 * Information functions
8 * The iODBC driver manager.
10 * Copyright (C) 1995 by Ke Jin <kejin@empress.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
44 #define SECT1 "ODBC Data Sources"
45 #define SECT2 "Default"
46 #define MAX_ENTRIES 1024
48 extern char * _iodbcdm_getinifile (char *buf
, int size
);
49 extern char * _iodbcdm_getkeyvalbydsn (char *dsn
, int dsnlen
, char *keywd
, char *value
, int size
);
52 stricmp (const char *s1
, const char *s2
)
58 if ((cmp
= toupper (*s1
) - toupper (*s2
)) != 0)
63 return (*s2
) ? -1 : 0;
67 SectSorter (const void *p1
, const void *p2
)
69 char **s1
= (char **) p1
;
70 char **s2
= (char **) p2
;
72 return stricmp (*s1
, *s2
);
87 GENV_t FAR
*genv
= (GENV_t FAR
*) henv
;
92 static int cur_entry
= -1;
93 static int num_entries
= 0;
94 static char **sect
= NULL
;
96 if (henv
== SQL_NULL_HENV
)
98 return SQL_INVALID_HANDLE
;
101 if (cbDSNMax
< 0 || cbDescMax
< 0)
103 PUSHSQLERR (genv
->herr
, en_S1090
);
107 if (fDir
!= SQL_FETCH_FIRST
108 && fDir
!= SQL_FETCH_NEXT
)
110 PUSHSQLERR (genv
->herr
, en_S1103
);
114 if (cur_entry
< 0 || fDir
== SQL_FETCH_FIRST
)
121 * Open the odbc.ini file
123 path
= (char *) _iodbcdm_getinifile (buf
, sizeof (buf
));
124 if ((fp
= fopen (path
, "r")) == NULL
)
126 return SQL_NO_DATA_FOUND
;
129 * Free old section list
133 for (i
= 0; i
< MAX_ENTRIES
; i
++)
138 if ((sect
= (char **) calloc (MAX_ENTRIES
, sizeof (char *))) == NULL
)
140 PUSHSQLERR (genv
->herr
, en_S1011
);
145 * Build a dynamic list of sections
151 str
= fgets (buf
, sizeof (buf
), fp
);
159 for (p
= str
; *p
; p
++)
163 if (!strcmp (str
, SECT1
))
165 if (!strcmp (str
, SECT2
))
169 * Add this section to the comma separated list
171 if (num_entries
>= MAX_ENTRIES
)
172 break; /* Skip the rest */
174 sect
[num_entries
++] = (char *) strdup (str
);
179 * Sort all entries so we can present a nice list
182 qsort (sect
, num_entries
, sizeof (char *), SectSorter
);
185 * Try to get to the next item
187 if (cur_entry
>= num_entries
)
189 cur_entry
= 0; /* Next time, start all over again */
190 return SQL_NO_DATA_FOUND
;
193 * Copy DSN information
195 STRNCPY (szDSN
, sect
[cur_entry
], cbDSNMax
);
198 * And find the description that goes with this entry
200 _iodbcdm_getkeyvalbydsn (sect
[cur_entry
], strlen (sect
[cur_entry
]),
201 "Description", (char*) szDesc
, cbDescMax
);
216 UCHAR FAR
* szDrvDesc
,
218 SWORD FAR
* pcbDrvDesc
,
219 UCHAR FAR
* szDrvAttr
,
221 SWORD FAR
* pcbDrvAttr
)
223 GENV_t FAR
*genv
= (GENV_t FAR
*) henv
;
225 if (henv
== SQL_NULL_HENV
)
227 return SQL_INVALID_HANDLE
;
230 if (cbDrvDescMax
< 0 || cbDrvAttrMax
< 0 || cbDrvAttrMax
== 1)
232 PUSHSQLERR (genv
->herr
, en_S1090
);
237 if (fDir
!= SQL_FETCH_FIRST
|| fDir
!= SQL_FETCH_NEXT
)
239 PUSHSQLERR (genv
->herr
, en_S1103
);
244 /*********************/
245 return SQL_NO_DATA_FOUND
;
254 SWORD cbInfoValueMax
,
255 SWORD FAR
* pcbInfoValue
)
257 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
259 STMT_t FAR
*pstmt
= NULL
;
262 RETCODE retcode
= SQL_SUCCESS
;
265 int size
= 0, len
= 0;
266 char buf
[16] = {'\0'};
268 if (hdbc
== SQL_NULL_HDBC
|| pdbc
->henv
== SQL_NULL_HENV
)
270 return SQL_INVALID_HANDLE
;
273 if (cbInfoValueMax
< 0)
275 PUSHSQLERR (pdbc
->herr
, en_S1090
);
280 if ( /* fInfoType < SQL_INFO_FIRST || */
281 (fInfoType
> SQL_INFO_LAST
282 && fInfoType
< SQL_INFO_DRIVER_START
))
284 PUSHSQLERR (pdbc
->herr
, en_S1096
);
289 if (fInfoType
== SQL_ODBC_VER
)
291 sprintf (buf
, "%02d.%02d",
292 (ODBCVER
) >> 8, 0x00FF & (ODBCVER
));
295 if (rgbInfoValue
!= NULL
296 && cbInfoValueMax
> 0)
300 if (len
< cbInfoValueMax
- 1)
302 len
= cbInfoValueMax
- 1;
303 PUSHSQLERR (pdbc
->herr
, en_01004
);
305 retcode
= SQL_SUCCESS_WITH_INFO
;
308 STRNCPY (rgbInfoValue
, buf
, len
);
309 ((char FAR
*) rgbInfoValue
)[len
] = '\0';
312 if (pcbInfoValue
!= NULL
)
314 *pcbInfoValue
= (SWORD
) len
;
320 if (pdbc
->state
== en_dbc_allocated
|| pdbc
->state
== en_dbc_needdata
)
322 PUSHSQLERR (pdbc
->herr
, en_08003
);
329 case SQL_DRIVER_HDBC
:
330 dword
= (DWORD
) (pdbc
->dhdbc
);
331 size
= sizeof (dword
);
334 case SQL_DRIVER_HENV
:
335 penv
= (ENV_t FAR
*) (pdbc
->henv
);
336 dword
= (DWORD
) (penv
->dhenv
);
337 size
= sizeof (dword
);
340 case SQL_DRIVER_HLIB
:
341 penv
= (ENV_t FAR
*) (pdbc
->henv
);
342 dword
= (DWORD
) (penv
->hdll
);
343 size
= sizeof (dword
);
346 case SQL_DRIVER_HSTMT
:
347 if (rgbInfoValue
!= NULL
)
349 pstmt
= *((STMT_t FAR
**) rgbInfoValue
);
352 for (tpstmt
= (STMT_t FAR
*) (pdbc
->hstmt
);
354 tpstmt
= tpstmt
->next
)
364 PUSHSQLERR (pdbc
->herr
, en_S1009
);
369 dword
= (DWORD
) (pstmt
->dhstmt
);
370 size
= sizeof (dword
);
379 if (rgbInfoValue
!= NULL
)
381 *((DWORD
*) rgbInfoValue
) = dword
;
384 if (pcbInfoValue
!= NULL
)
386 *(pcbInfoValue
) = (SWORD
) size
;
392 hproc
= _iodbcdm_getproc (hdbc
, en_GetInfo
);
394 if (hproc
== SQL_NULL_HPROC
)
396 PUSHSQLERR (pdbc
->herr
, en_IM001
);
401 CALL_DRIVER (hdbc
, retcode
, hproc
, en_GetInfo
,
402 (pdbc
->dhdbc
, fInfoType
, rgbInfoValue
, cbInfoValueMax
, pcbInfoValue
))
404 if (retcode
== SQL_ERROR
405 && fInfoType
== SQL_DRIVER_ODBC_VER
)
407 STRCPY (buf
, "01.00");
409 if (rgbInfoValue
!= NULL
410 && cbInfoValueMax
> 0)
414 if (len
< cbInfoValueMax
- 1)
416 len
= cbInfoValueMax
- 1;
417 PUSHSQLERR (pdbc
->herr
, en_01004
);
420 STRNCPY (rgbInfoValue
, buf
, len
);
421 ((char FAR
*) rgbInfoValue
)[len
] = '\0';
424 if (pcbInfoValue
!= NULL
)
426 *pcbInfoValue
= (SWORD
) len
;
429 /* what should we return in this case ???? */
440 UWORD FAR
* pfExists
)
442 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
446 if (hdbc
== SQL_NULL_HDBC
)
448 return SQL_INVALID_HANDLE
;
451 if (fFunc
> SQL_EXT_API_LAST
)
453 PUSHSQLERR (pdbc
->herr
, en_S1095
);
458 if (pdbc
->state
== en_dbc_allocated
459 || pdbc
->state
== en_dbc_needdata
)
461 PUSHSQLERR (pdbc
->herr
, en_S1010
);
466 if (pfExists
== NULL
)
471 hproc
= _iodbcdm_getproc (hdbc
, en_GetFunctions
);
473 if (hproc
!= SQL_NULL_HPROC
)
475 CALL_DRIVER (hdbc
, retcode
, hproc
, en_GetFunctions
,
476 (pdbc
->dhdbc
, fFunc
, pfExists
))
481 if (fFunc
== SQL_API_SQLSETPARAM
)
483 fFunc
= SQL_API_SQLBINDPARAMETER
;
486 if (fFunc
!= SQL_API_ALL_FUNCTIONS
)
488 hproc
= _iodbcdm_getproc (hdbc
, fFunc
);
490 if (hproc
== SQL_NULL_HPROC
)
492 *pfExists
= (UWORD
) 0;
496 *pfExists
= (UWORD
) 1;
502 for (fFunc
= 0; fFunc
< 100; fFunc
++)
504 hproc
= _iodbcdm_getproc (hdbc
, fFunc
);
506 if (hproc
== SQL_NULL_HPROC
)
508 pfExists
[fFunc
] = (UWORD
) 0;
512 pfExists
[fFunc
] = (UWORD
) 1;