DBI question: binding params in HAVING clauses

David Cantrell david at cantrell.org.uk
Wed Jan 25 21:31:40 GMT 2006

On Wed, Jan 25, 2006 at 02:10:09PM -0500, Matt Sergeant wrote:
> On 25 Jan 2006, at 11:35, David Cantrell wrote:
> >but if instead I replace the 3 with a placeholder, and supply it like
> >so:
> >  $sth = $dbh->prepare('...');
> >  $sth->execute(3);
> >then the HAVING clause seems to be ignored, and I later get too many
> >rows back.
> Yes, it depends on where the underlying DB driver supports 
> placeholders. IIRC Pg is the same with LIMIT/OFFSET params (don't quote 
> me on that).

Grrr, hateful software.

> >  And do you have a solution?
> Use sprintf.

Use sprintf in what manner?

Seeing that I'm building the query up programmatically, including
putting in the placeholders, I think the best thing would be to just put
in the results of $dbh->quote(yadda yadda).  Re-parsing the SQL every
time won't be an issue in this case.

David Cantrell | http://www.cantrell.org.uk/david

There's a hole in the world like a great black pit
And the vermin of the world inhabit it
And its morals aren't worth what a pig could spit
And it goes by the name of London.

More information about the london.pm mailing list