invantive documentationpart of invantive cloud
Invantive Support ForumsLog In / Sign Up

Attribute Rule

An attribute rule is a business rule of one table, kept as a row in the repository and generated into the business layer. It either checks a condition and raises an error when the condition is not met, or performs an action. The attribute rules of a table are listed under the table as "Attribute Rules".

Kinds of Rule

A rule is described by three indicators:

  • The event says when the rule applies: on insert (I), update (U), delete (D), insert and update (M) or all events (A).
  • The action says what it does: an error check (E) or an action (A).
  • The moment says when an action runs: before the row is written (B) or after it (A).

An error check runs after the row has been written, against the row as it then stands. An action before the change can still change the values of the row; an action after the change sees the row as it was written.

Condition and Action

The condition is an expression that must be true for the row to be valid, such as :new.date_end is null or :new.date_end >= :new.date_start. The action is a statement that is executed, such as an assignment to a column. Both refer to the row with these names:

  • :new holds the values after the change.
  • :old holds the values before the change.
  • :last holds the values as they will be written; an assignment to :last changes the row.
  • :event holds the event, I, U or D.

A condition may contain a subquery, such as exists (...), to check other rows. Because the condition is also used to report existing rows that violate it, it must be valid both as a SQL condition and as a procedural expression.

Message

An error check carries a user message, written as a resource code with up to five parameters. The message is translated into the language of the user when the error is raised. The code of the rule identifies the rule in the message.

Rules Written in a Hook

A rule that does not fit one condition is written in the hook package of the table. Such a rule is still recorded as an attribute rule with "Create" switched off, so that its code and message are documented in the repository.

Release Notes