RE: What Databases exist? use sqgetdbs()
Posted in 1994
Topics: Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL
Conversion: Prohibited Conversion-With-Loss: Prohibited Encoding: 57 TEXT Jonathan Leffler (johnl@informix.com) wrote: : >From: mltsa!jgill@mlgtw.att.com : >Date: Mon, 16 May 94 10:11:06 BST : >Subject: <No Subject Supplied> : >X-Informix-List-Id: <list.3957> : > : >is there a way of knowing whether or not a database exists? According to Informix here, there is a function called sqgetdbs() which takes 5 arguments and for On-line & SE database returns a list of database names that it finds present. The definiton of the function is as follows (I got this from a fax from the local Informix office months ago, so I guess its still valid, and I guess its ok to make it public): According to their docs the function sqgetdbs is as follows: int sqgetdbs(ret_cnt,fnames,fnsize,farea,fasize) int *ret_cnt; // Return databases found count char **fnames; // argv[] type array of db names (sorted) int fnsize; // number of entries in the fnames[] array char *farea; // pointer to area where names are stored int fasize; // size of farea The return code from sqgetdbs is 0 if it worked, Informix error code otherwise. The farea pointer is used as a base, and a null terminated list (one filename per string) is written into farea, fnames[] is an array of char * (similar in concept to argv[]), into which pointers into farea are returned, which will be sorted alphabetically on the database name. The names in farea are not sorted, they are in some chronological type order. To use this function you MUST link in the library librds.a as sqgetdbs calls several RDS utility routines (This was for ESQL/C version 4 & may not apply to later versions of ESQL/C). BASICALLY TO USE THIS FUNCTION:you supply farea as a block of storage, fasize is the size of this area (in bytes), you also need to supply fnames as a char * array (e.g. char *fnames[100]) fnsize is the number of entries that fnames can store (in this case 100), the retcnt is a pointer to a integer you also need to pass which will contain how many entries in fnames are present if the sqgetdbs function worked ok. You do not have to be connected to any database to use this function, if you call this function the database backend process will be started as it needs to communicate with the Online database to give you this information. For SE databases I am not sure if the backend is started or not. I have tested this function on both SE 4.1 and Online 5.01ud3 databases without problems. Hope this helps someone else, (I wondered for a long time how Isql and others got the list of databases they showed when you went Database Select), now you know too!.