Brian said:
I don't think you can 'do' a delete command, you'd have to prepare and
execute it.
..... which is precisely what do() does. From perldoc DBI:
==================================================
do
$rows = $dbh->do($statement) or die $dbh->errstr;
$rows = $dbh->do($statement, \%attr) or die $dbh->errstr;
$rows = $dbh->do($statement, \%attr, @bind_values) or die ...
Prepare and execute a single statement. Returns the number of rows
affected or undef on error. A return value of -1 means the number of
rows is not known, not applicable, or not available.
This method is typically most useful for non-SELECT statements that
either cannot be prepared in advance (due to a limitation of the
driver) or do not need to be executed repeatedly. It should not be used
for SELECT statements because it does not return a statement handle (so
you can't fetch any data).
The default do method is logically similar to:
sub do {
my($dbh, $statement, $attr, @bind_values) = @_;
my $sth = $dbh->prepare($statement, $attr) or return undef;
$sth->execute(@bind_values) or return undef;
my $rows = $sth->rows;
($rows == 0) ? "0E0" : $rows; # always return true if no error
}
For example:
my $rows_deleted = $dbh->do(q{
DELETE FROM table
WHERE status = ?
}, undef, 'DONE') or die $dbh->errstr;
==================================================
Paul Lalli