INVOKE: Example 1

Previous Next

Suppose, the SQL statement of a constraint has Syntax

INVOKE    component.method WITH
SELECT    output-list
FROM      table
WHERE     condition

This is a single-record constraint. The constraint is evaluated as a result of the user manipulating a specific record. The component is invoked only for this record, at the time the record is stored. The external component is therefore called at the time the record is stored (if at all).

First the WHERE clause is evaluated:

If there is no record that satisfies condition, there are no result records to be fed to the component. The component is not invoked.

If exactly one record satisfies condition, there is 1 SELECTed record to be fed to the component so the component is invoked once.

If multiple records satisfy condition, the component is invoked as many times as there are records in the query result. Each time, the value(s) in the output list of the individual record are passed to the component.

If the component ends up being called one or more times:

For each call, if the component method returns no value, the constraint does not raise a violation.

If the component method returns a value, the invocation must be associated with the query protocol, and the component will either return 1, 0, or -1. The Rules Engine interprets this as "row exists", "row does not exist" or "error". Notice that this is very much the same sort of test as the WHERE clause. In this example, two filters must be passed and the statement can be thought of as:

SELECT        output-list
FROM          table
WHERE         condition-X-evaluated-by-RDMBS
AND           condition-Y-evaluated-by-external-component

 

See also

When and how many times a component is invoked