From: johnl@informix.com (Jonathan Leffler) Newsgroups: comp.databases.informix Subject: Re: ESQL/C: List of databases Date: 1 Feb 1994 14:28:32 -0500 X-Informix-List-ID: >Date: Tue, 1 Feb 1994 16:29:37 +0100 (GMT+0100) >From: "Centr. Instytut Ochrony Pracy" >Subject: ESQL/C: List of databases >X-Informix-List-Id: > >Hi, >Is there a way of determinig the names of all created databases >from within an esql/c program? > >Pawel Pietrusinski >Centralny Instytut Ochrony Pracy >Warsaw, Poland, >cinsop@frodo.nask.org.pl The code below covers your requirements. It is packaged as a free-standing program, but won't take long to disembowel into some sort of function you can use. Note that this works regardless of which version of ESQL/C you have -- it includes routines which are occasionally missing from the ESQL/C libraries but which are needed to make this work. Yours, Jonathan Leffler (johnl@informix.com) #include : "%W% %E%" #!/bin/sh # shar: Shell Archiver (v1.22) # # This is a shell archive. # Remove everything above this line and run sh on the resulting file # If this archive is complete, you will see this message at the end # "All files extracted" # # Created: Tue Feb 1 10:49:41 1994 by johnl at Sphinx Ltd. # Files archived in this archive: # dbnames.ec # if test -f dbnames.ec; then echo "File dbnames.ec exists"; else echo "x - dbnames.ec" sed 's/^X//' << 'SHAR_EOF' > dbnames.ec && X/* X@(#)File: dbnames.ec X@(#)Version: 1.3 X@(#)Last changed: 93/07/19 X@(#)Purpose: Print list of visible databases X@(#)Author: John Cooke/Mark Jeske/Jonathan Leffler X*/ X X/* X********************************************************** X** This code is derived from two almost identical ** X** programs with the identifications preserved below: ** X********************************************************** X** dbnames.ec ** X** List all available database names. ** X** Mark J (Informix) 3-13-91 ** X********************************************************** X** From: johnc@obelix (John Cooke) ** X** Quite a coincidence .... I wrote THIS program: ** X** program to get the names of all visible databases ** X********************************************************** X** Compile using: ** X** esql -o dbnames dbnames.ec $INFORMIXDIR/lib/librds.a ** X********************************************************** X*/ X X#ifndef lint Xstatic char sccs[] = "@(#)dbnames.ec 1.3 93/07/19"; X#endif X X#include X X#define MAXDBS 100 X#define FASIZ (MAXDBS * 19) X Xmain(argc, argv) Xint argc; Xchar **argv; X{ X int ndbs; X int sqlcode; X int i; X char *dbsname[MAXDBS + 1]; X char dbsarea[FASIZ]; X X if ((sqlcode = sqgetdbs(&ndbs, dbsname, MAXDBS, dbsarea, FASIZ)) != 0) X { X fprintf(stderr, "%s: error code %d from sqgetdbs\n", argv[0], sqlcode); X exit(1); X } X else X { X for (i = 0; i < ndbs; ++i) X printf("%s\n", dbsname[i]); X } X X return (0); X} X X/* X** Routines compact and frmcmpr provided in e-mail from: X** Message-Id: <9209131735.AA01780@spsgate.sps.mot.com> X** From: uunet!hermes1.sps.mot.com!baskett (Bob Baskett) X** Date: Sun, 13 Sep 92 10:27:52 MST X*/ X Xcompact(frm, fcnt) Xchar **frm; Xint fcnt; X{ X register char **to; X register char **from; X register char *last = " "; X int same; X X from = to = frm; X while (fcnt-- > 0) X { X same = stcmpr(last, *from); X last = *from; X if (same != 0) X *to++ = *from++; X else X from++; X } X return(to - frm); X} X Xfrmcmpr(n1, n2) Xchar **n1; Xchar **n2; X{ X return(stcmpr(*n1, *n2)); X} SHAR_EOF chmod 0444 dbnames.ec || echo "$0: failed to restore dbnames.ec" fi echo All files extracted exit 0