Safety
A language can be classified as safe when for each program, it is possible for the compiler to decide whether one of the error situations might occur during execution:
- A type restriction defined in the schema is violated.
The query contains an obvious type violation:
SELECT a FROM a IN employee WHERE familymember = fleet;
|
- An undefined property of an object is referred to.
The attribute
account
is not defined for persons in general, but only for a subset of persons, namely employees:
SELECT account FROM person WHERE domicile IN ( SELECT headoffice FROM company );
|
A type violation will occur as soon as a person is found who is not an employee or a shareholder.
Determines all persons who are employees or managers and are over 50.
SELECT * FROM p IN person WHERE ( p IN employee OR p IN manager ) AND p.age > 50;
|
This form of query is much more compact than processing both subclasses separately.
- The query will not create a type violation because objects of a subclass are referenced by a variable of the type of one of its superclass.
- The reverse case, where objects of a superclass are referenced by a variable of the type of one of its subclasses, will in general result in a type violation.
This is due to the fact that properties defined solely for a subclass might now be accessed for an object which belongs to the superclass and not to the subclass.