Using constraints.wrm


wspec/constraints.wrm can be used to validate data in a .ace file while it is being loaded. The file contains standard query conditions for each Class. If the query fails, a message box appears with the warning "Object <object name> does not satisfy constraints", and the object is not loaded.

After changing constraints.wrm, it must be read into the database with "Read models" for the changes to take effect.

Any acedb query local to a single object is valid. Constructions involving FOLLOW or FINDing other objects are not.

Examples

Class Paper
Constraints "Year"
// Requires that the tag Year be present in all Paper objects.

Class Paper
Constraints "Year:1"
// Requires that the tag Year have a value in the first field. 
// (Note: In ace4_5 this syntax can be used in any query.)

Class Paper
Constraints "COUNT Author < 4"
// Refuses to load any Papers with more than three Authors.

Objects are merged before testing.

Constraints are applied to the complete object, not just the current record in the .ace file. If data for the same object are present in separate records in the .ace file, or are already present in the database, the constraint is applied to the merged object.

For example, if the constraint is

Class Colleague
Constraints "Mail:1"
and the database already contains
Colleague "Jean"
Mail "Montpellier"
, additional data can be loaded into Colleague "Jean" without including a Mail value.

Another example: if the constraint is

Class Paper
Constraints "COUNT Author < 4"
attempting to load a .ace file containing the records
Paper "Durbin-1997"
Author Richard
Author Jean
Author Simon

Paper "Durbin-1997"
Author Ian
will succeed for the first record and fail for the second. (Assuming there are no pre-existing Author data for this object in the database.)


Dave Matthews, matthews@greengenes.cit.cornell.edu, 6aug97