Subject Re: [firebird-support] Cicling fields
Author Ann W. Harrison
arnofab2000 wrote:
> Hi all.
>
> I have a table with 140 fieds.
> Named c1, c2.. c 140.
>
> c1..c140 are type integer
>
> Now I have to count some values into them.
>
> this is a code snippet:
> -- ******************************************
> cnt = 1; s0 = 0;
> while ( :cnt < 101 ) do begin
> if ( 'new.c' || :cnt = 0 ) then s0 = :s0 + 1;
> cnt = :cnt + 1;
> end
> -- ******************************************
>
> Firebird refuse this : 'new.c' || :cnt.
>
> So don't works.
>

That's right. Procedure parameters represent values, and
can not be used to build up names of columns or tables inside
the procedure. What you want is EXECUTE STATEMENT - where
you build the whole statement string. A running server keeps
compiled and optimized versions of procedures for performance.
It can't do that if it doesn't know which fields and tables
are referenced. EXECUTE STATEMENT requires parsing, compiling
and optimizing each time a statement is sent.


Good luck,

Ann