Make it possible to pass functional expression to :order-by in select.
authorRyszard Szopa <ryszard.szopa@gmail.com>
Sun, 4 Jan 2009 00:23:07 +0000 (01:23 +0100)
committerNathan Bird <nathan@acceleration.net>
Mon, 20 Jun 2011 20:06:18 +0000 (16:06 -0400)
Also prevent errors when setting table qualifiers

  prev: Ryszard Szopa <ryszard.szopa@gmail.com>
        0c4d66aaaf81025974508a4e7b5d10205e4db7f7
        9aafcb72bd7ca1d7e908938b6a5319753b3371d9

sql/oodml.lisp

index 466e86a55945fa280a6f3e0a8c7034e304087d00..b2f16a6d3319adef5620d745e213175122f9809f 100644 (file)
@@ -1261,15 +1261,19 @@ as elements of a list."
            (when (and order-by (= 1 (length target-args)))
              (let ((table-name (view-table (find-class (car target-args))))
                    (order-by-list (copy-seq (listify order-by))))
-
-               (loop for i from 0 below (length order-by-list)
-                  do (etypecase (nth i order-by-list)
-                       (sql-ident-attribute
-                        (unless (slot-value (nth i order-by-list) 'qualifier)
-                          (setf (slot-value (nth i order-by-list) 'qualifier) table-name)))
-                       (cons
-                        (unless (slot-value (car (nth i order-by-list)) 'qualifier)
-                          (setf (slot-value (car (nth i order-by-list)) 'qualifier) table-name)))))
+               (labels ((set-table-if-needed (val)
+                          (typecase val
+                            (sql-ident-attribute
+                             (handler-case
+                                 (unless (slot-value val 'qualifier)
+                                   (setf (slot-value val 'qualifier) table-name))
+                               (simple-error ()
+                                 ;; TODO: Check for a specific error we expect
+                                 )))
+                            (cons (set-table-if-needed (car val))))))
+                 (loop for i from 0 below (length order-by-list)
+                       for id = (nth i order-by-list)
+                       do (set-table-if-needed id)))
                (setf (getf qualifier-args :order-by) order-by-list)))
 
            (cond