[postmodern-devel] Can't prepare query with :NULL

J.P. Larocque piranha at thoughtcrime.us
Tue Jul 24 08:46:22 UTC 2007


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 at thoughtcrime.us>, <piranha at ely.ath.cx>



More information about the postmodern-devel mailing list