Subject RE: [IBO] Parameterized "execute block" statement with IB_DSQL
Author Jason Wharton
Your syntax of the EXECUTE BLOCK statement is incorrect.
You need to actually give it input parameters that are then used to pass information from the outside to the inside of it.
 
Hope this helps!
 
Jason Wharton
www.ibobjects.com


From: IBObjects@yahoogroups.com [mailto:IBObjects@yahoogroups.com]
Sent: Wednesday, October 24, 2018 10:01 AM
To: IBObjects@yahoogroups.com
Subject: [IBO] Parameterized "execute block" statement with IB_DSQL

Hello,

am I wrong in the assumption, that a TIB_DSQL component could be used to execute a statement like this?

execute block
as
declare TempID int;
declare TempString varchar(10);
declare TempInteger integer;
begin
    select SETTING_VALUE from SETTINGS where (ID = 1) into :TempString;
    begin
        TempInteger = cast(TempString as integer);
        when any do TempInteger = 2;
    end
 
    for select ID from PENDING_UPDATES where (PARAM1 = :PARAM1) and (PARAM2 = :PARAM2) into :TempID do begin
        execute procedure SOME_PROCEDURE(:TempID, TempInteger, 'now');
    end
    delete from PENDING_UPDATES where (PARAM1 = :PARAM1) and (PARAM2 = :PARAM2);
end

When I try to assign the parameter values by either

IB_DSQL1.ParamByName('PARAM1').AsInteger := xxx;
IB_DSQL1.ParamByName('PARAM2').AsInteger := xxx;

or

IB_DSQL1.Params.Values['PARAM1'] := xxx;
IB_DSQL1.Params.Values['PARAM2'] := xxx;

I get an error message "Column unknown: PARAM1".

When I replace the :PARAM1 and :PARAM2 parts in the SQL statement directly by some values, it works.

Am I doing anything wrong?

Usually I use a TIB_Script for non-parameterized "execute block" statements, but in this case I need some parameters to pass in, so I thought TIB_DSQL is the way to go, because parameters seem to be supported by it, but somehow it doesn't work...