r9615: * sql/expressions.lisp: Avoid duplicate FROM names when selecting
authorKevin M. Rosenberg <kevin@rosenberg.net>
Mon, 14 Jun 2004 07:46:57 +0000 (07:46 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Mon, 14 Jun 2004 07:46:57 +0000 (07:46 +0000)
        from a table that has more than one primary index.

ChangeLog
sql/expressions.lisp
sql/oodml.lisp
sql/package.lisp

index 0dc2e4b570729c12dbb28ef401e2d0d033599e63..9066b78f6978843425745b04c0e5d790b793f0ee 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+13 Jun 2004 Kevin Rosenberg <kevin@rosenberg.net>
+       * sql/oodml.lisp: Add new serialization functions:
+       WRITE-INSTANCE-TO-STREAM and READ-INSTANCE-FROM-STREAM
+       * sql/expressions.lisp: Avoid duplicate FROM names when selecting
+       from a table that has more than one primary index.
+       
 13 Jun 2004 Kevin Rosenberg <kevin@rosenberg.net>
        * Version 2.11.9
        * sql/conditions.lisp: Set initial slot value for message in SQL-WARNING
 13 Jun 2004 Kevin Rosenberg <kevin@rosenberg.net>
        * Version 2.11.9
        * sql/conditions.lisp: Set initial slot value for message in SQL-WARNING
index 10b1130aa11dd81f38a0dc5199bfa3788c9a5f74..f2d63c9c85c47e9dd810bce8dff46480291692d8 100644 (file)
@@ -579,7 +579,12 @@ uninclusive, and the args from that keyword to the end."
     (when from
       (write-string " FROM " *sql-stream*)
       (typecase from 
     (when from
       (write-string " FROM " *sql-stream*)
       (typecase from 
-        (list (output-sql (apply #'vector from) database))
+        (list (output-sql (apply #'vector (remove-duplicates 
+                                          from 
+                                          :test #'(lambda (a b)
+                                                    (string-equal (symbol-name (slot-value a 'name))
+                                                                  (symbol-name (slot-value b 'name))))))
+                         database))
         (string (write-string from *sql-stream*))
         (t (output-sql from database))))
     (when inner-join
         (string (write-string from *sql-stream*))
         (t (output-sql from database))))
     (when inner-join
index 329444363b6ed723dab505ae92e3ae5eaebd9441..82f166e1da642108a48556f958bf90abf61c143e 100644 (file)
@@ -1081,3 +1081,27 @@ as elements of a list."
   results)
 
 
   results)
 
 
+
+;;; Serialization functions
+
+(defun write-instance-to-stream (obj stream)
+  "Writes an instance to a stream where it can be later be read.
+NOTE: an error will occur if a slot holds a value which can not be written readably."
+  (let* ((class (class-of obj))
+        (alist '()))
+    (dolist (slot (ordered-class-slots (class-of obj)))
+      (let ((name (slot-definition-name slot)))
+       (when (and (not (eq 'view-database name))
+                  (slot-boundp obj name))
+         (push (cons name (slot-value obj name)) alist))))
+    (setq alist (reverse alist))
+    (write (cons (class-name class) alist) :stream stream :readably t))
+  obj)
+
+(defun read-instance-from-stream (stream)
+  (let ((raw (read stream nil nil)))
+    (when raw
+      (let ((obj (make-instance (car raw))))
+       (dolist (pair (cdr raw))
+         (setf (slot-value obj (car pair)) (cdr pair)))
+       obj))))
index 32365c0a9313d949b9a30be44d4adfd513f6a7ef..9d654fc2f362251de1835655374c534e6fe66344 100644 (file)
         #:delete-instance-records          
         ;; CLSQL Extensions 
         #:*db-auto-sync*    
         #:delete-instance-records          
         ;; CLSQL Extensions 
         #:*db-auto-sync*    
-
+        #:write-instance-to-stream
+        #:read-instance-from-stream
+        
         ;; Symbolic SQL Syntax (syntax.lisp) 
         #:sql                              
         #:sql-expression                   
         ;; Symbolic SQL Syntax (syntax.lisp) 
         #:sql                              
         #:sql-expression