Re: embedded SQL corrupting loops

From: Dogan Cibiceli <dcib_at_gwl.com>
Date: Mon, 12 Jul 1999 19:14:52 -0600
Message-ID: <378A930C.B11EED9E_at_gwl.com>


Hi,
[Quoted]   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.
>
> Sent via Deja.com http://www.deja.com/
> Share what you know. Learn what you don't.
Received on Tue Jul 13 1999 - 03:14:52 CEST

Original text of this message