X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=sql%2Foodml.lisp;h=7bf7d5bf77db5adcb9bed1ca976ca7082a2afebb;hb=29184a377bfebf51266104aadafc5fe422cbd791;hp=634acc859f9fa5e3e14f459d2ef77bd67c697ebf;hpb=90ce2284fab5f1daedb8aa6aba3008a5c3651e30;p=clsql.git diff --git a/sql/oodml.lisp b/sql/oodml.lisp index 634acc8..7bf7d5b 100644 --- a/sql/oodml.lisp +++ b/sql/oodml.lisp @@ -265,6 +265,7 @@ (ordered-class-direct-slots view-class) (ordered-class-slots view-class)))) (record-values (mapcar #'slot-value-list slots))) + (cond ((and (not (normalizedp view-class)) (not record-values)) (error "No settable slots.")) @@ -285,16 +286,22 @@ (insert-records :into (sql-expression :table view-class-table) :av-pairs record-values :database database) + (when pk-slot (if (or (and (listp (view-class-slot-db-constraints pk-slot)) (member :auto-increment (view-class-slot-db-constraints pk-slot))) (eql (view-class-slot-db-constraints pk-slot) :auto-increment)) + (unless pk + (let ((db-pk (car (query "SELECT LAST_INSERT_ID();" + :flatp t :field-names nil + :database database)))) + (setf pk db-pk + (slot-value + obj (slot-definition-name pk-slot)) db-pk))) + (setf pk (or pk - (car (query "SELECT LAST_INSERT_ID();" - :flatp t :field-names nil - :database database)))) - (setf pk (or pk - (slot-value obj (slot-definition-name pk-slot)))))) + (slot-value + obj (slot-definition-name pk-slot)))))) (when (eql this-class nil) (setf (slot-value obj 'view-database) database))))))) pk)) @@ -332,6 +339,7 @@ :result-types nil :database vd)))) (when res + (setf (slot-value instance 'view-database) vd) (get-slot-values-from-view instance (mapcar #'car sels) (car res)))) (pres) (t nil))))) @@ -358,6 +366,7 @@ (res (select att-ref :from view-table :where view-qual :result-types nil))) (when res + (setf (slot-value instance 'view-database) vd) (get-slot-values-from-view instance (list slot-def) (car res)))))) (defmethod update-slot-with-null ((object standard-db-object) @@ -580,8 +589,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)) @@ -635,10 +648,19 @@ (declare (ignore database db-type)) ;; writing 1.0 writes 1, so we we *really* want a float, must do (float ...) (etypecase val - (string - (float (read-from-string val))) - (float - val))) + (string (float (read-from-string val))) + (float val))) + +(defmethod read-sql-value (val (type (eql 'double-float)) database db-type) + (declare (ignore database db-type)) + ;; writing 1.0 writes 1, so if we *really* want a float, must do (float ...) + (etypecase val + (string (float + (let ((*read-default-float-format* 'double-float)) + (read-from-string val)) + 1.0d0)) + (double-float val) + (float (coerce val 'double-float)))) (defmethod read-sql-value (val (type (eql 'boolean)) database db-type) (declare (ignore database db-type))