X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql%2Foodml.lisp;h=9aff2c8dab99a36b930d09c103340b1125961abe;hb=53bf64089da7f091d748f46eb95ebeb39d990dd9;hp=8eec40e98fed5840c6aa487108d81904324c2a43;hpb=106b55bc15b5118cd328e3ebb6f5f67db3b26206;p=clsql.git diff --git a/sql/oodml.lisp b/sql/oodml.lisp index 8eec40e..9aff2c8 100644 --- a/sql/oodml.lisp +++ b/sql/oodml.lisp @@ -473,8 +473,12 @@ (format nil "~F" val))) (defmethod read-sql-value (val type database db-type) - (declare (ignore type database db-type)) - (read-from-string val)) + (declare (ignore database db-type)) + (cond + ((null type) val) ;;we have no desired type, just give the value + ((typep val type) val) ;;check that it hasn't already been converted. + ((typep val 'string) (read-from-string val)) ;;maybe read will just take care of it? + (T (error "Unable to read-sql-value ~a as type ~a" val type)))) (defmethod read-sql-value (val (type (eql 'string)) database db-type) (declare (ignore database db-type)) @@ -870,6 +874,10 @@ maximum of MAX-LEN instances updated in each query." (car objects) objects)))) +(defmethod select-table-sql-expr ((table T)) + "Turns an object representing a table into the :from part of the sql expression that will be executed " + (sql-expression :table (view-table table))) + (defun find-all (view-classes &rest args &key all set-operation distinct from where group-by having @@ -883,8 +891,6 @@ maximum of MAX-LEN instances updated in each query." (flet ((ref-equal (ref1 ref2) (string= (sql-output ref1 database) (sql-output ref2 database))) - (table-sql-expr (table) - (sql-expression :table (view-table table))) (tables-equal (table-a table-b) (when (and table-a table-b) (string= (string (slot-value table-a 'name)) @@ -910,15 +916,15 @@ maximum of MAX-LEN instances updated in each query." (fullsels (apply #'append (mapcar #'append sels immediate-join-sels))) (sel-tables (collect-table-refs where)) (tables (remove-if #'null - (remove-duplicates - (append (mapcar #'table-sql-expr sclasses) - (mapcan #'(lambda (jc-list) - (mapcar - #'(lambda (jc) (when jc (table-sql-expr jc))) - jc-list)) - immediate-join-classes) - sel-tables) - :test #'tables-equal))) + (remove-duplicates + (append (mapcar #'select-table-sql-expr sclasses) + (mapcan #'(lambda (jc-list) + (mapcar + #'(lambda (jc) (when jc (select-table-sql-expr jc))) + jc-list)) + immediate-join-classes) + sel-tables) + :test #'tables-equal))) (order-by-slots (mapcar #'(lambda (ob) (if (atom ob) ob (car ob))) (listify order-by))) (join-where nil))