Re: Informix ESQL C Problems on AIX
Posted in 2000
Montgomery
Just a thought. Also make sure that you allocate char[n+1] in your ESQL/C code
for variables declared as char(n) in your database.
Sujit
mars1972@my-deja.com on 01/20/2000 01:16:05 PM
Please respond to mars1972@my-deja.com
To: informix-list@iiug.org
cc:
Subject: Re: Informix ESQL C Problems on AIX
In article <867m10$gfm$1@nnrp1.deja.com>,
montgomery@sysar.com wrote:
> Ok, I made a few modifications at your suggestion, specifically
> adding "while(sqlca.sqlcode == 0) {" in place of "for (;;) {" (I was
> checking the error codes internally anyways).
>
> As far as the "exec sql begin declare" stuff, I had one global one
> at the start of the program which both functions used. I instead made
> 2 separate begin delcare sections (one for each function) just in case
> there was some weird buffer overwrite problem.
>
> Also the fetch into stuff was taken care of by my cursor
> declaration. As I understand it something like:
> "EXEC SQL declare addressCursor cursor for
> SELECT dno_type, dno_city, dno_state, dno_line INTO
> :dbType, :dbCity, :dbState, :dbLine FROM
> informix.dnotes WHERE dno_loadno = :orderNum ORDER BY dno_line;"> will take care of inserting the variables into the right places
> automatically when a "EXEC SQL fetch addressCursor;" is called. So
> essentially the "exec sql prepare testStatement from <some sql>;"
> statement is unnecesary correct?
>
> Well at any rate it still doesn't work correctly. The first
> iteration brings back the correct information but on the second record
> retrieval it returns a no more records error. There must be something
> going on under the sheets in the APIs that I don't see. It must not
> like performing a select inside a select on the same data connection
to
> the database?
>
> Thanks for your assistance, any other ideas?
>
Hmmm.... I tried doing the exec sql declare for... statement and I
couldn't get it to compile. I've never seen anyone do that, but that
doesn't mean much. You may have a newer vesion of the compiler. All I
can tell you is how I'd do it.
Here's an example. I hope it's not more information than you're looking
for. You'll may some compile warnings because the size of some of the
variables is not know, but you can ignore those.
Func1(dno_loadno)
exec sql begin declare section;
string *dno_loadno; /* Declare passed value types. */
exec sql end declare section;
{
exec sql begin declare section;
string dno_type[20]; /* Define locals. */
string dno_city[35];
string dno_state[3];
string dno_line[20];
exec sql end declare section;
exec sql prepare testStatement from ' /* Prepare the statement*/
SELECT
dno_type,
dno_city,
dno_state,
dno_line
FROM
informix.dnotes
WHERE
dno_loadno = ? /* ? = put variable here */
ORDER BY /* when you call open using*/
dno_line';
if(sqlca.sqlcode != 0) {
Do some error stuff...
}
exec sql declare testCursor for testStatement;
if(sqlca.sqlcode != 0) {
Do some error stuff...
}
exec sql open testCursor using :dno_loadno;
/* Where dno_loadno is a variable you passed in */
/* dno_loadno will be put in where you had the ? in the */
/* prepare*/
if(sqlca.sqlcode != 0) {
Do some error stuff...
}
exec sql fetch next testCursor into /* Fetch record into vars*/
:dno_type,
:dno_city,
:dno_state,
:dno_line ;
while(sqlca.sqlcode == 0) {
Func2(dno_type, dno_city, dno_state, dno_line);
exec sql fetch next testCursor into /* Fetch next... */
:dno_type,
:dno_city,
:dno_state,
:dno_line ;
}
exec sql close testCursor;
exec sql free testCursor;
}
Func2(hv_type, hv_city, hv_state, hv_line)
exec sql begin declare section;
string *hv_type;
string *hv_city;
string *hv_state;
string *hv_line;
exec sql end declare section;
{
Do the same type of stuff as in Func1()...
}
--
# unrm /
ksh: unrm: not found
# man cpio
Sent via Deja.com http://www.deja.com/
Before you buy.