in reply to Re: DBD::Sybase $sth->rows returns -1
in thread DBD::Sybase $sth->rows returns -1

You could use

my $rowCount; my $role; while (my @row_18 = $sth18->fetchrow_array) { $role = $row_18[0]; ++$rowCount; }

Are you using the while loop to get the last record of many ?

poj

Replies are listed 'Best First'.
Re^3: DBD::Sybase $sth->rows returns -1
by Perl300 (Friar) on Jan 06, 2016 at 22:08 UTC
    Thank you for your suggestion poj.

    I am using while loop to get all the fetched records. In select queries I am using your suggestion where ever possible or else writing another query with select count(*)

    But even in case of UPDATE queries I am getting -1 for $sth->rows and trying to figure out how to handle that.

      For non-select statements you could use

      my $rowCount = $dbh->do($statement);

      see do

      poj
      Please remove the COMMIT and give a feedback ;)

      Edit
      Please change your execute with this one :)
      $sth18->execute($userName) or die "Couldn't execute statement: " . $st +h18->errstr;
      Execute returns a true value if it succeeds and a false value otherwise, so we abort if for some reason the execution fails.

      Another important thing is that Rows method is database-driver specific, so it might not work in other drivers, or it might work differently in other drivers.