Subject Re: [firebird-support] Re: something very strange going on here
Author Lucas Franzen
Martin,

> everything's fine; outside the debugger the procedure seems to somehow
> strangely enter an infinite loop (but of course I don't know where):

The infinite loop might be caused in the FOR BEGIN .. SUSPEND .. END
since if you don't have any record returned back you won't increment
your pos variable thus never reaching the exit, see below..


>
> CREATE PROCEDURE GET_20_DICENTRIES_BY_ASTERM (
> "TERM" varchar(240))
> returns (
> pos integer,
> id bigint)
> as
> declare variable asterm_try varchar(240) character set unicode_fss;
> declare variable asterm_temp varchar(240) character set unicode_fss;
> begin
> pos = 10;
> asterm_temp = :term;
> while (1 = 1) do
> begin

INIT the asterm_try to NULL.
If your select(max) doesn't return antyhing atermy_try won't be null, it
will be nothing (or when this is happening within a loop, it still wil
hold the last value)

asterm_try = NULL;

> select max(asterm) from dicentries where asterm < :asterm_temp
> into :asterm_try;

> if (:asterm_try is null) then

should read
if (asterm_try is null) then ...

Use colons when a variable is used for selecting into or within a DML
statement, in all other cases don't use the colon prefix
.

> break;
> for select id from dicentries where asterm = :asterm_try order
> by id descending into :id do
> begin
> suspend;
> pos = :pos - 1;
> if (:pos = 0) then

pos = pos - 1;
if (pos = 0) then

see above.

> break;
> end
> if (:pos = 0) then

if (pos = 0) then
and once more ...

> break;
> asterm_temp = :asterm_try;

asterm_temp = asterm_try;
and again...

> end
>
> pos = 11;
> for select id from dicentries where asterm = :term order by id
> ascending into :id do
> begin
> suspend;
> pos = :pos + 1;

pos = pos + 1;

> if (:pos = 20) then

if (pos = 20) then

> break;
> end
>
> asterm_temp = :term;

asterm_temp = term;

> while (1 = 1) do

Do you think this is a good idea?

> begin
> select min(asterm) from dicentries where asterm > :asterm_temp
> into :asterm_try;
> if (:asterm_try is null) then

if (asterm_try is null) then

> break;
> for select id from dicentries where asterm = :asterm_try order
> by id ascending into :id do
> begin
> suspend;
> pos = :pos + 1;
> if (:pos = 20) then

pos = pos + 1;
if (pos = 20) then

> break;
> end
> if (:pos = 20) then
> break;
> asterm_temp = :asterm_try;

if (pos = 20) then
break;
asterm_temp = asterm_try;


Are you sure you reach this point?

Having alook at your inital post you had data with NULL from outside
IBExpert, so it might be you don't have any records found.




Luc.