Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Property with SqlComputed and SqlComputeCode, but not Calculated or SqlComputeOnChange

Question
Timothy Leavitt · Feb 9, 2016

Property with SqlComputed and SqlComputeCode, but not Calculated or SqlComputeOnChange

Looking at a property defined as follows:

Property SystemTime As %Library.TimeStamp [ SqlComputeCode = {Set {*}=$ZDATETIME($NOW(),3,1,0)}, SqlComputed ];

The documentation talks about using SqlComputed and SqlComputeCode with SqlComputeOnChange (specifying which events will trigger computation), and about using them with the Calculated keyword (so it's always computed). I don't see any specific explanation of the case above, though, when neither SqlComputeOnChange nor Calculated is specified.

From a bit of testing, it seems that the behavior is:

  • Upon SQL insert or first %Save, if no value has been specified explicitly for such a property, the SqlComputeCode is run to provide an initial value. (In an SQL insert, null is treated as an explicitly-specified value; in Objects, explicitly setting the property to "" is not.)
  • Otherwise, the SqlComputeCode is never invoked automatically.

Is there anything I'm missing?

#Object Data Model #ObjectScript #SQL #Caché

Source URL:https://community.intersystems.com/post/property-sqlcomputed-and-sqlcomputecode-not-calculated-or-sqlcomputeonchange