This file is indexed.

/usr/share/doc/cl-sql/html/def-view-class.html is in cl-sql 6.5.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>DEF-VIEW-CLASS</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1" /><link rel="home" href="index.html" title="CLSQL Users' Guide" /><link rel="up" href="ref-ooddl.html" title="Object Oriented Data Definition Language (OODDL)" /><link rel="prev" href="create-view-from-class.html" title="CREATE-VIEW-FROM-CLASS" /><link rel="next" href="drop-view-from-class.html" title="DROP-VIEW-FROM-CLASS" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">DEF-VIEW-CLASS</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="create-view-from-class.html">Prev</a> </td><th width="60%" align="center">Object Oriented Data Definition Language (OODDL)</th><td width="20%" align="right"> <a accesskey="n" href="drop-view-from-class.html">Next</a></td></tr></table><hr /></div><div class="refentry"><a id="def-view-class"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>DEF-VIEW-CLASS — Defines CLOS classes with mapping to SQL database.<strong>Macro</strong></p></div><div class="refsect1"><a id="idp62774512"></a><h2>Syntax</h2><pre class="synopsis">
      <code class="function">def-view-class</code> <em class="replaceable"><code>name</code></em> <em class="replaceable"><code>superclasses</code></em> <em class="replaceable"><code>slots</code></em> &amp;rest <em class="replaceable"><code>class-options</code></em> =&gt; <span class="returnvalue">class</span></pre></div><div class="refsect1"><a id="idp62778928"></a><h2>Arguments and Values</h2><div class="variablelist"><dl class="variablelist"><dt><span class="term"><em class="parameter"><code>name</code></em></span></dt><dd><p>
	      The class name.
	    </p></dd><dt><span class="term"><em class="parameter"><code>superclasses</code></em></span></dt><dd><p>
	      The superclasses for the defined class.
	    </p></dd><dt><span class="term"><em class="parameter"><code>slots</code></em></span></dt><dd><p>
	      The class slot definitions.
	    </p></dd><dt><span class="term"><em class="parameter"><code>class options</code></em></span></dt><dd><p>
	      The class options.
	    </p></dd><dt><span class="term"><em class="parameter"><code>class</code></em></span></dt><dd><p>
	      The defined class.
	    </p></dd></dl></div></div><div class="refsect1"><a id="idp62791216"></a><h2>Slot Options</h2><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
	    <em class="parameter"><code>:db-kind</code></em> - specifies the kind of
	    database mapping which is performed for this slot and
	    defaults to <em class="parameter"><code>:base</code></em> which indicates
	    that the slot maps to an ordinary column of the database
	    table. A <em class="parameter"><code>:db-kind</code></em> value of
	    <em class="parameter"><code>:key</code></em> indicates that this slot is a
	    special kind of <em class="parameter"><code>:base</code></em> slot which
	    maps onto a column which is one of the unique keys for the
	    database table, the value <em class="parameter"><code>:join</code></em>
	    indicates this slot represents a join onto another
	    <a class="glossterm" href="glossary.html#gloss-view-class"><em class="glossterm">View Class</em></a>
	    which contains View Class objects, and the value
	    <em class="parameter"><code>:virtual</code></em> indicates a standard CLOS
	    slot which does not map onto columns of the database
	    table.
	  </p></li><li class="listitem"><p>
	    <em class="parameter"><code>:db-info</code></em> - if a slot is specified
	    with <em class="parameter"><code>:db-kind</code></em>
	    <em class="parameter"><code>:join</code></em>, the slot option
	    <em class="parameter"><code>:db-info</code></em> contains a property list
	    which specifies the nature of the join. The valid members
	    of the list are:
	  </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: circle; "><li class="listitem"><p>
		<em class="parameter"><code>:join-class</code></em>
		<span class="emphasis"><em>class-name</em></span> - the name of the
		class to join on.
	      </p></li><li class="listitem"><p>
		<em class="parameter"><code>:home-key</code></em>
		<span class="emphasis"><em>slot-name</em></span> - the name of the slot
		of this class for joining
	      </p></li><li class="listitem"><p>
		<em class="parameter"><code>:foreign-key</code></em>
		<span class="emphasis"><em>slot-name</em></span> - the name of the slot
		of the <em class="parameter"><code>:join-class</code></em> for joining
	      </p></li><li class="listitem"><p>
		<em class="parameter"><code>:target-slot</code></em>
		<span class="emphasis"><em>target-slot</em></span> - this is an optional
		parameter. If specified, then the join slot of the
		defining class will contain instances of this target
		slot rather than of the join class. This can be useful
		when the <em class="parameter"><code>:join-class</code></em> is an
		intermediate class in a
		<span class="emphasis"><em>many-to-many</em></span> relationship and the
		application is actually interested in the
		<em class="parameter"><code>:target-slot</code></em>.
	      </p></li><li class="listitem"><p>
		<em class="parameter"><code>:retrieval</code></em>
		<span class="emphasis"><em>time</em></span> - The default value is
		<em class="parameter"><code>:deferred</code></em>, which defers filling
		this slot until the value is accessed. The other valid
		value is <em class="parameter"><code>:immediate</code></em> which
		performs the SQL query when the instance of the class
		is created. In this case, the
		<em class="parameter"><code>:set</code></em> is automatically set to
		<code class="constant">NIL</code>
	      </p></li><li class="listitem"><p>
		<em class="parameter"><code>:set</code></em> <span class="emphasis"><em>set</em></span> -
		This controls what is stored in the join slot.  The
		default value is <code class="constant">T</code>. When <span class="emphasis"><em>set</em></span> is
		<code class="constant">T</code> and <span class="emphasis"><em>target-slot</em></span> is undefined,
		the join slot will contain a list of instances of the
		join class. Whereas, if
		<span class="emphasis"><em>target-slot</em></span> is defined, then the
		join slot will contain a list of pairs of
		<span class="emphasis"><em>(target-value join-instance)</em></span>.
		When <span class="emphasis"><em>set</em></span> is <code class="constant">NIL</code>, the join slot
		will contain a single instances.
	      </p></li></ul></div></li><li class="listitem"><p>
	    <em class="parameter"><code>:type</code></em> - for slots of
	    <em class="parameter"><code>:db-kind</code></em> <em class="parameter"><code>:base</code></em> or
	    <em class="parameter"><code>:key</code></em>, the <em class="parameter"><code>:type</code></em> slot
	    option has a special interpretation such that Lisp
	    types, such as string, integer and float are
	    automatically converted into appropriate SQL types for
	    the column onto which the slot maps. This behaviour may
	    be overridden using the <em class="parameter"><code>:db-type</code></em> slot
	    option. The valid values are:
	    </p><table border="0" summary="Simple list" class="simplelist"><tr><td>
		<em class="parameter"><code>string</code></em> - a variable length
		character field up to <a class="link" href="default-string-length.html" title="*DEFAULT-STRING-LENGTH*">*default-string-length*</a>
		characters.
	      </td></tr><tr><td>
		<em class="parameter"><code>(string n)</code></em> - a fixed length
		character field <em class="parameter"><code>n</code></em> characters
		long.
	      </td></tr><tr><td>
		<em class="parameter"><code>varchar</code></em> - a variable length
		character field up to <a class="link" href="default-string-length.html" title="*DEFAULT-STRING-LENGTH*">*default-string-length*</a>
		characters.
	      </td></tr><tr><td>
		<em class="parameter"><code>(varchar n)</code></em> - a variable length
		character field up to <em class="parameter"><code>n</code></em>
		characters in length.
	      </td></tr><tr><td>
		<em class="parameter"><code>char</code></em> - a single character field
	      </td></tr><tr><td><em class="parameter"><code>integer</code></em> - signed integer
	      at least 32-bits wide</td></tr><tr><td><em class="parameter"><code>(integer n)</code></em></td></tr><tr><td><em class="parameter"><code>float</code></em></td></tr><tr><td><em class="parameter"><code>(float n)</code></em></td></tr><tr><td><em class="parameter"><code>long-float</code></em></td></tr><tr><td><em class="parameter"><code>number</code></em></td></tr><tr><td><em class="parameter"><code>(number n)</code></em></td></tr><tr><td><em class="parameter"><code>(number n p)</code></em></td></tr><tr><td>
		<em class="parameter"><code>tinyint</code></em> - An integer column 8-bits
		wide. [not supported by all database backends]
	      </td></tr><tr><td>
		<em class="parameter"><code>smallint</code></em> - An integer column 16-bits
		wide. [not supported by all database backends]
	      </td></tr><tr><td>
		<em class="parameter"><code>bigint</code></em> - An integer column
		64-bits wide. [not supported by all database backends]
	      </td></tr><tr><td>
		<em class="parameter"><code>universal-time</code></em> - an integer
		field sufficiently wide to store a
		universal-time. On most databases, a slot of this
		type assigned a SQL type of
		<em class="parameter"><code>BIGINT</code></em>
	      </td></tr><tr><td>
		<em class="parameter"><code>wall-time</code></em> - a slot which stores
		a date and time in a SQL timestamp column. <span class="application"><span class="emphasis"><em>CLSQL</em></span></span>
		provides a number of time manipulation functions to
		support objects of type <span class="type">wall-time</span>.
	      </td></tr><tr><td>
		<em class="parameter"><code>date</code></em> - a slot which stores the
		date (without any time of day resolution) in a
                column. <span class="application"><span class="emphasis"><em>CLSQL</em></span></span> provides a number of time
		manipulation functions that operate on date values.
	      </td></tr><tr><td>
		<em class="parameter"><code>duration</code></em> - stores a
		<span class="type">duration</span> structure.  <span class="application"><span class="emphasis"><em>CLSQL</em></span></span> provides
		routines for <span class="type">wall-time</span> and
		<span class="type">duration</span> processing.
	      </td></tr><tr><td><em class="parameter"><code>boolean</code></em> - stores a <code class="constant">T</code> or
	      <code class="constant">NIL</code> value.</td></tr><tr><td>
		<em class="parameter"><code>generalized-boolean</code></em> - similar
		to a <em class="parameter"><code>boolean</code></em> in that either a
		<code class="constant">T</code> or <code class="constant">NIL</code> value is stored in the SQL
		database. However, any Lisp object can be stored in
		the Lisp object. A Lisp value of <code class="constant">NIL</code> is stored as
		<code class="constant">FALSE</code> in the database, any
		other Lisp value is stored as
		<code class="constant">TRUE</code>.
	      </td></tr><tr><td>
		<em class="parameter"><code>keyword</code></em> - stores a keyword
	      </td></tr><tr><td><em class="parameter"><code>symbol</code></em> - stores a symbol</td></tr><tr><td>
		<em class="parameter"><code>list</code></em> - stores a list by writing
		it to a string. The items in the list must be able to
		be readable written.
	      </td></tr><tr><td><em class="parameter"><code>vector</code></em> - stores a vector
	      similarly to <em class="parameter"><code>list</code></em></td></tr><tr><td><em class="parameter"><code>array</code></em> - stores a array
	      similarly to <em class="parameter"><code>list</code></em></td></tr></table><p>
	  </p></li><li class="listitem"><p>
	    <em class="parameter"><code>:column</code></em> - specifies the name of
	    the SQL column which the slot maps onto, if
	    <em class="parameter"><code>:db-kind</code></em> is not
	    <em class="parameter"><code>:virtual</code></em>, and defaults to the
	    slot name. If the slot name is used for the SQL column
	    name, any hypens in the slot name are converted
	    to underscore characters.
	  </p></li><li class="listitem"><p>
	    <em class="parameter"><code>:void-value</code></em> - specifies the value
	    to store in the Lisp instance if the SQL value is NULL and
	    defaults to NIL.
	  </p></li><li class="listitem"><p>
	    <em class="parameter"><code>:db-constraints</code></em> - is a keyword
	    symbol representing an SQL column constraint expression or
	    a list of such symbols. The following column constraints
	    are supported: <span class="symbol">:not-null</span>,
	    <span class="symbol">:primary-key</span>, <span class="symbol">:unique</span>,
	    <span class="symbol">:unsigned</span> (<span class="application">MySQL</span> specific),
	    <span class="symbol">:zerofill</span> (<span class="application">MySQL</span> specific) and
	    <span class="symbol">:auto-increment</span> (<span class="application">MySQL</span> specific).
	  </p></li><li class="listitem"><p>
	    <em class="parameter"><code>:db-type</code></em> - a string to specify the SQL
	    column type. If specified, this string overrides the SQL
	    column type as computed from the <em class="parameter"><code>:type</code></em>
	    slot value.
	  </p></li><li class="listitem"><p>
	    <em class="parameter"><code>:db-reader</code></em> - If a string, then when
	    reading values from the database, the string will be used
	    for a format string, with the only value being the value
	    from the database.  The resulting string will be used as
	    the slot value.  If a function then it will take one
	    argument, the value from the database, and return the
	    value that should be put into the slot. If a symbol, then
	    the symbol-function of the symbol will be used.
          </p></li><li class="listitem"><p>
	    <em class="parameter"><code>:db-writer</code></em> - If a string, then when
	    reading values from the slot for the database, the string
	    will be used for a format string, with the only value
	    being the value of the slot.  The resulting string will be
	    used as the column value in the database.  If a function
	    then it will take one argument, the value of the slot, and
	    return the value that should be put into the database. If
	    a symbol, then the symbol-function of the symbol will be
	    used.
          </p></li></ul></div></div><div class="refsect1"><a id="idp59270496"></a><h2>Class Options</h2><p>
	</p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p>
	      <em class="parameter"><code>:base-table</code></em> - specifies the name
	      of the SQL database table. The default value is the
	      class name. Like slot names, hypens in the class name
	      are converted to underscore characters.
	    </p></li><li class="listitem"><p>
	      <em class="parameter"><code>:normalizedp</code></em> - specifies whether
          this class uses normalized inheritance from parent classes.
          Defaults to nil, i.e. non-normalized schemas. When true,
          SQL database tables that map to this class and parent
          classes are joined on their primary keys to get the full
          set of database columns for this class.  This means that 
          the primary key of the base class will be copied to all 
          subclasses as we insert so that all parent classes of an 
          instance will have the same value in their primary key slots
          (see tests/ds-nodes.lisp and oodml.lisp)
	    </p></li></ul></div><p>
      </p></div><div class="refsect1"><a id="idp59276304"></a><h2>Description</h2><p>
	Creates a <a class="glossterm" href="glossary.html#gloss-view-class"><em class="glossterm">View
	Class</em></a> called <em class="parameter"><code>name</code></em> whose
	slots <em class="parameter"><code>slots</code></em> can map onto the attributes
	of a table in a database. If
	<em class="parameter"><code>superclasses</code></em> is <code class="constant">NIL</code> then the
	superclass of <em class="parameter"><code>class</code></em> will be
	<em class="parameter"><code>standard-db-object</code></em>, otherwise
	<em class="parameter"><code>superclasses</code></em> is a list of superclasses
	for <em class="parameter"><code>class</code></em> which must include
	<em class="parameter"><code>standard-db-object</code></em> or a descendent of
	this class.
      </p><div class="refsect2"><a id="idp59284432"></a><h3>Normalized inheritance schemas</h3><p>
    Specifying that <span class="symbol">:normalizedp</span> is <span class="symbol">T</span>
    tells <span class="application"><span class="emphasis"><em>CLSQL</em></span></span> to normalize the database schema for inheritance.
    What this means is shown in the examples below.
      </p><p>
    With <span class="symbol">:normalizedp</span> equal to <span class="symbol">NIL</span>
    (the default) the class inheritance would result in the following:
      </p><pre class="screen">
(def-view-class node ()
  ((title :accessor title :initarg :title :type (varchar 240))))

SQL table NODE:
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| TITLE | varchar(240) | YES  |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+

(def-view-class user (node)
  ((user-id :accessor user-id :initarg :user-id
            :type integer :db-kind :key :db-constraints (:not-null))
   (nick :accessor nick :initarg :nick :type (varchar 64))))

SQL table USER:
+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| USER_ID | int(11)      | NO   | PRI |         |       |
| NICK    | varchar(64)  | YES  |     | NULL    |       |
| TITLE   | varchar(240) | YES  |     | NULL    |       |
+---------+--------------+------+-----+---------+-------+
      </pre><p>
    Using <span class="symbol">:normalizedp</span> <span class="symbol">T</span>, both
    view-classes need a primary key to join them on:
      </p><pre class="screen">
(def-view-class node ()
  ((node-id :accessor node-id :initarg :node-id
            :type integer :db-kind :key
            :db-constraints (:not-null))
   (title :accessor title :initarg :title :type (varchar 240))))

SQL table NODE:
+---------+--------------+------+-----+---------+-------+
| Field   | Type         | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| NODE_ID | int(11)      | NO   | PRI |         |       |
| TITLE   | varchar(240) | YES  |     | NULL    |       |
+---------+--------------+------+-----+---------+-------+

(def-view-class user (node)
  ((user-id :accessor user-id :initarg :user-id
            :type integer :db-kind :key :db-constraints (:not-null))
   (nick :accessor nick :initarg :nick :type (varchar 64)))
  (:normalizedp t))

SQL table USER:
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| USER_ID | int(11)     | NO   | PRI |         |       |
| NICK    | varchar(64) | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
      </pre><p>
        In this second case, all slots of the view-class 'node
        are also available in view-class 'user, and can be used
        as one would expect. For example, with the above normalized
        view-classes 'node and 'user, and SQL tracing turned on:
      </p><pre class="screen">
CLSQL&gt; (setq test-user (make-instance 'user :node-id 1 :nick "test-user"
                                            :title "This is a test user"))
#&lt;USER {1003B392E1}&gt;

CLSQL&gt; (update-records-from-instance test-user :database db)

;; .. =&gt; INSERT INTO NODE (NODE_ID,TITLE) VALUES (1,'This is a test user')
;; .. &lt;= T
;; .. =&gt; INSERT INTO USER (USER_ID,NICK) VALUES (1,'test-user')
;; .. &lt;= T
1


CLSQL&gt; (node-id test-user)
1

CLSQL&gt; (title test-user)
"This is a test user"

CLSQL&gt; (nick test-user)
"test-user"
      </pre><p>
        Notes from a refactor of this code.

        There are many assumptions that need to be met for normalized classes to work

        * The each of the classes should have its own single key column (of a different name)
          that will contain an identical value.  EG: node has a node-id, setting which
          is a node has a node-id and a setting-id which must be equal.  You cannot use
          node-id as the primary key on both tables (as I would have expected).  The exception
          to this seems to be if your class has no slots at all, then you dont need to have a
          single key column, because your class is fully represented in the db by its parent(s)

        * more than one parent class per normalized class should be considered experimental
          and untested (vaya con Dios)

        * There are a few code paths that just dont pay any attention to normalized classes
          eg: delete-records-for-instance

      </p></div></div><div class="refsect1"><a id="idp59297424"></a><h2>Examples</h2><p>
	The following examples are from the <span class="application"><span class="emphasis"><em>CLSQL</em></span></span> test suite.
      </p><pre class="screen">
(def-view-class person (thing)
  ((height :db-kind :base :accessor height :type float
           :initarg :height)
   (married :db-kind :base :accessor married :type boolean
            :initarg :married)
   (birthday :type clsql:wall-time :initarg :birthday)
   (bd-utime :type clsql:universal-time :initarg :bd-utime)
   (hobby :db-kind :virtual :initarg :hobby :initform nil)))

(def-view-class employee (person)
  ((emplid
    :db-kind :key
    :db-constraints :not-null
    :type integer
    :initarg :emplid)
   (groupid
    :db-kind :key
    :db-constraints :not-null
    :type integer
    :initarg :groupid)
   (first-name
    :accessor first-name
    :type (varchar 30)
    :initarg :first-name)
   (last-name
    :accessor last-name
    :type (varchar 30)
    :initarg :last-name)
   (email
    :accessor employee-email
    :type (varchar 100)
    :initarg :email)
   (ecompanyid
    :type integer
    :initarg :companyid)
   (company
    :accessor employee-company
    :db-kind :join
    :db-info (:join-class company
			  :home-key ecompanyid
			  :foreign-key companyid
			  :set nil))
   (managerid
    :type integer
    :initarg :managerid)
   (manager
    :accessor employee-manager
    :db-kind :join
    :db-info (:join-class employee
			  :home-key managerid
			  :foreign-key emplid
			  :set nil))
   (addresses
    :accessor employee-addresses
    :db-kind :join
    :db-info (:join-class employee-address
			  :home-key emplid
			  :foreign-key aemplid
			  :target-slot address
			  :set t)))
  (:base-table employee))

(def-view-class company ()
  ((companyid
    :db-kind :key
    :db-constraints :not-null
    :type integer
    :initarg :companyid)
   (groupid
    :db-kind :key
    :db-constraints :not-null
    :type integer
    :initarg :groupid)
   (name
    :type (varchar 100)
    :initarg :name)
   (presidentid
    :type integer
    :initarg :presidentid)
   (president
    :reader president
    :db-kind :join
    :db-info (:join-class employee
			  :home-key presidentid
			  :foreign-key emplid
			  :set nil))
   (employees
    :reader company-employees
    :db-kind :join
    :db-info (:join-class employee
			  :home-key (companyid groupid)
			  :foreign-key (ecompanyid groupid)
			  :set t))))

(def-view-class address ()
  ((addressid
    :db-kind :key
    :db-constraints :not-null
    :type integer
    :initarg :addressid)
   (street-number
    :type integer
    :initarg :street-number)
   (street-name
    :type (varchar 30)
    :void-value ""
    :initarg :street-name)
   (city
    :column "city_field"
    :void-value "no city"
    :type (varchar 30)
    :initarg :city)
   (postal-code
    :column zip
    :type integer
    :void-value 0
    :initarg :postal-code))
  (:base-table addr))

;; many employees can reside at many addressess
(def-view-class employee-address ()
  ((aemplid :type integer :initarg :emplid)
   (aaddressid :type integer :initarg :addressid)
   (verified :type boolean :initarg :verified)
   (address :db-kind :join
	    :db-info (:join-class address
				  :home-key aaddressid
				  :foreign-key addressid
				  :retrieval :immediate)))
  (:base-table "ea_join"))

(def-view-class deferred-employee-address ()
  ((aemplid :type integer :initarg :emplid)
   (aaddressid :type integer :initarg :addressid)
   (verified :type boolean :initarg :verified)
   (address :db-kind :join
	    :db-info (:join-class address
				  :home-key aaddressid
				  :foreign-key addressid
				  :retrieval :deferred
				  :set nil)))
  (:base-table "ea_join"))
      </pre></div><div class="refsect1"><a id="idp59303856"></a><h2>Side Effects</h2><p>Creates a new CLOS class.</p></div><div class="refsect1"><a id="idp59305216"></a><h2>Affected by</h2><p>
	Nothing.
      </p></div><div class="refsect1"><a id="idp59306560"></a><h2>Exceptional Situations</h2><p>
	None.
      </p></div><div class="refsect1"><a id="idp59307904"></a><h2>See Also</h2><p>
	</p><table border="0" summary="Simple list" class="simplelist"><tr><td><a class="link" href="create-view-from-class.html" title="CREATE-VIEW-FROM-CLASS"><code class="function">create-view-from-class</code></a></td></tr><tr><td><a class="link" href="standard-db-object.html" title="STANDARD-DB-OBJECT"><em class="parameter"><code>standard-db-object</code></em></a></td></tr><tr><td><a class="link" href="drop-view-from-class.html" title="DROP-VIEW-FROM-CLASS"><code class="function">drop-view-from-class</code></a></td></tr></table><p>
      </p></div><div class="refsect1"><a id="idp59313712"></a><h2>Notes</h2><p>
	The actual SQL type for a column depends up the database type
	in which the SQL table is stored. As an example, the view
	class type <em class="parameter"><code>(varchar 100)</code></em> specifies a
	SQL column type <em class="parameter"><code>VARCHAR(100)</code></em> in <span class="application">MySQL</span>
	and a column type <em class="parameter"><code>VARCHAR2(100)</code></em> in
	<span class="application">Oracle</span>
      </p><p>
	The actual lisp type for a slot may be different than the
	value specified by the <em class="parameter"><code>:type</code></em> attribute.
	For example, a slot declared with "<em class="parameter"><code>:type (string
	30)</code></em>" actually sets the slots Lisp type as
	<em class="parameter"><code>(or null string)</code></em>. This is to allow a
	<code class="constant">NIL</code> value or a string shorter than 30 characters to be
	stored in the slot.
      </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="create-view-from-class.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ref-ooddl.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="drop-view-from-class.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">CREATE-VIEW-FROM-CLASS </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> DROP-VIEW-FROM-CLASS</td></tr></table></div></body></html>