Re: embedded SQL corrupting loops

From: GHouck <hksys_at_teleport.com>
Date: Mon, 12 Jul 1999 23:36:38 -0700
Message-ID: <378ADE76.2B51_at_teleport.com>


Dogan Cibiceli wrote:
>
> Hi,
> If this is in a function and you are calling it as function. Max will
> always be initiliazed to 0. However, the correct way is to assign max as
> the first
> element. For ex...
> if ( i == 0) // first iteration through the loop
> max = weeksago[i] ;
> else // maximum calculation bla bla...
>
> Dogan
>
> PS. If max is initiliazed to zero before entering into the loop,That is a
> whole lot different...
>
> shockerman_at_my-deja.com wrote:
>
> > I have a program that does this loop. If I run an embedded SQL command
> > after I have the number, the number gets corrupted and gets very large.
> > Here's the important parts of the program.
> >
> > char temp[4][15];
> > char temp1[4][15];
> > long int max=0;
> >
> > for (i=4; i>=0; i--)
> > {
> > EXEC SQL select count(*) into :weeksago[i]
> > from sorted
> > where rid=10992 AND
> > ddate between next_day(sysdate-:i*7, 'Sunday') AND next_day
> > (sysdate-(:i-1)*7, 'Saturday');
> >
> > if (weeksago[i] >= max)
> > max = weeksago[i];
> >
> > printf("<p>Max is %d\n", max);}
> >
> > EXEC SQL select next_day(sysdate-:i*7, 'Sunday') into :temp[i] from
> > dual;
> > EXEC SQL select next_day(sysdate-(:i-1)*7, 'Saturday') into :temp1[i]
> > from dual;
> > }
> >
> > The first iteration returns a correct max number because I initialized
> > max to 0. After that, Max goes to 1244475442 or some other large
> > number. If I comment out the SQL statements, max is calculated
> > perfectly all the way through. Even if I take the max part out of this
> > loop and give it its own loop before or after the SQL statement loop,
> > max still gets large when I need it later.
> > Someone please help with this. let me know if you need more info.

shockerman_at_my-deja.com wrote:

(the above Pro*C)

The problem is probably related to the index of your loop, which appears to go from 4 - 3 - 2 - 1 - 0, which will not index your 'temp' or 'temp1' arrays properly, which are dimensioned to only four (4) elements ... you need five (5). The SQL SELECTs into those two character arrays are probably wiping out "max", which may follow them in memory.

Yours,

Geoff Houck
systems hk
hksys_at_teleport.com
http://www.teleport.com/~hksys Received on Tue Jul 13 1999 - 08:36:38 CEST

Original text of this message