4D v16

トリガー

ホーム

 
4D v16
トリガー

トリガー    


 

 



ビデオ中で説明されている操作に加え、以下の点にも留意してください。

データベースエンジンイベントを利用するにあたり、覚えておくべき重要な点がひとつあります。トリガーはデータベースエンジン上で呼び出し、実行されるということです。

  • シングルユーザーモードでは4D上でトリガーが実行されます。
  • クライアント/サーバーモードではサーバー上にデータがあり、クライアントに送信されます。この場合トリガーは4D Server上で実行されます。クライアントマシン上ではありません。
トリガーは連鎖して呼び出されることがあります。トリガー発生元となったアクションやカスケードレベルを知るためのコマンドがあります。

またトリガーを使用すればレコードに関する処理を受け入れたり拒否したりすることができます。

レコードを作成、更新、削除する方法には以下のように複数種類がありますが、トリガーを使用するとどの方法を使用したかに関わらず、データの整合性を保証することができます:

  • SQL
  • プラグイン
  • 入力
  • 読み込み
  • Web

トリガーを使用する際には以下の点に留意してください:

  • 素早く実行を終了させる
  • インターフェース要素を呼び出さない
  • エラーを発生させない (ディスクへのアクセスなど)

In this video, we're going to learn how to configure database events and how to take them into account in the programming.
A trigger (or table method) is used to check on actions performed by the database engine on data:

  • creation
  • modification
  • deletion.

In that sense, a trigger is a method like any other. It's simply the context in which it is executed that changes.

Like form events, database events must be checked so that 4D gives control to the trigger to execute.

We can enable any database event in the Table inspector.

You’ll find the “Edit” button at the bottom right, which allows creating the method to execute when the checked events occur.

The method is generally structured in the following manner:

 $evt:=Database event `What is the number of the event being executed by the database event?
 Case of
    :($evt=On Saving New Record Event`A new record is saved
 
    :($evt=On Saving Existing Record Event`An existing record is saved
 
    :($evt=On Deleting Record Event`A record is deleted
 
 End case

Unlike a form method that is only executed during a display (or print), a trigger is executed regardless of how you access records:

  • programming
  • import/export
  • SQL
  • Web
  • and so on.

The trigger has the advantage of being a mandatory passage point.

  • Let's add a Date_Last_Modified field to the Interventions table
  • We'll make it visible on the form
  • And assign a value to it whenever we save a record:

 [Interventions]Date_Last_Modified:=Current date

Of course, this latest modification will also be valid when creating a record.

Let's try it out by performing a modification:

  • If we change the intervention date
  • Then save it and come back here, the modification date has in fact been assigned a value
  • So the trigger works correctly.

 
 

 
プロパティ 

プロダクト: 4D
テーマ: トリガー

 
履歴 

 
ARTICLE USAGE

セルフトレーニング ( 4D v16)