Re: [CLSQL-Help] Bug in 'update-records-from-instance'

Nathan Bird <[email protected]> Thu, 07 Jun 2007 14:53:22 -0400
Newsgroups gmane.lisp.clsql.devel
Message-ID <[email protected]>
I also note that update-records-from-instance prefers the database
argument over the view-database which is different than
update-record-from-slots (and others). I propose pulling that decision
for which database to use into a separate method, and converting most of
the functions update-*-from-*.

(defmethod choose-database-for-instance ((obj standard-db-object) database)
  "Determine which database connection to use for a standard-db-object.
        Errs if none is available."
  (or (view-database obj)
      database
      *default-database*
      (signal-no-database-error nil)))

I tend to agree with Saurabh that if I am explicitly passing in a
database object I want the system to use that one. My case tends to be
in handling a webrequest we keep database connections open much shorter
than we keep objects around on the server. Maybe extend the logic of the
above function to
  (or (find-if #'(lambda (db) (and db (is-database-open db)))
               (list (view-database obj)
                     database
                     *default-database*))
      (signal-no-database-error nil))

That would handle my problem of being associated with a closed
connection but remain somewhat faithful to the original spec.
Additionally making this a method gives me a nice point to override from
my code should I want different behavior.

I would also like to see delete-instance-records extended to take a
database as an optional argument using the above function to select
which actually gets used.

Currently working on some patches for the above, wanted to get some
feedback in case I was way off base.

I also kind of like the reopen the database idea. Maybe set that up as a
restart or a *variable* to select behavior?  I would say that if you do
have the auto-reopen it should auto-reclose. This is kind of a muddy
issue though, I wouldn't be surprised if there are some ugly corner
cases for it.

Nathan Bird


Saurabh Nanda wrote:
> Quoting from http://www.lispworks.com/documentation/lww42/LWUG-W/html/lwuser-w-171.htm
> :
> "update-records-from-instance  instance &key  database
>
> Updates the record in database represented by instance . If the
> instance is already associated with a database, that database is used
> and database is ignored. If instance is not yet associated with a
> database, a record is created for instance in the appropriate table of
> database and the instance becomes associated with that database."
>
> I think the intended behaviour is incorrect. If I'm *explicitly*
> passing a database connection to 'update-records-from-instance' it
> should use that, even if the object is already associated with a
> database.
>
>   
>> Would you propose that an object can automatically reopen a database?
>> If so, should the object then automatically reclose the database? Such
>> issues are not covered by the CommonSQL specification.
>>     
>
> I think the standard can be extended by saying that, if a database
> connection is explicity passed that DB connection is used. Else, it
> uses the DB connection associated with the object iff it is open. Else
> it attemps to use *default-database*.
>
> Thoughts?
>
> PS: Continuing this thread only on clsql-devel.
>
> Saurabh.
>