Skip to main content

SqlComputeOnChange (Property Keyword)

This keyword controls when the property is recomputed. Applies only to triggered computed properties.

Usage

To specify when a property is recomputed, use the following syntax:

Property name As classname [ SqlComputed, SqlComputeCode=sqlcomputecode, SqlComputeOnChange = propertynames ];

Where:

  • sqlcomputecode specifies the code used the compute the property, as described in SqlComputeCode. If the compute code is defined in a PropertyComputation method instead, omit SqlComputeCode. For more details, see Computed Values.

  • propertynames is either a single property name or a comma-separated list of property names. This value can also include the values %%INSERT or %%UPDATE. Note that you must use the actual property names, rather than the values given by SqlFieldname.

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.)

This keyword controls the conditions under which this property is recomputed. Recomputation can result from:

  • The modification of any specified properties.

  • The occurrence of a triggering event.

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($HOROLOG,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.

See Also

FeedbackOpens in a new tab