in reply to Number of rows affected by an update command

From the DBI docs:

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 } # do

Note the word logically in there. I'm not sure if all DBD drivers follow this exactly as documented. You might try to see if changing the do () to above sequence changes the returned expectation. If it does, please inform the DBD author at hand that the return code from do () is not as documented by the DBI.


Enjoy, Have FUN! H.Merijn

Replies are listed 'Best First'.
Re^2: Number of rows affected by an update command
by Anonymous Monk on Nov 03, 2010 at 20:48 UTC
    Thanks for your reply. How would you spot a failed update then?

      Define "failed". If an update affects no records at all (the where clause doesn't match any records), is it a FAIL or is it a PASS? For me it is a PASS. A FAIL is when the database returns an error.

      Personally I ALWAYS use the RaiseError database handle attribute, and enclose code that expectedly can fail inside an eval { }.


      Enjoy, Have FUN! H.Merijn