Subject: | sth->rows() returns incorrect values with mysqlPP.pm |
Description
===========
The ->rows() method called on a statement handle returns incorrect value. In my testing, I have seen it return 0 in many cases, but also 1.
Repro
=====
Tested on Windows 2000 with Activestate build 633, Perl v5.6.1. Local mysql server 3.23.55-nt. Tested with both 0.03 and 0.04 of mysqlPP.pm. Using latest Net::MySQL version 0.08
#!/usr/bin/perl -W
use strict;
use warnings;
use DBI;
my $root_user = 'sa';
my $root_pass = 'Sex';
&do_test("mysql");
&do_test("mysqlPP");
sub do_test {
my($driver) = shift;
print "Driver: $driver\n";
my($dbh) = DBI -> connect
(
"DBI:$driver:test:127.0.0.1", $root_user, $root_pass,
{
AutoCommit => 1,
LongReadLen => 150_000,
LongTruncOk => 0,
PrintError => 0,
RaiseError => 1,
ShowErrorStatement => 1,
}
);
eval{$dbh -> do('drop table ttable')};
my($sql) = "create table ttable (b_value blob)";
$dbh -> do($sql);
$sql = 'insert into ttable (b_value) values (?)';
my($sth) = $dbh -> prepare($sql);
my $MAX = 10;
for (1..$MAX) {
$sth->execute($_);
}
$sth->finish();
$sql = 'select b_value from ttable';
$sth = $dbh -> prepare($sql);
$sth -> execute();
my $rows = $sth->rows();
print "Found $rows rows (expected $MAX) with driver $driver\n";
$sth -> finish();
$dbh->disconnect;
}
# (example code based on lairdshaw@hotmail.com )
Show quoted text
--- prints ---
E:\>\test2.pl
Driver: mysql
Found 10 rows (expected 10) with driver mysql
Driver: mysqlPP
Found 1 rows (expected 10) with driver mysqlPP
Severity
========
This bug broke every SQL script I had. I was using ->rows() in a conditional to decide whether to print a table of data or give a "no data present" message, and ->rows() was always returning the wrong value and forcing the wrong branch.
mysqlPP.pm is now installed by default with ActiveState, and DBD::mysql is not. mysqlPP needs to be at least as bug-free as DBD::mysql was