考虑以下脚本:
set term ^;
exit
^
execute block
as
begin
execute statement 'this will fail';
end
^
exit
完全有效,并且会导致脚本执行结束。至少在我正在测试它的IBExpert中。但我想以编程方式执行此操作。
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
^
我的第一个示例中的exit
是有效的Firebird还是IBExpert处理它本身?有条件地退出整个脚本有不同的方法吗?
答案 0 :(得分:2)
您在脚本中使用exit
时感到困惑,在Firebird语句中使用exit
(特别是execute block
)。脚本中的普通exit
被IBExpert解释为停止脚本的信号。
但是当exit
是execute block
的一部分时,它是不是脚本的一部分,它是发送到Firebird服务器执行的语句的一部分,它对脚本本身的执行没有影响。
execute block
语句中的代码是PSQL,其中EXIT
具有特定含义:
EXIT
语句导致执行过程或触发器从代码中的任何一点跳转到最终END
语句,从而终止程序。
此处,程序是程序(execute block
是匿名程序)或触发器。
换句话说,exit
中的execute block
导致execute block
的终止,仅此而已。
我不知道IBExpert是否支持更高级的脚本选项,但您可以查看从execute block
返回值并使用脚本中的条件退出(如果可以在IBExpert中使用)。另一个解决方案可能是execute block
中的raise an exception(假设IBExpert在错误时停止脚本)。