On 8/17/07, Jens Teich info@jensteich.de wrote:
What's wrong here? Tested with LW and SBCL.
POMO> (with-connection ("web_access" "web_access" "***" "localhost") (query (:select '* :from 'dokumente-files))) (("s5s732006l9t5i0ai3a308281gwdh5 " "z_z15p02" "Bilddata/AZ/Pdf/Az15_16/baumuste" "pdf" 1914355) ......
POMO> (defparameter *db* '("web_access" "web_access" "***" "localhost")) *DB*
POMO> (with-connection *db* (query (:select '* :from 'dokumente-files)))
error while parsing arguments to DEFMACRO WITH-CONNECTION: bogus sublist *DB* to satisfy lambda-list (DATABASE USER PASSWORD HOST &KEY (PORT 5432) POOLED-P) [Condition of type SB-KERNEL::DEFMACRO-BOGUS-SUBLIST-ERROR]
Postmodern's macro WITH-CONNECTION expects its connection specification argument to be an unquoted list (it doesn't evaluate it). The easiest solution to your problem may be writing a macro with-default-connection:
(defmacro with-default-connection (&body body) `(with-connection ("web_access" "web_access" "***" "localhost") ,@body))
Another possibility would be to change Postmodern's with-connection and make it a macro interface to a function:
(defun with-connection-fun (connection-spec what-to-do) "Functional under the macro WITH-CONNECTION." (let ((postmodern:*database* (apply #'postmodern:connect connection-spec))) (unwind-protect (progn (funcall what-to-do)) (postmodern:disconnect postmodern:*database*))))
;; This is postmodern's WITH-CONNECTION modified to use the functional ;; interface. (defmacro with-connection ((database user password host &key (port 5432) pooled-p) &body body) "Binds *database* to a new connection and runs body in that scope." `(with-connection-fun '(,database ,user ,password ,host :port ,port :pooled-p ,pooled-p) (lambda () (progn ,@body))))
Then you can do something like (with-connection-fun *DB* (lambda () (query (:select '* :from 'dokumente-files)))) if you really want it.
This approach make also a lot easier writing custom with-*-connection macros (like with-object-connection and so on).
Marijn: maybe you could consider changing Postmodern's with-connection as I've described above?
Bests,
-- Richard