Bug: update-instance-from-records
Joel Reymont <[email protected]> Fri, 10 Mar 2006 17:32:32 +0000
| Newsgroups | gmane.lisp.clsql.devel |
|---|---|
| Message-ID | <[email protected]> |
I have been playing with update-instance-from-records today. I don't
know if it's an issue with the Oracle module or something more
general but it does not work the way select does.
If I select a record the OO way then my slot values are converted
from strings and the instance is associated with a database. If I
make-instance, set the key slots and try update-instance-from-records
then several things happen:
1) I get an error from update-slot-from-db. The very first cond
clause uses (view-database instance) but that is nil. database-
underlying-type then complains.
2) If I change the update-slot-from-db code to use (or (view-database
instance) *default-database*) then my record is updated but the slot
values are not converted according to types specified in def-view-
class. All slots retrieved by update-instance-from-records are set to
string values.
I'm currently resorting to the following but there must be an easier
way:
(defmacro fetch-with-keys (class-name &rest key-values)
(let* ((class (find-class class-name))
(key-names (loop for slot-def in (sb-mop:class-slots class)
when (eq :key (slot-value slot-def 'clsql-
sys::db-kind))
collect (sb-mop:slot-definition-name slot-def)
))
(where (mapcar #'(lambda (name value)
`[= [slot-value ',class-name
',name] ,value])
key-names key-values))
(init-args (loop for name in key-names
for value in key-values
append (list (intern (symbol-name
name) :keyword)
value))))
`(or (caar (clsql:select ',class-name :where [and ,@where]))
(make-instance ',class-name ,@init-args))
))
Thanks, Joel
--
http://wagerlabs.com/