]>
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
);
197 glt??? pcbDSN = strlen(szDSN);
200 * And find the description that goes with this entry
202 _iodbcdm_getkeyvalbydsn (sect
[cur_entry
], strlen (sect
[cur_entry
]),
203 "Description", (char*) szDesc
, cbDescMax
);
205 glt??? pcbDesc = strlen(szDesc);
220 UCHAR FAR
* szDrvDesc
,
222 SWORD FAR
* pcbDrvDesc
,
223 UCHAR FAR
* szDrvAttr
,
225 SWORD FAR
* pcbDrvAttr
)
227 GENV_t FAR
*genv
= (GENV_t FAR
*) henv
;
229 if (henv
== SQL_NULL_HENV
)
231 return SQL_INVALID_HANDLE
;
234 if (cbDrvDescMax
< 0 || cbDrvAttrMax
< 0 || cbDrvAttrMax
== 1)
236 PUSHSQLERR (genv
->herr
, en_S1090
);
241 if (fDir
!= SQL_FETCH_FIRST
|| fDir
!= SQL_FETCH_NEXT
)
243 PUSHSQLERR (genv
->herr
, en_S1103
);
248 /*********************/
249 return SQL_NO_DATA_FOUND
;
258 SWORD cbInfoValueMax
,
259 SWORD FAR
* pcbInfoValue
)
261 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
263 STMT_t FAR
*pstmt
= NULL
;
266 RETCODE retcode
= SQL_SUCCESS
;
269 int size
= 0, len
= 0;
270 char buf
[16] = {'\0'};
272 if (hdbc
== SQL_NULL_HDBC
|| pdbc
->henv
== SQL_NULL_HENV
)
274 return SQL_INVALID_HANDLE
;
277 if (cbInfoValueMax
< 0)
279 PUSHSQLERR (pdbc
->herr
, en_S1090
);
284 if ( /* fInfoType < SQL_INFO_FIRST || */
285 (fInfoType
> SQL_INFO_LAST
286 && fInfoType
< SQL_INFO_DRIVER_START
))
288 PUSHSQLERR (pdbc
->herr
, en_S1096
);
293 if (fInfoType
== SQL_ODBC_VER
)
295 sprintf (buf
, "%02d.%02d",
296 (ODBCVER
) >> 8, 0x00FF & (ODBCVER
));
299 if (rgbInfoValue
!= NULL
300 && cbInfoValueMax
> 0)
304 if (len
< cbInfoValueMax
- 1)
306 len
= cbInfoValueMax
- 1;
307 PUSHSQLERR (pdbc
->herr
, en_01004
);
309 retcode
= SQL_SUCCESS_WITH_INFO
;
312 STRNCPY (rgbInfoValue
, buf
, len
);
313 ((char FAR
*) rgbInfoValue
)[len
] = '\0';
316 if (pcbInfoValue
!= NULL
)
318 *pcbInfoValue
= (SWORD
) len
;
324 if (pdbc
->state
== en_dbc_allocated
|| pdbc
->state
== en_dbc_needdata
)
326 PUSHSQLERR (pdbc
->herr
, en_08003
);
333 case SQL_DRIVER_HDBC
:
334 dword
= (DWORD
) (pdbc
->dhdbc
);
335 size
= sizeof (dword
);
338 case SQL_DRIVER_HENV
:
339 penv
= (ENV_t FAR
*) (pdbc
->henv
);
340 dword
= (DWORD
) (penv
->dhenv
);
341 size
= sizeof (dword
);
344 case SQL_DRIVER_HLIB
:
345 penv
= (ENV_t FAR
*) (pdbc
->henv
);
346 dword
= (DWORD
) (penv
->hdll
);
347 size
= sizeof (dword
);
350 case SQL_DRIVER_HSTMT
:
351 if (rgbInfoValue
!= NULL
)
353 pstmt
= *((STMT_t FAR
**) rgbInfoValue
);
356 for (tpstmt
= (STMT_t FAR
*) (pdbc
->hstmt
);
358 tpstmt
= tpstmt
->next
)
368 PUSHSQLERR (pdbc
->herr
, en_S1009
);
373 dword
= (DWORD
) (pstmt
->dhstmt
);
374 size
= sizeof (dword
);
383 if (rgbInfoValue
!= NULL
)
385 *((DWORD
*) rgbInfoValue
) = dword
;
388 if (pcbInfoValue
!= NULL
)
390 *(pcbInfoValue
) = (SWORD
) size
;
396 hproc
= _iodbcdm_getproc (hdbc
, en_GetInfo
);
398 if (hproc
== SQL_NULL_HPROC
)
400 PUSHSQLERR (pdbc
->herr
, en_IM001
);
405 CALL_DRIVER (hdbc
, retcode
, hproc
, en_GetInfo
,
406 (pdbc
->dhdbc
, fInfoType
, rgbInfoValue
, cbInfoValueMax
, pcbInfoValue
))
408 if (retcode
== SQL_ERROR
409 && fInfoType
== SQL_DRIVER_ODBC_VER
)
411 STRCPY (buf
, "01.00");
413 if (rgbInfoValue
!= NULL
414 && cbInfoValueMax
> 0)
418 if (len
< cbInfoValueMax
- 1)
420 len
= cbInfoValueMax
- 1;
421 PUSHSQLERR (pdbc
->herr
, en_01004
);
424 STRNCPY (rgbInfoValue
, buf
, len
);
425 ((char FAR
*) rgbInfoValue
)[len
] = '\0';
428 if (pcbInfoValue
!= NULL
)
430 *pcbInfoValue
= (SWORD
) len
;
433 /* what should we return in this case ???? */
444 UWORD FAR
* pfExists
)
446 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
450 if (hdbc
== SQL_NULL_HDBC
)
452 return SQL_INVALID_HANDLE
;
455 if (fFunc
> SQL_EXT_API_LAST
)
457 PUSHSQLERR (pdbc
->herr
, en_S1095
);
462 if (pdbc
->state
== en_dbc_allocated
463 || pdbc
->state
== en_dbc_needdata
)
465 PUSHSQLERR (pdbc
->herr
, en_S1010
);
470 if (pfExists
== NULL
)
475 hproc
= _iodbcdm_getproc (hdbc
, en_GetFunctions
);
477 if (hproc
!= SQL_NULL_HPROC
)
479 CALL_DRIVER (hdbc
, retcode
, hproc
, en_GetFunctions
,
480 (pdbc
->dhdbc
, fFunc
, pfExists
))
485 if (fFunc
== SQL_API_SQLSETPARAM
)
487 fFunc
= SQL_API_SQLBINDPARAMETER
;
490 if (fFunc
!= SQL_API_ALL_FUNCTIONS
)
492 hproc
= _iodbcdm_getproc (hdbc
, fFunc
);
494 if (hproc
== SQL_NULL_HPROC
)
496 *pfExists
= (UWORD
) 0;
500 *pfExists
= (UWORD
) 1;
506 for (fFunc
= 0; fFunc
< 100; fFunc
++)
508 hproc
= _iodbcdm_getproc (hdbc
, fFunc
);
510 if (hproc
== SQL_NULL_HPROC
)
512 pfExists
[fFunc
] = (UWORD
) 0;
516 pfExists
[fFunc
] = (UWORD
) 1;