[postmodern-devel] Can't prepare query with :NULL
Hi, I can't use the value :NULL in a Postmodern prepared query:
(postmodern:query "select cast ($1 as int)" :null :single)
debugger invoked on a CL-POSTGRES:DATABASE-ERROR in thread #<THREAD "initial thread" {10025599C1}>: Database error 08P01: bind message supplies 0 parameters, but prepared statement "" requires 1 Query: select cast ($1 as int) (The cast was given so that the type of the expected value would be known.) If I understand PostgreSQL and Postmodern correctly, this should return the Lisp value NIL. I have no similar problem with SQL and SQL-COMPILE, since these apparently don't technically do query preparation. I believe there is an error in the QUERY macro which is causing this. The loop which determines ARGS sees :NULL as a keyword symbol and assumes this means it is an output format. Instead of checking each member of ARGS/FORMAT to see if it is a keyword symbol, I would check for its membership in a list of possible valid format symbols. Alternatively, I'd take the idea of the DB-NULL type to an extreme, writing Lisp type definitions for each supported SQL type, and also write a type (e.g. DB-VALUE) that is the OR of all of these types. (It looks something similar was already done.) In the QUERY macro, only if an argument isn't of the type DB-VALUE would it be considered an output format. -- J.P. Larocque: <piranha@thoughtcrime.us>, <piranha@ely.ath.cx>
Good point, I guess I'll revise the query macro to be a bit more careful about recognizing output-format keywords. For now, you should be able to just use 'null instead. Regards, Marijn
On 7/24/07, Marijn Haverbeke <marijnh@gmail.com> wrote:
Good point, I guess I'll revise the query macro to be a bit more careful about recognizing output-format keywords. For now, you should be able to just use 'null instead.
'null also doesn't seem to work. (postmodern:query (format nil "select cast (~A as int)" 'null) :single) does work, though it's rather ugly. Bests, -- Richard -- http://szopa.tasak.gda.pl/
Hi again, I ended up just fixing 'query' to be more disciminative about the things it recognizes as format-specifiers, which should solve your problem. While I was at it, I made a new release (1.02), because there were already a few other bugfixes and new features waiting. Cheers, Marijn
participants (3)
-
J.P. Larocque
-
Marijn Haverbeke
-
Ryszard Szopa