User Tools

Site Tools


lesson_6_trigger_properties.htm
Navigation:  User's Guide and Tutorials > The Dictionary > Dictionary Editor >====== Lesson 6 - Trigger Properties ====== Previous pageReturn to chapter overviewNext page

Overview

Triggers are a mechanism for providing Clarion language support during database operations on a selected table. This support is added in the data dictionary, so all applications that reference this table will automatically contain the built-in support.

Regarding SQL tables, the trigger support that is added here is considered to be Client-Side, and should not be confused with the server-side database triggers supported by many SQL engines.

The uses of dictionary triggers are limited only to the developer's imagination. For more information regarding the uses of dictionary triggers, review the Dictionary Triggers topic found in the core help. This section simply describes how a trigger is added and maintained in the data dictionary.

To add a dictionary trigger to a selected table:

1.In the DCT Explorer, double-click on the target table to open the Entity Browser.

2.In the Entity Browser, click on the Triggers folder, then press the Add button, or press the INSERT key. Alternatively, you can also right-click on the Triggers folder, and select Add Triggers from the popup menu.

3.In the Trigger Properties window, select from six different types of trigger entry points. Each name is self-explanatory:

Before Insert After Insert
Before Update After Update
Before Delete After Delete

After a trigger type is added, you cannot select it again for the same table.

4.You can add trigger Data variables to use with the trigger source. Press the Columns tab to access the Trigger Data dialog, and press the Add button to add your data elements.

These data elements are automatically included in the application's generated base class source file (Example: myappBC0.clw). They are only valid in the trigger type that they are created in, and are locally defined within the supporting trigger's derived method.

5.Enter your trigger source code in the General tab using the text control provided.

Example trigger source:

! After update trigger
IF ~ERRORCODE()
  !Log insert
  UPL:UpdRec = 'Pub ID: ('& PUB:PubID &')  was updated in Publisher on '&|
                FORMAT(TODAY(),@D1) &' at '&format(Clock(),@t3)
  ACCESS:UpdLog.Insert()
  ! Change record in child file ( 1 <;–> 1 relationship)
  PBI:PubID = PUB:PubID
  IF ~Access:Pub_Info.TryFetch(PBI:PubID_Key)
   !If record Change
   PBI:Pr_info = CLIP(PBI:Pr_Info)&amp;'<;13,10>Publisher '&amp;clip(PUB:Pub_name) &amp;|
   ' in '&amp; clip(PUB:City) &amp; ' was updated on '&amp;FORMAT(TODAY(),@d1)&amp;'.'
   Access:Pub_Info.Update()
  END
END
! End of trigger (After update)

Two functions are accomplished here. After a record has been updated, a log entry is automatically entered into another table defined in the dictionary. After the log update, a child table is also updated with appropriate information.

Although trigger source should be designed to be maintenance free, the source code that is entered can be modified in the Application Generator through the following Global embeds:

triggerembeds.jpg

Next: Lesson 7 - SQL, ODBC, and ADO Imports

lesson_6_trigger_properties.htm.txt · Last modified: 2021/04/15 15:57 by 127.0.0.1