Re: Multiple SQLDA in a module Not Working
Posted in 1998
Robert Ogren <rmogren@gte.net> offerred: +Hello, +I have an application that is using the sqlda structures for getting +data out of the database. +The problem I am running into is this. See below + +All works okay in the getTable1 function. I get these values in the +daptr. +$41 = {sqld = 48, sqlvar = 0x8c274, desc_name = "\\000\\b''", '\\000' +<repeats 14 times>, desc_occ = 0, desc_next = 0x0} + +But in getTable2 +$5 = {sqld = 8, sqlvar = 0x8c2a4, desc_name = "\\000\\b\\234 +\\000\\000\\000\\000\\000\\b'P\\000\\000\\000\\000\\000\\000", desc_occ = 0, +desc_next = 0x0} +I only get 8 columns when I should have 62. + +Is there an unwritten rule where one can only use the sqlda once in a +program? +void getTable1() + EXEC SQL BEGIN DECLARE SECTION; + char cmd[SYNBUFSIZE]; + char ttime[5]; + char tdate[11]; + int records; + EXEC SQL END DECLARE SECTION; + + char selargs[SYNBUFSIZE]; +sqlda *daptr; +struct sqlvar_struct *colptr; + omcBSC *ptrBSC; + +/* other stuff snipped */ + + + sprintf(selargs," FROM cell_statistics WHERE date_val='%s' AND +time_val='%s'",tdate,ttime); + (void )infGetColumns(BSC,&selargs); /* build list of columns to get +*/ + strcpy(cmd,selargs); + + + EXEC SQL PREPARE bscobj from :cmd; + EXEC SQL DESCRIBE bscobj into daptr; + + EXEC SQL DECLARE bCurs cursor for bscobj; + + EXEC SQL OPEN bCurs; + + EXEC SQL FETCH bCurs USING DESCRIPTOR daptr; When you use DESCRIBE in this way, no memory is allocated to receive the values fetched. You must programatically go through the sqlda->sqlvar list and set sqldata to point to an existing buffer or allocate an appropriate amount of space and point sqldata to it. Based on the code fragment you included, you don't seem to be doing this anywhere. If that is the case, then the fact that your fetch worked at all in any case is entirely accidental. You are munging data in memory somewhere (sqldata should be considered uninitialized when it comes back from the describe). Typical coding would be: // after the describe for (i=0; i<daptr->sqld; i++) { // may have to reinterpret sqllen if data type is datetime, interval daptr->sqlvar[i].sqldata = malloc(daptr->sqlvar[i].sqllen); } If you want to use indicators, you should also allocate space for daptr->sqlvar[i].sqlidata. Dave ** Dave Kosenko <davek@summitdata.com> ** Director of Training Services (732) 469-4070 ** Summit Data Group (an Informix Authorized Education Center) ** Find my advice useful? Let me teach you everything I know about ** Informix. Sign up for OFFICIAL Informix training at SDG. ** For details, see http://www.summitdata.com/training