Subject strange problem in triggers with blob fields
Author
I have a very strange problem with the usage of blob fields in triggers.

It is hard to describe, so it would be better to give an example.

Here is a script for building up the metadata:

set term ^;

create table master
(master_id       integer not null
                 primary key,
 dummy           integer,
 blobfield       blob sub_type text)^

create table detail
(detail_id       integer not null
                 primary key,
 master_id       integer,
 dummy           integer,
 blobfield       blob sub_type text)^

alter table detail
add constraint detail_master_id foreign key (master_id) references master (master_id) on delete cascade^

create generator master_id^

create generator detail_id^

create or alter trigger master_ins_upd for master
before insert or update as
begin
if (coalesce (new.master_id, 0) = 0) then
   new.master_id = gen_id (master_id, 1);
new.blobfield = trim (new.blobfield);
end ^

create or alter trigger detail_ins_upd for detail
before insert or update as
begin
if (coalesce (new.detail_id, 0) = 0) then
   new.detail_id = gen_id (detail_id, 1);
new.blobfield = trim (new.blobfield);
end ^

create or alter trigger master_after_ins_upd for master
after insert or update as
begin
if (coalesce (new.blobfield, '') <> coalesce (old.blobfield, '')) then
   update detail
      set blobfield = new.blobfield
      where master_id = new.master_id;
end ^

create or alter trigger detail_after_ins_upd for detail
after insert or update as
begin
if (coalesce (new.blobfield, '') <> coalesce (old.blobfield, '')) then
   update master
      set blobfield = new.blobfield
      where master_id = new.master_id;
end ^

create or alter procedure test as

declare variable master_id integer;
declare variable detail_id integer;

begin
insert into master (dummy, blobfield)
values (1, 'test')
returning master_id into :master_id;
insert into detail (master_id, dummy, blobfield)
values (:master_id, 1, 'test')
returning detail_id into :detail_id;
update detail
   set dummy = 2
   where detail_id = :detail_id;
end^


After you built up the metadata, just execute the procedure tes by calling:

execute procedure test

Then you get the message:
BLOB not found.
At trigger 'DETAIL_AFTER_INS_UPD' line: 4, col: 1
At procedure 'TEST' line: 13, col: 1.

The problem is, that old.blobfield is not accessable any more in the after update trigger, when doing a trim of the blobfield in the before update trigger.
I can do
if (old.blobfield is null) then
I can do
if (old.blobfield is not null) then

but I cannot do
I can do
if (old.blobfield = '') then

When I remove the update statement in the procedure test and do it after the execution of the procedure test it works.

Could someone please tell me what's going wrong here?
Kind regards
Helmut