Subject: | Incorrect retrieval of binary BLOB data |
The mysqlPP driver returns truncated/incorrect BLOB field data when the BLOB data is binary. It seems to be OK with text data (except for '/'s, another apparent bug.
This bug occurred with the following setups
1)
OS: Windows 95
mysql server version 3.23.54 (running on the same machine as the scripts)
Perl v5.8.0 from ActiveState
DBI version 1.30
DBD::mysqlPP version 0.03
2)
OS: Windows 95
mysql server version 3.23.54 (running on the same machine as the scripts)
Perl v5.6.1 build 633 from ActiveState
DBI version 1.32
DBD::mysqlPP version 0.03
The script that follows is a cut-down version of code provided by Ron Savage on the dbi-users mailing list.
Show quoted text
-----Begin Demonstration code-----
use strict;
use warnings;
use DBI;
my $input_file_name = 'c:\file0003.chk';
my $rootpassword;
&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', $rootpassword,
{
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);
open(INX, $input_file_name) || die("Can't open($input_file_name): $!");
binmode INX;
print "File name: $input_file_name. \n";
print "Blob file size: ", -s INX, " bytes.\n";
my($blob);
{
local $/ = undef;
$blob = <INX>;
close INX;
}
print "Blob ram size: ", length($blob), " bytes.\n";
$sth -> execute($blob);
$sth -> finish();
$sql = 'select b_value from ttable';
$sth = $dbh -> prepare($sql);
$sth -> execute();
$blob = $sth -> fetch();
$blob = $$blob[0];
$sth -> finish();
print "Blob db size: ", length($blob), " bytes.\n";
$dbh->disconnect;
}
-----End Demonstration code-----
-----Begin Results-----
Driver: mysql
File name: c:\file0003.chk.
Blob file size: 49152 bytes.
Blob ram size: 49152 bytes.
Blob db size: 49152 bytes.
Driver: mysqlPP
File name: c:\file0003.chk.
Blob file size: 49152 bytes.
Blob ram size: 49152 bytes.
Blob db size: 49137 bytes.
-----End Results-----
Notice that the final Blob db size is not correct.