What's wrong here? Tested with LW and SBCL.
Thanks Jens
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]
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
On 8/17/07, Ryszard Szopa ryszard.szopa@gmail.com wrote:
(defun with-connection-fun (connection-spec what-to-do) "Functional under the macro WITH-CONNECTION."
Should be: "Function under the macro..."
(let ((postmodern:*database* (apply #'postmodern:connect connection-spec))) (unwind-protect (progn (funcall what-to-do)) (postmodern:disconnect postmodern:*database*))))
On 8/17/07, Ryszard Szopa ryszard.szopa@gmail.com wrote:
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?
or to something like this one:
(defvar *connection-spec* (list "db" "user" "pass" "host" :pooled-p t))
(defmacro with-db (&body body) `(let ((*database* (apply 'connect *connection-spec*))) (unwind-protect (progn ,@body) (disconnect *database*))))
On 8/17/07, Ryszard Szopa ryszard.szopa@gmail.com wrote:
Marijn: maybe you could consider changing Postmodern's with-connection as I've described above?
Will be looked into when I'm back at my own place (which won't be for a while). It would be an incompatible change though, I'll probably just add an alternative with another name instead.
Cheers, Marijn
Hey Ryszard,
I didn't actually read your mail very well last time -- your suggestion wasn't an incompatible change. The function is a good idea, I added it. I also realized how completely useless my take on with-connection was in any kind of serious application, so I also made a with-connection* macro which does evaluate its connection-specification.
At least, I think I did. The changes are completely untested -- could you kindly test them and tell me how it goes?
Cheers, Marijn
(BTW, does anyone know what's up with the darcsweb thingy for http://common-lisp.net/cgi-bin/darcsweb/darcsweb.cgi?r=postmodern-postmodern... ? It does seem to work for other projects, but postmodern breaks it... which is a shame.)
(BTW, does anyone know what's up with the darcsweb thingy for http://common-lisp.net/cgi-bin/darcsweb/darcsweb.cgi?r=postmodern-postmodern... ? It does seem to work for other projects, but postmodern breaks it... which is a shame.)
Never mind -- it was a weird Croatian letter that I accidentally added to a patch description while typing on a Croatian keyboard. I unrecorded it and replaced it by a patch with a regular ascii name, and everything works again.
Lesson: Darcsweb does not do unicode very well.
Cheers, Marijn
On 9/17/07, Marijn Haverbeke marijnh@gmail.com wrote:
At least, I think I did. The changes are completely untested -- could you kindly test them and tell me how it goes?
I pulled all the changes from the repo and ran your tests. Fiveam said: Did 27 checks. Pass: 27 (100%) Skip: 0 ( 0%) Fail: 0 ( 0%)
That means everything is OK. Unless, of course, they introduced really ugly bugs that aren't even covered by the tests. :P
-- Richard
I pulled all the changes from the repo and ran your tests. Fiveam said: Did 27 checks. Pass: 27 (100%) Skip: 0 ( 0%) Fail: 0 ( 0%)
Oh, you seem to be under the impression that I actually introduced test cases for the changes -- how naive ;) . I didn't, but a quick usage of call-with-connection (your with-connection-fun) and with-connection* (a variant of with-connection which evaluates the specification list) should show any problems I introduced. I stared at the code for a few minutes, so it shouldn't contain any glaring mistakes, but you never know.
Cheers, Marijn
On 9/18/07, Marijn Haverbeke marijnh@gmail.com wrote:
Oh, you seem to be under the impression that I actually introduced test cases for the changes -- how naive ;) . I didn't, but a quick
Oh. I thought you reimplemented WITH-CONNECTION using CALL-WITH-CONNECTION (nb. that's a lot better name for that function) in order to avoid code reduplication blahblahblah ;), so the tests for WITH-CONNECTION would reveal any errors. Yeah, I definitely should look more thoroughly at the patches I apply in oder to test them :)
usage of call-with-connection (your with-connection-fun) and with-connection* (a variant of with-connection which evaluates the specification list) should show any problems I introduced. I stared at the code for a few minutes, so it shouldn't contain any glaring mistakes, but you never know.
Apparently, you missed a comma before SPEC in WITH-CONNECTION*, so there was an undefined variable error. After applying the attached patch:
CL-USER> (let ((test "test")) (pomo:with-connection* (list test "richard" "dupa" "localhost") (pomo:query (:select 1)))) ((1)) CL-USER> (let ((test "test")) (pomo:call-with-connection (list test "richard" "dupa" "localhost") (lambda () (pomo:query (:select 1))))) ((1))
I hope it's OK now.
Bests,
-- Richard
postmodern-devel@common-lisp.net