Re: Way to get list of all databases?
Posted in 1992
In article <1992Jul28.155440.29855@cbis.ece.drexel.edu> you write:
>
> Does someone know of a way (easy or not, but needs to be executeable
>from command line, not interactive) to return a list of all the available
>databases? Someone pointed out that we should probably be running
>'update statistics' on them each not, so tha tthe cost based optimizer
>will have accurate information.
Based on the sqgetdbs() call mentioned in another article, I put together
the following stand-alone C program that lists available databases.
It works with Informix 4.0, both SE and OnLine, and also with Informix*Net
(and I assume Informix*Star), so make sure your DBPATH doesn't include
remote hosts if you only want local databases.
Unfortunately, you need RDS or ESQL in order to compile because of
library routines required by "libsql.a". See the Makefile for details
on choosing the library for compilation.
This is unsupported, undocumented, and comes with no guarantees.
#! /bin/sh
# This is a shell archive. Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file". To overwrite existing
# files, type "sh file -c". You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g.. If this archive is complete, you
# will see the following message at the end:
# "End of shell archive."
# Contents: Makefile dbnames.c
# Wrapped by daves@techmpc on Wed Jul 29 14:23:41 1992
PATH=/bin:/usr/bin:/usr/ucb ; export PATHif test -f 'Makefile' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \\"'Makefile'\\"
else
echo shar: Extracting \\"'Makefile'\\" \\(426 characters\\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X#
X# The following symbols are not available in the sql library, nor in the
X# compiled C 4gl development package, either:
X#
X# frmcmpr
X# compact
X#
X# You need either the RDS or ESQL package in order to compile.
X#
X# RDS use: SPECIAL=rds
X#
X# ESQL-C use: SPECIAL=sace or SPECIAL=sperf (either is o.k.)
X#
X
XSPECIAL=rds
X
XLIBS = -L$(INFORMIXDIR)/lib -lsql -l$(SPECIAL)
X
Xdbnames : dbnames.o
X $(CC) $(CFLAGS) -o dbnames dbnames.o $(LIBS)
END_OF_FILE
if test 426 -ne `wc -c <'Makefile'`; then
echo shar: \\"'Makefile'\\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'dbnames.c' -a "${1}" != "-c" ; then
echo shar: Will not clobber existing file \\"'dbnames.c'\\"
else
echo shar: Extracting \\"'dbnames.c'\\" \\(683 characters\\)
sed "s/^X//" >'dbnames.c' <<'END_OF_FILE'
X#include <stdio.h>
X
X/* This is a short C program to print a list of available
X Informix databases to stdout. */
X
X#define MAXDBNAMES 256 /* you can change this */
X#define AREA 256
X
Xextern int sqgetdbs();
X
Xint main(argc, argv)
Xint argc;
Xchar **argv;
X{
X int ndb, sqlcode, i;
X char *fnames[MAXDBNAMES];
X char area[AREA];
X
X sqlcode = sqgetdbs(&ndb, fnames, MAXDBNAMES, area, AREA);
X if (sqlcode) {
X (void) fprintf(
X stderr, "%s: error code %d from sqgetdbs()\\n", *argv, sqlcode);
X exit(2);
X }
X for(i=0; i < ndb; i++) {
X if (printf("%s\\n", fnames[i])) {
X (void) fprintf(stderr, "%s: Error printing to stdout.", *argv);
X exit(2);
X }
X }
X return(0);
X}
END_OF_FILE
if test 683 -ne `wc -c <'dbnames.c'`; then
echo shar: \\"'dbnames.c'\\" unpacked with wrong size!
fi
# end of 'dbnames.c'
fi
echo shar: End of shell archive.
exit 0
--
David Schmitt, Database/Systems Administrator Voice: (708)632-5562
Cellular Subscriber Group MIS FAX: (708)632-4421
Motorola, Inc., Room S356 Email: daves@csg.gss.mot.com
1475 W. Shure Dr., Arlington Hts, IL 60004