4
# $Id: 40blobs.t 11244 2008-05-11 15:13:10Z capttofu $
6
# This is a test for correct handling of BLOBS; namely $dbh->quote
7
# is expected to work correctly.
13
use vars qw($table $test_dsn $test_user $test_password);
19
for ($i = 0; $i < 8; $i++) {
20
if (defined($blob) && length($blob) > $i) {
21
$b = substr($blob, $i*32);
26
printf("%08lx %s\n", $i*32, unpack("H64", $b));
31
eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,
32
{ RaiseError => 1, AutoCommit => 1}) or ServerError() ;};
35
plan skip_all => "ERROR: $DBI::errstr. Can't continue test";
41
ok $dbh->do("DROP TABLE IF EXISTS $table"), "Drop table if exists $table";
45
id INT(3) NOT NULL DEFAULT 0,
46
name BLOB ) DEFAULT CHARSET=utf8
49
ok ($dbh->do($create));
51
my ($blob, $qblob) = "";
53
for ($j = 0; $j < 256; $j++) {
56
for ($i = 0; $i < $size; $i++) {
59
ok ($qblob = $dbh->quote($blob));
61
# Insert a row into the test table.......
63
$query = "INSERT INTO $table VALUES(1, $qblob)";
64
ok ($dbh->do($query));
66
# Now, try SELECT'ing the row out.
67
ok ($sth = $dbh->prepare("SELECT * FROM $table WHERE id = 1"));
71
ok ($row = $sth->fetchrow_arrayref);
73
ok defined($row), "row returned defined";
75
is @$row, 2, "records from $table returned 2";
77
is $$row[0], 1, 'id set to 1';
79
cmp_ok byte_string($$row[1]), 'eq', byte_string($blob), 'blob set equal to blob returned';
81
ShowBlob($blob), ShowBlob(defined($$row[1]) ? $$row[1] : "");
85
ok $dbh->do("DROP TABLE $table"), "Drop table $table";