[All]
Error when running isql script: -Token unknown - line 4, char 2 -when
Abstract: Error when running isql script: -Token unknown - line 4, char 2 -when
Problem:
When I try to run the isql script below, I get the following error:
Statement failed, SQLCODE = -104
Dynamic SQL Error
-SQL error code = -104
-Token unknown - line 4, char 2
-when
***************************************************************************************************
create database 'c:inprogresscall_20454test.gdb' user 'SYSDBA'
password 'masterkey';
connect 'c:inprogresscall_20454test.gdb';
create table T1(col_1 int, col_2 char(10), col_3 varchar(25));
create table T2(col_1 int not null unique, col_2 char(10), col_3
varchar(25));
create exception expt_1 'LOSER!';
commit;
set term !!;
create trigger my_trig for T1 active before insert
as
begin
when any do exception expt_1;
insert into T2(col_1, col_2, col_3)
values(new.col_1, new.col_2, new.col_3);
end !!
set term ;!!
Solution:
The information in this article applies to:
** InterBase 4.x
** InterBase 5.x
According to the 5.5 Language Reference, page 179, if you use the WHEN...DO
statement, it must be the last statement in the BEGIN...END block. It should come
after SUSPEND, if present. This information was not explicitly stated in the 4.0
documents, although the example shows the correct usage.