On Wed, Sep 04, 2002 at 09:58:35AM -0500, Paul DuBois wrote: > At 9:50 -0500 9/4/02, David Dooling wrote: > >For security reasons, wouldn't you want to know what statements are > >non-select _before_ you execute? > > > >If you only care about after, how about something like this: > > > > $sth->execute; > > my @row = $sth->fetchrow_array; > > if (@row) { # results } > > elsif (!$sth->errstr) { # now rows } > > else { warn $sth->errstr } > > > >You can't distinguish between selects that return no data and > >non-selects. But for your example below, it really wouldn't matter. > >It seems you need to parse this stuff before. > > In MySQL, you can distinguish select from non-select statements after > $sth->execute by checking $sth->{NUM_OF_FIELDS}. If it's zero, it's > a non-select, if it's non-zero, it's a select. This works even if the > select returns zero rows, because the "width" of the result set is > greater than zero. No parsing of the statement or any other messing > around with it is necessary. > > Does this work for other database engines as well?
It has to as it's the "standard" way to check. The DBI docs specifically say "Non-C<SELECT> statements will have C<NUM_OF_FIELDS == 0>." Tim.