Hi,
I have a bit of a problem understanding how multiple connections and connection pools work.
What I would like to do is to open an connection to the database, read several rows from one table with doquery, and for each read row analyze data, and if conditions are met, write a row to another table. I'd rather not use memory to store the results from the first query because I am a bit memory constrained.
I have tried the following (just the simplification of the actual code), for which I get the message "Database error: This connection is still processing another query."
(defvar *db-parameters* (list "databasename" "databaseuser" "databasepassword" "dbhostaddress" :pooled-p t)) (defmacro with-db (&body body) `(postmodern:with-connection *db-parameters* ,@body))
(defun process-some-stuff () (with-db (postmodern:doquery (read some stuff from a table) (several variables) (analyze row) (if some conditions (with-db (postmodern:query (insert stuff into another table)))))))
Also, I have tried using two postmodern:connection and then after each with-db, but the error is the same.
I understand that when I use ":pooled-p t" postmodern will use some kind of pool, but I have'nt been able to understand how to use it properly, nor did I manage to find any kind of solution on the internet. The test.lisp in postmodern source directory did test the pool, but each time the connection was imediatelly closed after openning it, and there were no examples like in my situation.
Perhaps the nesting of the querries is not allowed in postmodern?
Hi Slobodan,
Firstly, your snippet works for me (if I substitute meaningful stuff for your placeholders), and should work -- the inner with-db should open (or fetch from the pool) a fresh connection, that can be used even while the outer connection is processing a query (doquery will run its body while the database is returning the result rows). I tested against PostgreSQL 9.0.
So, since you don't really describe what kind of error you are getting, you'll have to be more specific (maybe give me a full example, including tables and some test data) for me to be able to debug this.
Best, Marijn
Dear Mr. Haverbeke,
It was an stupid mistake on my side, I had another query in the code I have been playing with, and that one wasn't with the "with-connection" and ":pooled-p". I appologize for wasting your time, I will try my best not to do so again.
On Tue, Nov 23, 2010 at 13:13, Marijn Haverbeke marijnh@gmail.com wrote:
Hi Slobodan,
Firstly, your snippet works for me (if I substitute meaningful stuff for your placeholders), and should work -- the inner with-db should open (or fetch from the pool) a fresh connection, that can be used even while the outer connection is processing a query (doquery will run its body while the database is returning the result rows). I tested against PostgreSQL 9.0.
So, since you don't really describe what kind of error you are getting, you'll have to be more specific (maybe give me a full example, including tables and some test data) for me to be able to debug this.
Best, Marijn
postmodern-devel mailing list postmodern-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/postmodern-devel
Good to hear you've solved the issue. Don't worry about the occasional false alarm -- it makes the mailing list look alive ;)
postmodern-devel@common-lisp.net