Re: Using sqgetdbs core dumps program
Posted in 2004
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
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/
I think I pretty much used that for Aubit4gls asql (like dbaccess) :
Extract :
#define MAXDBS 100
#define FASIZ (MAXDBS * 19)
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 <jleffler@earthlink.net> wrote in message news:<Dkc5c.21913$%06.17754@newsread2.news.pas.earthlink.net>... > 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 It appears that the problem is not necessarily my code, but the fact that I'm trying to access a remote database server. To eliminate my "connect" code, I created a simple test program that calls sqgetdbs, prints the database names returned by sqgetdbs, call sqgetdbs a second time and print the database names. The following code works fine if I have INFORMIXSERVER set to a local database server, but core dumps if I set INFORMIXSERVER to a remote database server: #include <stdio.h> #include <stdlib.h> #define BUFFSZ 256 #define NUM_DBNAMES 10 int main() { char db_buffer[BUFFSZ]; char *dbnames[NUM_DBNAMES]; int num_returned, ret, i; printf("\\nFirst call to sqgetdbs.\\n"); ret = sqgetdbs(&num_returned, dbnames, NUM_DBNAMES, db_buffer, BUFFSZ); if (ret < 0) { printf("Unable to obtain names of databases.\\n"); exit(1); } printf("Number of database names returned = %d\\n", num_returned); printf("Databases on current server:\\n"); for (i = 0; i < num_returned; i++) printf("\\t%s\\n", dbnames[i]); $disconnect all; printf("\\nSecond call to sqgetdbs.\\n"); ret = sqgetdbs(&num_returned, dbnames, NUM_DBNAMES, db_buffer, BUFFSZ); if (ret < 0) { printf("Unable to obtain names of databases.\\n"); exit(1); } printf("Number of database names returned = %d\\n", num_returned); printf("Databases on current server:\\n"); for (i = 0; i < num_returned; i++) printf("\\t%s\\n", dbnames[i]); printf("\\n"); return(0); } Examination of the core file stack trace yields: Stack Trace for p1, Program list_db *[0] _x_xti_bind(0x4, 0x3, 0, 0x80667e0) [0xbfe22e53] [1] _xti_bind(0x3, 0, 0x80667e0, 0, 0, 0x80667e0) [0xbff2b73f] [2] conntli(0x806fed0, 0x8047014, 0x80670b0) [0xbff2bb0c] [3] tlConnect(presumed: 0x80670b0, 0x8047014, 0x8063d08) [0xbff22ae5] [4] slSQIreq(presumed: 0x80670b0, 0x104, 0x8047014) [0xbff1f238] [5] pfConReq(presumed: 0x80670b0, 0x8067a2c, 0x804754c) [0xbff1a206] [6] cmReqSync(0x80670b0, 0x804754c, 0x8067a28, 0x4055b3c7, 0x50) [0xbff14b4a] [7] cmConReq(presumed: 0x80670b0, 0x804754c, 0xbff389dc) [0xbff12d41] [8] ascRequest(0x80670b0, 0x8067010, 0x8047548) [0xbff0a24b] [9] ASF_Call(0x80475a8, 0x8047548) [0xbff0c5eb] [10] asf_connect(0x8066988, 0, 0, 0x804bf30, 0) [0xbff49077] [11] _asf_dblist(0x8047968, 0x804796c, 0xa, 0x8047994, 0x100, 0x804bf30) [0xbff4b8b1] [12] sqgetdbs(0x8047968, 0x804796c, 0xa, 0x8047994, 0x100) [0xbff551ca] [13] main(0x1, 0x8047ab4, 0x8047abc) [list_db.c@list_db.ec@30] [14] _start() [0x80488ac] Any ideas??
snorris wrote: > > #define BUFFSZ 256 > #define NUM_DBNAMES 10 > > int > main() > { > char db_buffer[BUFFSZ]; > char *dbnames[NUM_DBNAMES]; > int num_returned, ret, i; > > printf("\\nFirst call to sqgetdbs.\\n"); > ret = sqgetdbs(&num_returned, dbnames, NUM_DBNAMES, db_buffer, > BUFFSZ); dbsnames should be (i think) NUM_DBNAMES+1 in size... Have you got >=10 remote databases but <10 local ones ?