!0

Peter Corlett abuse at cabal.org.uk
Thu Feb 12 15:52:23 GMT 2009


On 12 Feb 2009, at 15:18, Michael Lush wrote:
[...]
> Is there a better idiom for:-
>
> $rows = $dbh->do("SELECT *
>                    FROM foo
>                   WHERE baz >= 42")
> if ($rows != 0) {
>    #do stuff
> }


Yes:

a) use COUNT(*) instead so you're not sending a massive resultset over  
the wire.

b) use RaiseError => 1 so that it throws an exception instead of  
returns a value in-band. I hate in-band errors as people usually don't  
bother checking for them, making for some really exciting problems  
down the line.




More information about the london.pm mailing list