Overview of Constraints
Constraints allow you to implement business rules in your application. These rules specify which data is allowed in the database and which is not. The aim of constraints is to check as early as possible that newly entered or changed data is valid, and to warn the user or correct the data if it is not.
You can write constraints that reject any data manipulation that violates your business rules. For instance, if a user attempts to set a hire date that is earlier than a date of birth for a particular employee, you can write a constraint to reject this input. This type of constraint is called a restrictive constraint.
If data entered by a user requires manipulation of other data, you can have a constraint do this automatically. For example, if the number of participants in a tour reservation changes, you can write a constraint to re-calculate the reservation price. This type of constraint is called a corrective constraint.
If data entered by a user requires external testing or additional functionality that is defined in a component, you can let a constraint call (invoke) this component, which then performs the appropriate action. For example, if a reservation is made, you can send the customer an e-mail message to confirm the reservation. This type of constraint is called an invocative constraint.
Not all business rules need to be dealt with by writing constraints. For example, allowed domain values or cascading delete actions correspond to business rules, but are best defined at domain and relationship level, not through constraints.
One of the strengths of the Rules Engine is that constraints are written in plain SQL. SQL is used to retrieve or manipulate any data in the database, so it is also the most logical means for defining constraints.
The USoft Rules Engine has been constructed in such a manner that SQL statements are parsed and processed as efficiently as possible. However, you MUST comply with your RDBMS vendor's SQL guidelines to provide your application with optimum performance.
The scope of each constraint is one of the following:
The Rules Engine also supports rules that rely on the transition between an old and a new value. An example of a transitional rule is "An amount cannot increase by more than 10% at a time".
You can use the OLD() function in your SQL to refer to the old value, or you can set transition properties for the constraint. If you use the OLD() function or set transition properties (or both), you turn the constraint into a transitional constraint.
Thus USoft Developer supports:
It is also possible to write constraints that must be evaluated at a particular time or on a specific date. These are called time constraints.
You must not use the ROWID pseudo column in constraints.