DBI question: binding params in HAVING clauses

Matt Sergeant msergeant at messagelabs.com
Thu Jan 26 16:43:24 GMT 2006


On 26 Jan 2006, at 10:16, Andy Armstrong wrote:

> On 26 Jan 2006, at 15:01, Jeff Anderson wrote:
>> Like so?
>>
>> my $sql = sprintf('
>>      SELECT COUNT(actors.name), countries.name
>>        FROM actorsXcountries, countries, actors
>>       WHERE actors.id = actorsXcountries.actorid AND
>>             countries.id = actorsXcountries.countryid
>>    GROUP BY countries.name
>>      HAVING COUNT(actors.name) < %d
>>    ORDER BY COUNT(actors.name)
>> ', $dbh->quote(3));
>
> What's the point of $dbh->quote() when %d can only expand to an 
> integer anyway? Or rather what's the point of using sprintf()?

It ensures that whatever you're using is an integer. It's a type safety 
thing.

$dbh->quote() is for strings.

Matt.


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


More information about the london.pm mailing list