2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
4 <!ENTITY % myents SYSTEM "entities.inc">
8 <!-- Object Oriented Data Manipulation Language -->
9 <reference id="ref-oodml">
10 <title>Object Oriented Data Manipulation Language (OODML)</title>
13 Object Oriented Data Manipulation Language (OODML) provides a Common Lisp
14 Object System (CLOS) interface to SQL databases. View classes are defined with
15 the <link linkend="ref-ooddl">OODDL</link> interface and objects are read and
16 written with the OODML.
19 The main function for reading data with the OODML is the <link
20 linkend="select"><function>select</function></link>
21 function. The <function>select</function> is also used in the
22 FDML. However, when <function>select</function> is given a view
23 class name, it returns a list of instances of view classes.
26 View class instances can be updated to reflect any changes in
27 the database with the functions <link
28 linkend="update-slot-from-record"><function>update-slot-from-record</function></link>
30 linkend="update-instance-from-records"><function>update-instance-from-records</function></link>.
32 <para>To update the database to reflect changes made to instances of view classes, use the functions <link
33 linkend="update-records-from-instance"><function>update-records-from-instance</function></link>,
35 linkend="update-record-from-slot"><function>update-record-from-slot</function></link>, and
37 linkend="update-record-from-slots"><function>update-record-from-slots</function></link>.
41 linkend="delete-instance-records"><function>delete-instance-records</function></link>
42 deletes the records corresponding to an instance of a view
47 <refentry id="db-auto-sync">
49 <refname>*DB-AUTO-SYNC*</refname>
50 <refpurpose>Enables SQL storage during Lisp object creation.</refpurpose>
51 <refclass>Variable</refclass>
54 <title>Value Type</title>
60 <title>Initial Value</title>
64 <title>Description</title>
66 When this variable is &t; an instance is stored in the SQL
67 database when the instance is created by
68 <function>make-instance</function>. When this variable is
69 &nil;, which is the default value, &clsql; behaves like
70 &commonsql;: instances of view classes are stored to the SQL
71 database only when <link
72 linkend="update-record-from-slots"><function>update-record-from-slots</function></link>
77 <title>Examples</title>
79 (let ((instance (make-instance 'foo)))
80 (update-record-from-slots instance))
84 (let ((*db-auto-sync* t))
89 <title>Affected By</title>
93 <title>See Also</title>
95 <member><link linkend="update-record-from-slots"><function>update-record-from-slots</function></link></member>
104 <refentry id="default-update-objects-max-len">
106 <refname>*DEFAULT-UPDATE-OBJECTS-MAX-LEN*</refname>
107 <refpurpose>The default maximum number of objects each query to perform a join</refpurpose>
108 <refclass>Variable</refclass>
111 <title>Value Type</title>
117 <title>Initial Value</title>
121 <title>Description</title>
123 This special variable provides the default value for the
124 <parameter>max-len</parameter> argument of the function <link
125 linkend="update-object-joins"><function>update-object-joins</function></link>.
129 <title>Examples</title>
131 (setq *default-update-objects-max-len* 100)
135 <title>Affected By</title>
139 <title>See Also</title>
141 <member><link linkend="update-object-joins"><function>update-object-joins</function></link></member>
150 <refentry id="delete-instance-records">
152 <refname>DELETE-INSTANCE-RECORDS</refname>
153 <refpurpose>Delete SQL records represented by a view class
155 <refclass>Function</refclass>
158 <title>Syntax</title>
160 <function>(delete-instance-records object)</function> => <returnvalue><!-- result --></returnvalue></synopsis>
163 <title>Arguments and Values</title>
166 <term><parameter>object</parameter></term>
169 An instance of a view class.
176 <title>Description</title>
177 <para>Deletes the records represented by
178 <parameter>object</parameter> in the appropriate table of the
179 database associated with <parameter>object</parameter>. If
180 <parameter>object</parameter> is not yet associated with a
181 database, an error is signalled.
185 <title>Examples</title>
187 * (def-view-class tab () ((a :type integer :db-kind :key) (b :type string)))
188 #<clsql-sys::db-standard-class tab>
189 * (defvar obj (let ((*db-auto-sync* t))
190 (make-instance 'tab :a 5 :b "the string")))
191 * (start-sql-recording :type :both)
192 * (delete-instance-records obj)
196 <title>Side Effects</title>
198 Deletes data from the SQL database.
202 <title>Affected by</title>
204 Permissions granted by the SQL database to the user in the database connection.
208 <title>Exceptional Situations</title>
210 An exception may be signaled if the database connection user does not have
211 sufficient privileges to modify the database.
215 <title>See Also</title>
218 <member><link linkend="update-records"><function>update-records</function></link></member>
219 <member><link linkend="update-records-from-instance"><function>update-records-from-instance</function></link></member>
226 Instances are referenced in the database by values stored in the key slots. If
227 <function>delete-records-from-instance</function> is called with an instance of a class that does
228 not contain any keys, then all records in that table will be deleted.
233 <refentry id="instance-refreshed">
235 <refname>INSTANCE-REFRESHED</refname>
236 <refpurpose>User hook to call on object refresh.</refpurpose>
237 <refclass>Generic function</refclass>
240 <title>Syntax</title>
242 <function>(instance-refreshed object)</function> => <returnvalue><!-- result --></returnvalue></synopsis>
245 <title>Arguments and Values</title>
248 <term><parameter>object</parameter></term>
251 The view class object which is being refreshed.
258 <title>Description</title>
259 <para>Provides a hook which is called within an object oriented
260 call to <function>select</function> with a non-nil value of
261 <parameter>refresh</parameter> when the View Class instance
262 <parameter>object</parameter> has been updated from the
263 database. A method specialised on
264 <type>standard-db-object</type> is provided which has no
265 effects. Methods specialised on particular View Classes can be
266 used to specify any operations that need to be made on View
267 Classes instances which have been updated in calls to
268 <function>select</function>.
272 <title>Examples</title>
278 <title>Side Effects</title>
280 The user hook function may cause side effects.
284 <title>Exceptional Situations</title>
290 <title>See Also</title>
293 <member><link linkend="select"><function>select</function></link></member>
299 <refentry id="update-instance-from-records">
301 <refname>UPDATE-INSTANCE-FROM-RECORDS</refname>
302 <refpurpose>Update slot values from database.</refpurpose>
303 <refclass>Function</refclass>
306 <title>Syntax</title>
308 <function>(update-instance-from-records object &key database)</function> => <returnvalue><!-- result --></returnvalue></synopsis>
311 <title>Arguments and Values</title>
314 <term><parameter>object</parameter></term>
317 An instance of a view class.
322 <term><parameter>database</parameter></term>
325 A database connection.
332 <title>Description</title>
333 <para>Updates the slot values of the View Class instance
334 <parameter>object</parameter> using the attribute values of the
335 appropriate table of <parameter>database</parameter> which
336 defaults to the database associated with
337 <parameter>object</parameter> or, if <parameter>object</parameter> is not associated
338 with a database, <variable>*default-database*</variable>. Join slots are updated but
339 instances of the class on which the join is made are not
344 <title>Examples</title>
350 <title>Side Effects</title>
352 Slot values of <parameter>object</parameter> may be modified.
356 <title>Affected by</title>
359 Data in SQL database.
364 <title>Exceptional Situations</title>
366 If <parameter>database</parameter> is not able to be read.
370 <title>See Also</title>
385 <refentry id="update-objects-joins">
387 <refname>UPDATE-OBJECTS-JOINS</refname>
388 <refpurpose>Updates joined slots of objects.</refpurpose>
389 <refclass>Function</refclass>
392 <title>Syntax</title>
394 <function>(update-objects-joins objects &key (slots t) (force-p t) class-name (max-len *default-update-objects-max-len*))</function> => <returnvalue><!-- result --></returnvalue></synopsis>
397 <title>Arguments and Values</title>
400 <term><parameter>objects</parameter></term>
403 A list of instances of a view class.
408 <term><parameter>slots</parameter></term>
415 <term><parameter>force-p</parameter></term>
422 <term><parameter>class-name</parameter></term>
425 A list of instances of a view class.
430 <term><parameter>max-len</parameter></term>
439 <title>Description</title>
440 <para>Updates from the records of the appropriate database
441 tables the join slots specified by <parameter>slots</parameter>
442 in the supplied list of View Class instances
443 <parameter>objects</parameter>. <parameter>slots</parameter>
444 when &t; means that all join slots with :retrieval :immediate
445 are updated. <parameter>class-name</parameter> is used to
446 specify the View Class of all instance in
447 <parameter>objects</parameter>, when &nil; then the class of the
448 first instance in <parameter>objects</parameter> is
449 used. <parameter>force-p</parameter> when &t; means that all
450 join slots are updated whereas a value of &nil; means that only
451 unbound join slots are updated. <parameter>max-len</parameter>
452 when non-nil specifies that
453 <function>update-object-joins</function> may issue multiple
454 database queries with a maximum of
455 <parameter>max-len</parameter> instances updated in each query.
459 <title>Examples</title>
465 <title>Side Effects</title>
467 <!-- side effects -->
471 <title>Affected by</title>
476 linkend="default-update-objects-max-len"><variable>*default-update-objects-max-len*</variable></link></member>
482 <title>Exceptional Situations</title>
488 <title>See Also</title>
503 <refentry id="update-record-from-slot">
505 <refname>UPDATE-RECORD-FROM-SLOT</refname>
506 <refpurpose>Updates database from slot value.</refpurpose>
507 <refclass>Function</refclass>
510 <title>Syntax</title>
512 <function>(update-record-from-slot object slot &key database)</function> => <returnvalue><!-- result --></returnvalue></synopsis>
515 <title>Arguments and Values</title>
518 <term><parameter>object</parameter></term>
521 An instance of a view class.
526 <term><parameter>slot</parameter></term>
529 The name of a slot in <parameter>object</parameter>.
534 <term><parameter>database</parameter></term>
537 A database connection.
544 <title>Description</title>
545 <para>Updates the value stored in the column represented by the
546 slot, specified by the CLOS slot name
547 <parameter>slot</parameter>, of View Class instance
548 <parameter>object</parameter>. <parameter>database</parameter>
549 specifies the database in which the update is made only if
550 <parameter>object</parameter> is not associated with a
551 database. In this case, a record is created in
552 <parameter>database</parameter> and the attribute represented by
553 <parameter>slot</parameter> is initialised from the value of the
554 supplied slots with other attributes having default
555 values. Furthermore, <parameter>object</parameter> becomes
556 associated with <parameter>database</parameter>.
560 <title>Examples</title>
566 <title>Side Effects</title>
572 <title>Affected By</title>
578 <title>Exceptional Situations</title>
584 <title>See Also</title>
587 <member><link linkend="update-record-from-slots"><function>update-record-from-slots</function></link></member>
588 <member><link linkend="update-records-from-instance"><function>update-records-from-instance</function></link></member>
600 <refentry id="update-record-from-slots">
602 <refname>update-record-from-slots</refname>
603 <refpurpose>update database from slots of view class object.</refpurpose>
604 <refclass>function</refclass>
607 <title>syntax</title>
609 <function>(update-record-from-slots object slots &key (database *default-database*))</function> => <returnvalue><!-- result --></returnvalue></synopsis>
612 <title>Arguments and Values</title>
615 <term><parameter>object</parameter></term>
618 An instance of a view class.
623 <term><parameter>slots</parameter></term>
626 A list of slot names in <parameter>object</parameter>.
631 <term><parameter>database</parameter></term>
634 A database connection.
641 <title>Description</title>
642 <para>Updates the values stored in the columns represented by
643 the slots, specified by the clos slot names
644 <parameter>slots</parameter>, of view class instance
645 <parameter>object</parameter>. <parameter>database</parameter>
646 specifies the database in which the update is made only if
647 <parameter>object</parameter> is not associated with a
648 database. In this case, a record is created in the appropriate
649 table of <parameter>database</parameter> and the attributes
650 represented by <parameter>slots</parameter> are initialised from
651 the values of the supplied slots with other attributes having
652 default values. Furthermore, <parameter>object</parameter>
653 becomes associated with <parameter>database</parameter>.
657 <title>Examples</title>
663 <title>Side Effects</title>
665 Modifies the SQL database.
669 <title>Affected by</title>
675 <title>Exceptional Situations</title>
681 <title>See Also</title>
684 <member><link linkend="update-record-from-slot"><function>update-record-from-slot</function></link></member>
685 <member><link linkend="update-records-from-instance"><function>update-records-from-instance</function></link></member>
698 <refentry id="update-records-from-instance">
700 <refname>UPDATE-RECORDS-FROM-INSTANCE</refname>
701 <refpurpose>Update database from view class object.</refpurpose>
702 <refclass>Function</refclass>
705 <title>Syntax</title>
707 <function>(update-records-from-instance object &key (database *default-database*))</function> => <returnvalue><!-- result --></returnvalue></synopsis>
710 <title>Arguments and Values</title>
713 <term><parameter>object</parameter></term>
716 An instance of a view class.
721 <term><parameter>database</parameter></term>
724 A database connection.
731 <title>Description</title>
732 <para>Using an instance of a View Class,
733 <parameter>object</parameter>, update the table that stores its
734 instance data. <parameter>database</parameter> specifies the
735 database in which the update is made only if
736 <parameter>object</parameter> is not associated with a
737 database. In this case, a record is created in the appropriate
738 table of <parameter>database</parameter> using values from the
739 slot values of <parameter>object</parameter>, and
740 <parameter>object</parameter> becomes associated with
741 <parameter>database</parameter>.
745 <title>Examples</title>
751 <title>Side Effects</title>
753 Modifies the database.
757 <title>Affected by</title>
763 <title>Exceptional Situations</title>
769 <title>See Also</title>
772 <member><link linkend="update-record-from-slot"><function>update-record-from-slot</function></link></member>
773 <member><link linkend="update-record-from-slots"><function>update-record-from-slots</function></link></member>
785 <refentry id="update-slot-from-record">
787 <refname>UPDATE-SLOT-FROM-RECORD</refname>
788 <refpurpose>Update objects slot from database.</refpurpose>
789 <refclass>Function</refclass>
792 <title>Syntax</title>
794 <function>(update-slot-from-record object slot &key (database *default-database*))</function> => <returnvalue><!-- result --></returnvalue></synopsis>
797 <title>Arguments and Values</title>
800 <term><parameter>object</parameter></term>
803 An instance of a view class.
808 <term><parameter>slot</parameter></term>
811 The name of a slot in <parameter>object</parameter>.
816 <term><parameter>database</parameter></term>
819 A database connection.
826 <title>Description</title>
827 <para>Updates the slot value, specified by the CLOS slot name
828 <parameter>slot</parameter>, of the View Class instance
829 <parameter>object</parameter> using the attribute values of the
830 appropriate table of <parameter>database</parameter> which
831 defaults to the database associated with
832 <parameter>object</parameter> or, if
833 <parameter>object</parameter> is not associated with a database,
834 <variable>*default-database*</variable>. Join slots are updated
835 but instances of the class on which the join is made are not
840 <title>Examples</title>
846 <title>Side Effects</title>
848 Modifies the slot value of the object.
852 <title>Affected by</title>
855 <member>Data in SQL database.</member>
860 <title>Exceptional Situations</title>
866 <title>See Also</title>