Consider the following script:
set term ^;
exit
^
execute block
as
begin
execute statement 'this will fail';
end
^
The exit is perfectly valid and does cause script execution to end. At least in IBExpert where I am testing this. But I want to do this programmatically.
set term ^;
execute block
as
begin
if (exists(select 1 from sometable where somevalue = 1)) then begin
-- This only exits the block, not the script
exit;
end
end
^
execute block
as
begin
execute statement 'this will fail';
end
^
Is the exit in my first example valid Firebird or is IBExpert handling this itself? Is there a different way to exit the entire script conditionally?
You are confusing the use of
exitin your script, with usingexitinside Firebird statements (specifically theexecute block). The plainexitin your script is interpreted by IBExpert as a signal to stop the script.However when
exitis part of anexecute block, it is not part of your script, it is part of a statement that is sent to Firebird server for execution, and it does not have effect on the execution of the script itself.The code in an
execute blockstatement is PSQL, whereEXIThas a specific meaning:Here, program is the procedure (an
execute blockis an anonymous procedure) or trigger.In other words, an
exitwithin anexecute blockcauses termination of thatexecute block, nothing more.I don't know if IBExpert supports more advanced scripting options, but you could look at returning a value from the
execute blockand use a condition in your script to exit (if that is possible in IBExpert). Another solution might be to raise an exception within theexecute block(this assumes IBExpert stops the script on errors).