Skip to main content

SqlComputeCode

Specifies code that sets the value of this property.

Usage

To specify how the property is computed, use the following syntax:

Property name As classname [ SqlComputeCode = { Set {FieldName} = Expression }, SqlComputed ];

Where:

  • FieldName — The SQL field name of the property being defined.

  • Expression — ObjectScript expression that specifies the value of the property.

Details

If this keyword is specified (and if SqlComputed is true), then this property is a computed property. See “Defining a Computed Property” in Using Caché Objects.

For the value of this keyword, specify (in curly braces) a line of ObjectScript code that sets the value of the property, according to the following rules:

  • To refer to this property, use {*}

    Or if the SqlFieldName keyword is not specified for the property, use {propertyname} where propertyname is the property name. If the SqlFieldName keyword is specified for the property, use {sqlfieldnamevalue} where sqlfieldnamevalue is the value of that keyword.

    Note that SqlFieldName is available for all object classes, although it is useful only for persistent classes.

    For further information on field names in ObjectScript code, see “Controlling the SQL Projection of Literal Properties” in the chapter “Defining and Using Literal Properties” in Using Caché Objects or see CREATE TRIGGER in the Caché SQL Reference.

  • Similarly, to refer to another property, if the SqlFieldName keyword is not specified for the property, use {propertyname} where propertyname is the property name. If the SqlFieldName keyword is specified for the property, use {sqlfieldnamevalue} where sqlfieldnamevalue is the value of that keyword.

  • The code can include multiple Set commands, if necessary. Blank spaces are permitted before or after the equal sign, though each entire Set statement must appear on a single line.

  • The code can refer to class methods, routines, or subroutines via the usual full syntax. Similarly, it can use ObjectScript functions and operators.

  • The code can include embedded SQL.

  • The code can include the following pseudo-field reference variables, which are translated into specific values at class compilation time:

    • {%%CLASSNAME} and {%%CLASSNAMEQ} both translate to the name of the class which projected the SQL table definition. {%%CLASSNAME} returns an unquoted string and {%%CLASSNAMEQ} returns a quoted string.

    • {%%TABLENAME} translates to the fully qualified name of the table, returned as a quoted string.

    • {%%ID} translates to the RowID name. This reference is useful when you do not know the name of the RowID field.

    These names are not case-sensitive.

  • The code cannot use syntax of the form ..propertyname or ..methodname()

For example:

Property TestProp As %String [ SqlComputeCode = {set {*} = {OtherField}}, SqlComputed ];

For another example:

Property FullName As %String [ SqlComputeCode = {set {*}={FirstName}_" "_{LastName}}, SqlComputed ];

The code is called with a Do command.

Important:
  • If you intend to index this field, use deterministic codeOpens in a new tab, rather than nondeterministic code. Caché cannot maintain an index on the results of nondeterministic code because it is not possible to reliably remove stale index key values. (Deterministic code returns the same value every time when passed the same arguments. So for example, code that returns $h is nondeterministic, because $h is modified outside of the control of the function.)

  • Any user variables used in the SqlComputeCode should be New'd before they are used. This prevents any conflict with variables of the same name elsewhere in related code.

Default

The default is an empty string.

See Also

FeedbackOpens in a new tab