|
| 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