4D v14

ビデオの内容

ホーム

 
4D v14
ビデオの内容

ビデオの内容  


 

 

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 v13)
セルフトレーニング ( 4D v14)