use $sth->rows() to get number of rows.
authorMartin Atukunda <matlads@yahoo.co.uk>
Tue, 29 Jan 2013 09:35:29 +0000 (09:35 +0000)
committerMartin Atukunda <matlads@yahoo.co.uk>
Tue, 29 Jan 2013 09:35:29 +0000 (09:35 +0000)
From the DBI manpage:

'A DBI statement handle execute always returns true regardless of the number of rows affected, even it's zero." It only returns the number of rows affected for non-"SELECT" statements.'

This patch ensures that we get the proper count by calling $sth->rows() instead of relying on $sth->execute.

Bucardo.pm

index df7a4edcbdef48f0eee174513bdddc3e5d8c7b8d..5cf7b803a7d819edb54d1e95e7626989678044ac 100644 (file)
@@ -7715,11 +7715,13 @@ sub table_has_rows {
 
     ## Some types do not have a count
     return 0 if $x->{does_append_only};
-
+    my $rv;
     if ($x->{does_limit}) {
         $SQL = "SELECT 1 FROM $tname LIMIT 1";
         $sth = $x->{dbh}->prepare($SQL);
-        $count = $sth->execute();
+        $rv = $sth->execute();
+        $count = $sth->rows();
         $sth->finish();
         return $count >= 1 ? 1 : 0;
     }
@@ -7731,7 +7733,8 @@ sub table_has_rows {
     elsif ('oracle' eq $x->{dbtype}) {
         $SQL = "SELECT 1 FROM $tname WHERE rownum > 1";
         $sth = $x->{dbh}->prepare($SQL);
-        $count = $sth->execute();
+        $rv = $sth->execute();
+        $count = $sth->rows();
         $sth->finish();
         return $count >= 1 ? 1 : 0;
     }