2017-12-20 15 views
1

別の列が更新されたときに、列を更新するためにfirebird 2.5でトリガーを作成しようとしています。私は、私の試みのための簡単なテーブルの例を作成しました。AFTER UPDATEトリガーで読み取り専用列エラーの更新を試みました

create tablea (estado char(1), fl_previa_laudo char(1)); 

そして、私のトリガーこのようなものです:

create trigger ATUALIZA_PREVIA_AI for TABLEA 
active after update position 0 
as 
begin 

if(old.estado in ('3', '4', '7', '8')) then 
    new.fl_previa_laudo = 'T'; 
else 
    new.fl_previa_laudo = 'F'; 
end; 

そして、私はトリガーを実行すると、エラーを与える:

can't format message 13:849 -- message file C:\Windows\firebird.msg not found. attempted update of read-only column.

答えて

1

あなたはAFTER UPDATEトリガーで列を変更しようとしていますしかし、それは不可能です。値を変更する場合は、BEFORE UPDATEトリガーを使用する必要があります。具体的には(強調鉱山)、Firebird documentation on triggersに参照:

The NEW and OLD variables are subject to some rules:

  • In all triggers, the OLD value is read-only
  • In BEFORE UPDATE and BEFORE INSERT code, the NEW value is read/write, unless it is a COMPUTED BY column
  • In INSERT triggers, references to the OLD variables are invalid and will throw an exception
  • In DELETE triggers, references to the NEW variables are invalid and will throw an exception
  • In all AFTER trigger code, the NEW variables are read-only

言い換えれば、行は、あなたができるように、永続化されたafter updateトリガが起動した後ながらbefore updateトリガが、行が永続化される前に、値を変更することを可能にします決定的な値を参照してください。

+0

これは機能します。ありがとうたくさんの男! –

+0

@diegopereira私の答えがあなたの問題を解決する助けとなったら、「承諾」ボタン(チェックマーク)をクリックして回答を「受け入れてください」。 –

関連する問題