Bug in 'update-records-from-instance'
"Saurabh Nanda" <[email protected]> Mon, 28 May 2007 17:35:59 +0530
| Newsgroups | gmane.lisp.clsql.general,gmane.lisp.clsql.devel |
|---|---|
| Message-ID | <[email protected]> |
--===============0710996712==
Content-Type: multipart/alternative;
boundary="----=_Part_187418_9029392.1180353959749"
------=_Part_187418_9029392.1180353959749
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi,
I've been hacking around the CLSQL OODML/OODDL stuff for some time now, and
just noticed that 'update-records-from-instance' assumes that the database
connection of an object will be open at the time of updating the DB. Is this
correct?
Here's some proof of concept code that hits this bug:
;;;
(defparameter *db-credentials* (list (list "//172.16.31.29/db" "user"
"pass") :pool nil :database-type :oracle :if-exists :new :make-default nil))
;;;
(defmacro with-custom-database ((&key db-var (connection-args
'*db-credentials*)) &body body)
(let ((result (gensym "result-")))
(unless db-var (setf db-var 'clsql:*default-database*))
`(let ((,db-var (apply #'clsql:connect ,connection-args))
(,result nil))
(unwind-protect
(let ((,db-var ,db-var))
(setf ,result (progn ,@body)))
(clsql:disconnect :database ,db-var))
,result)))
;;;
(defun get-object (id)
(with-custom-database ()
(first (select 'student :where [= [id] id] :flatp t))))
;;
(defun poc ()
(with-custom-database ()
(let ((a (get-object 3)))
(setf (student-name a) "Joe Stud")
(update-records-from-instance a))))
The form '(update-records-from-instance a)' in the 'poc' functions throws a
"Database is closed error" because of the way 'update-records-from-instance'
uses the 'view-database' slot.
Regards,
Saurabh.
--
http://nandz.blogspot.com
http://foodieforlife.blogspot.com
------=_Part_187418_9029392.1180353959749
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi,<br><br>I've been hacking around the CLSQL OODML/OODDL stuff for some time now, and just noticed that 'update-records-from-instance' assumes that the database connection of an object will be open at the time of updating the DB. Is this correct?
<br><br>Here's some proof of concept code that hits this bug:<br><br>;;;<br>(defparameter *db-credentials* (list (list "//172.16.31.29/db" "user" "pass") :pool nil :database-type :oracle :if-exists :new :make-default nil))
<br><br>;;;<br>(defmacro with-custom-database ((&key db-var (connection-args '*db-credentials*)) &body body)<br> (let ((result (gensym "result-")))<br> (unless db-var (setf db-var 'clsql:*default-database*))
<br> `(let ((,db-var (apply #'clsql:connect ,connection-args))<br> (,result nil))<br> (unwind-protect<br> (let ((,db-var ,db-var))<br> (setf ,result (progn ,@body)))<br> (clsql:disconnect :database ,db-var))
<br> ,result)))<br><br clear="all">;;;<br>(defun get-object (id)<br> (with-custom-database ()<br> (first (select 'student :where [= [id] id] :flatp t))))<br><br>;;<br>(defun poc ()<br> (with-custom-database ()
<br> (let ((a (get-object 3)))<br> (setf (student-name a) "Joe Stud")<br> (update-records-from-instance a))))<br><br>The form '(update-records-from-instance a)' in the 'poc' functions throws a "Database is closed error" because of the way 'update-records-from-instance' uses the 'view-database' slot.
<br><br>Regards,<br>Saurabh.<br>-- <br><a href="http://nandz.blogspot.com">http://nandz.blogspot.com</a><br><a href="http://foodieforlife.blogspot.com">http://foodieforlife.blogspot.com</a>
------=_Part_187418_9029392.1180353959749--
--===============0710996712==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
CLSQL-Help mailing list
[email protected]
http://lists.b9.com/mailman/listinfo/clsql-help
--===============0710996712==--