Re: Using sqgetdbs core dumps program
Posted in 2004
Mike Aubury wrote:
> I think I pretty much used that for Aubit4gls asql (like dbaccess) :
>
>
> Extract :
>
> #define MAXDBS 100
> #define FASIZ (MAXDBS * 19)
Beware: database names can be up to 128 characters, and server names
can be up to 128 characters, so an individual dbase@server can require
(2*128+2) characters. Obviously, if none of your server names are
128 characters, you can trim that allowance; if none of your database
names are 128 characters, you can trim that too (and you'll be normal
and sane, to boot). Given 1900 characters, in a worst case, you'd
only be able to list the first 7 databases. I don't regard that as a
serious probability or problem - but beware what long identifiers mean
in IDS 9.20 and above.
> int ndbs;
> char *dbsname[MAXDBS+1];
> char dbsarea[FASIZ];
> sqlca.sqlcode = sqgetdbs(&ndbs, dbsname, MAXDBS, dbsarea, FASIZ);
>
>
>
> I then go on to select the db from that list, copy it out into another
> variable :
>
> let lv_newname=prompt_pick("SELECT DATABASE >>","")
>
>
> Then select the db:
>
> whenever error continue
> close database
> database lv_newname
> whenever error stop
>
>
> for full source look at :
>
> http://cvs.sourceforge.net/viewcvs.py/aubit4gl/aubit4glsrc/tools/asql/infx.4gl?rev=1.23&view=auto
>
> (It's the select_db function...)
>
>
> One thing to note is the mix of 4GL and C in that code - which is allowed in
> Aubit4GL by using the :
>
> code
> .
> .
> endcode
>
> syntax - this just passes that code through intact in the output ready for
> the C compiler...
>
>
>
> Jonathan Leffler wrote:
>
>
>>snorris wrote:
>>
>>
>>>I'm attempting to use sqgetdbs() in an ESQL/C program to allow users
>>>to select a database and then connect to the selected database. The
>>>database name list is returned successfully by sqgetdbs(). However, I
>>>can't seem to figure out how to execute a "connect" to the selected
>>>database. All methods that I've tried result in the program core
>>>dumping. The core dump appears to be in one of the Informix
>>>libraries, making it difficult to determine why the program core
>>>dumped.
>>
>>Have you printed out the data returned by sqgetdbs()?
>>Have you printed out the database name returned by the 'select' step
>>of your code? Are you sure you're passing the same value to the
>>connect statement?
>>
>>
>>>Does anyone have some example code that uses sqgetdbs() and then
>>>connects to one of the databases listed in the returned database name
>>>list?
>>
>>I'm pretty sure the FAQ and/or the IIUG Softwre Archive has examples -
>>SQLCMD has an 'info databases' command that uses that function.
>>
>>
>>>My environment is: Unixware7.1.X, ESQL/C 7.25 and SE 7.25
>>
>>
>
--
Jonathan Leffler #include <disclaimer.h>
Email: jleffler@earthlink.net, jleffler@us.ibm.com
Guardian of DBD::Informix v2003.04 -- http://dbi.perl.org/