Re: HELP! ESQL program crashes
Posted in 1995
Questions, but they may lead to answers...
1. Was 5.02.UC1 ported for A.09.03 or was it for a later version of the
o/s? If for A.09.04, then the mismatch may be the cause of the
trouble. And are you referring to Informix-ESQL/C? There is no
5.02.UC1 Informix-SQL (4.15.UC1 is the highest pre-5 release, and
6.00.UE1 is the lowest poset-5 release, as of today).
2. You code is not checking any error statuses -- you don't make it clear
whether it is the DECLARE that goes wrong, though the comments imply
that.
3. You should not be looping on the FETCH with a for loop, unless you also
test for SQLNOTFOUND. If it is the DECLARE that is crashing, the OPEN
and FETCH are redundant and should be removed from the reproduction.
4. Your definition of main is wrong. ANSI C says you can use either of
two prototypes: int main(void) or "int main(int argc, char **argv)".
The comp.lang.c FAQ (and the new book derived from it) both give
reasons why you shouldn't abuse main().
5. Does the program work any better if you change the name of the cursor
from 'cursor' to something else?
6. I can think of no reason why _iqlocate() would be calling ungetc(). Do
you have the complete stack trace for the core dump? Did you compile
your code with debug enabled (-g?)?
Suggestion:
Add the following function to your test code before get_mtg_attendee():
#include <stdlib.h>
void sqlerror(void)
{
fprintf(stderr, "SQLCODE = %d", sqlca.sqlcode);
if (sqlca.sqlerrd[1] != 0)
fprintf(stderr, " (ISAM = %d)", sqlca.sqlerrd[1]);
fputc('\\n', stderr);
abort();
}
Also revise the get_mtg_attendee() function to include this whenever statement
before the $database statement.
EXEC SQL WHENEVER ERROR CALL sqlerror;
The code provided does not need sqltypes.h, sqlstype.h nor sqlda; in fact,
sqlca.h is included automatically by the generated C code, so you don't
need that header either.
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>
>From: bertelse@hp0.cs.uiuc.edu (bertelsen christophe)
>Date: 07 Dec 1995 07:52:51 GMT
>X-Informix-List-Id: <news.19515>
>
>We are having trouble getting the following program to work:
>
>/* -*-c-*- */
>#include <stdio.h>
>
>$include sqltypes.h;
>$include sqlstype.h;
>$include sqlca;
>$include sqlda;
>
>$define DATPATH "schedule";
>
>void get_mtg_attendee(void) {
> $char db_nam[9];
> $int id;
> int indx;
>
> $database DATPATH;
>/* The following declare statement causes a bus error. We've
> used $PREPARE to create a query id as well. The error seems
> to be occurring in _ungetc which is being called by the
> informix function _iqlocate. */
> $DECLARE cursor CURSOR FOR
> SELECT m_id,
> m_user
> INTO $id,
> $db_nam
> FROM meeting
> ;>
> EXEC SQL
> OPEN cursor;
>
> for(indx = 0; indx < 10; indx++)
> EXEC SQL
> FETCH cursor;
>}
>
>void main(void)
>{
>
> get_mtg_attendee();
>}
>
>Version INFORMIX-SQL Version 5.02.UC1 on HP-UX hp0 A.09.03 A 9000/755.