Skip to content

Commit 5096566

Browse files
committed
Merge pull request #178
Add test for large BLOB with parameter
2 parents be52823 + f141379 commit 5096566

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

MANIFEST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ t/35prepare.t
3434
t/40bindparam.t
3535
t/40bindparam2.t
3636
t/40bit.t
37+
t/40blobslarge.t
3738
t/40blobs.t
3839
t/40catalog.t
3940
t/40invalid_attributes.t

t/40blobslarge.t

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More;
5+
use DBI;
6+
use vars qw($test_dsn $test_user $test_password);
7+
use lib '.', 't';
8+
require 'lib.pl';
9+
10+
my $dbh = DbiTestConnect($test_dsn, $test_user, $test_password,
11+
{ RaiseError => 1, PrintError => 0 });
12+
13+
plan tests => 15;
14+
15+
# BLOB maximum size on MariaDB is 65,535
16+
# LONGBLOB maximum size is 4 GB
17+
# but effective maximum length of LONGBLOB columns depends
18+
# configured maximum packet size and available memory.
19+
#
20+
# We test with 512k which should go through on older
21+
# MySQL and MariaDB
22+
my $size = (1024 * 512);
23+
24+
ok $dbh->do("DROP TABLE IF EXISTS dbd_mysql_t40blobslarge"), "Drop table if exists dbd_mysql_t40blobslarge";
25+
26+
my $create = <<EOT;
27+
CREATE TABLE dbd_mysql_t40blobslarge (
28+
id INT(3) NOT NULL DEFAULT 0,
29+
name LONGBLOB )
30+
EOT
31+
32+
ok ($dbh->do($create));
33+
34+
my ($blob, $qblob) = "";
35+
my $b = "";
36+
37+
my @out = ( );
38+
my $chr = 0;
39+
40+
# Create little bit random
41+
# byte string
42+
for( 1..$size ) {
43+
if($chr >= 255)
44+
{
45+
$chr = 0;
46+
}
47+
48+
push @out, chr($chr ++);
49+
}
50+
51+
$blob = join '', @out;
52+
53+
my $sth = undef;
54+
55+
# Insert a row into the test table.......
56+
my $query = "INSERT INTO dbd_mysql_t40blobslarge VALUES(?, ?)";
57+
58+
ok ($sth = $dbh->prepare( $query ));
59+
60+
# See https://metacpan.org/dist/DBD-MariaDB/view/lib/DBD/MariaDB.pod#Binary-parameters
61+
ok ($sth->bind_param(1, 1, DBI::SQL_INTEGER), "Bind 1 to first param");
62+
ok ($sth->bind_param(2, $blob, DBI::SQL_BINARY), "Bind BLOB to second param");
63+
64+
ok ($sth->execute(), "Execute INSERT statement");
65+
66+
# Now, try SELECT'ing the row out.
67+
ok ($sth = $dbh->prepare("SELECT * FROM dbd_mysql_t40blobslarge WHERE id = 1"));
68+
69+
ok ($sth->execute(), "Execute SELECT statement");
70+
71+
ok (my $row = $sth->fetchrow_arrayref);
72+
73+
ok (defined($row), "row returned defined");
74+
75+
is (@$row, 2, "records from dbd_mysql_t40blobslarge returned 2");
76+
77+
is ($$row[0], 1, 'id set to 1');
78+
79+
cmp_ok byte_string($$row[1]), 'eq', byte_string($blob), 'Original blob set equal to blob returned';
80+
81+
ok ($dbh->do("DROP TABLE dbd_mysql_t40blobslarge"), "Drop table dbd_mysql_t40blobslarge");
82+
83+
ok ($dbh->disconnect);

0 commit comments

Comments
 (0)