To view the inserted objects, execute "SELECT * FROM Employee
" for example:
When you select from the class Employee
, the query returns objects from both Employee
and Manager
since Manager
is inheriting from Employee
. However, the result table does not include the properties specific to Manager
, e.g., Title
, because the attribute Title
is not visible from the class Employee
.
You can define SQL methods for classes. The syntax follows SQL PSM (Persistent Stored Module). For example, let us define an instance method Age()
that returns the age of an employee:
CREATE METHOD Age()
RETURNS INTEGER
FOR Employee
BEGIN
RETURN EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM SELF.BirthDate);
END;
Execute the statement in the SQL Query Analyzer window, and then try the next SELECT
query:
SELECT * FROM Employee emp WHERE emp.Age() > 40 ;
The Age()
method works for both Employee
and Manager
, of course. You can override the method for Manager
, and enjoy the polymorphic behavior just as you do with .NET.
Next Article
In this article, I showed a quick and brief introduction to SQL programming with Matisse, which shows object features like inheritance and relationships. In the following articles, I will show more details for each topic and discuss the technical advantages and disadvantages.
Comments