This keyword controls when the property is recomputed. Applies only to triggered computed properties.
Details
This keyword applies only to triggered computed properties; it is ignored for other properties. (A triggered computed property is a property for which SqlComputed is true and SqlComputeCode is specified, but for which Calculated and Transient are both false. See Defining a Computed Property in Defining and Using Classes.)
This keyword controls the conditions under which this property is recomputed. Recomputation can result from:
If the keyword has a value of %%INSERT or %%UPDATE, then INSERT or UPDATE calls, respectively, specify event-triggered computation of the value of the field (property).
-
With %%INSERT, InterSystems IRIS computes the field value when a row is inserted into the table. InterSystems IRIS invokes the code specified in the SQLComputeCode keyword to set the value. If SQLComputeCode uses the same field as an input value, then InterSystems IRIS uses the value explicitly provided for that field; if no value is given, InterSystems IRIS uses the InitialExpression (if this is specified) or null (if InitialExpression is not specified).
-
With %%UPDATE, InterSystems IRIS computes the field value when a row is inserted into the table and recomputes it when a row is updated. In both cases, InterSystems IRIS invokes the code specified in the SQLComputeCode keyword to set the value. If SQLComputeCode uses the same field as an input value, then InterSystems IRIS uses the value explicitly provided for that field; if no value is given, InterSystems IRIS uses the previous field value.
Any event-triggered computation occurs immediately before validation and normalization (which themselves are followed by writing the value to the database).
In this example, property LastUpdate is updated with the current date and time when a row is inserted or updated:
Property LastUpdate As %TimeStamp [ SqlComputeCode = {set {*}=$ZDATETIME($NOW(),3)}, SqlComputed, SqlComputeOnChange = (%%INSERT, %%UPDATE) ];
Note:
Event-triggered computation of a field’s value may override any explicitly specified value for the property, depending on the code that computes the property’s value.
Default
The default value for the SqlComputeOnChange keyword is an empty string.