Re: [ESQL/C] Segmentation Fault on Prepare
Posted in 1993
From article <CF7DL3.Erz@walter.bellcore.com>, by johnd@leis.bellcore.com (John Droggitis): > This problem is driving me crazy! I'm getting a segmentation fault > on a prepare statement, for no apparent reason. Any help is greatly > appreciated. > > Platform: Sun IPX, ESQL/C 4.10.UE1, informix online 5.01.UC1. > > The code: A vanilla prepare statement, illustrated below (simplified): > > sprintf(prep_str, "SELECT fld1, fld2 FROM %s ORDER BY fld1", from_clause); > $prepare p1 from prep_str; /* Statement that segfaults */ > $declare c1 cursor for p1; Some things you might look at (in no particular order of obviousness): 1. That prep_str is big enough 2. That prep_str is a hostvar: A. $char prep_str[1024]; B. $prepare p1 from :prep_str; 3. Note that $prepare/$declare are only needed *once* static int prepared; if (! prepared) { $prepare...; $declare...; prepared++; } 4. Check sqlca after the $prepare and $declare for more information. This is the way I do them, and get good results... Andrew Shaw AT&T Bell Labs andrew.shaw@att.com shaw@apache.att.com