I tried a few more tests with Execute Block with Flamerobin and Lazarus.
What I tested is following codes. This works when run in FlameRobin ISQL (DSQL?) window.
SET term #;
EXECUTE BLOCK
AS
DECLARE i INT;
DECLARE lowend INT=10111;
DECLARE highend INT=10120;
BEGIN
i = lowend;
while (i <= highend) do BEGIN
UPDATE TEST SET Description= 'changed ' || CAST(:i AS VARCHAR(10))
WHERE Code=:i;
i = :i + 1;
END
END
#
SET term ;#
But, when moved to Pascal, it does not run. Following codes raise DataBase exception. This is strange.
with SQLQuery1 do begin
SQL.Clear;
// SQL.Add('set term #;');
SQL.Add('EXECUTE BLOCK');
SQL.Add('AS');
SQL.Add('declare i int;');
SQL.Add('declare lowend int=10111;');
SQL.Add('declare highend int=10120;');
SQL.Add('BEGIN');
SQL.Add('i = lowend;');
SQL.Add('while (i <= highend) do begin');
SQL.Add('update TEST set Description= ''changed '' || cast(:i as varchar(10))');
SQL.Add('where Code=:i;');
SQL.Add('i = :i + 1;');
SQL.Add('end');
SQL.Add('END');
// SQL.Add('#');
// SQL.Add('set term ; #');
Transaction.Active := True;
try
ExecSQL;
(Transaction as TSQLTransaction).Commit;
showmessage('succes');
except
(Transaction as TSQLTransaction).Rollback;
end;
showmessage('fail');
end;
Next, it says Firebird supports using parameters in following forms.
EXECUTE BLOCK (lowend INT=?, highend INT=?)
AS
DECLARE i INT;
BEGIN
i = lowend;
while (i <= highend) do BEGIN
UPDATE TEST SET Description= 'changed ' || CAST(:i AS VARCHAR(10))
WHERE Code=:i;
i = :i + 1;
END
END
In Lazarus, there are no way to set parameters here. Neither Params[0] nor parambyname work. It raises Lazarus exception.
Not sure of the usefulness of Execute Block in these forms, as regular operations may be defined as stored procedures.