All Manuals > LispWorks User Guide and Reference Manual > 19 Common SQL > 19.4 Object oriented interface > 19.4.2 Object-Oriented Data Definition Language (OODDL)

NextPrevUpTopContentsIndex

19.4.2.1 Example View Class definition

The following example shows a View Class corresponding to the traditional employees table, with the employee's department given by a join with the departments table. See def-view-class for a description of the slot options.

(def-view-class employee (standard-db-object)
   ((employee-number :db-kind :key 
                     :column empno 
                     :type integer)
    (employee-name :db-kind :base 
                   :column ename 
                   :type (string 20)
                   :accessor employee-name)
    (employee-department :db-kind :base 
                         :column deptno 
                         :type integer
                         :accessor employee-department)
    (employee-job :db-kind :base 
                  :column job 
                  :type (string 9))
    (employee-manager :db-kind :base 
                      :column mgr 
                      :type integer)
    (employee-location :db-kind :join
                       :db-info (:join-class department
                                 :retrieval :deferred
                                 :set nil
                                 :home-key employee-department
                                 :foreign-key department-number
                                 :target-slot department-loc)
                       :accessor employee-location))
                (:base-table emp))

The def-view-class macro allows elements or lists of elements to follow :home-key and :foreign-key . The elements can be symbols, nil , strings, integers or floats.

This syntax means that an object from the join class is only included in the join slot if the values from home-key are equal to the values in foreign-key , in order. These values are calculated as follows:

Note that some database vendors may have short maximum identifier lengths. The CLOS interface uses constructed alias names for tables in its SQL queries, and long table names or long class names may cause the constructed aliases to exceed the maximum identifier length for a particular vendor.


LispWorks User Guide and Reference Manual - 21 Dec 2011

NextPrevUpTopContentsIndex