Skip to content

Commit

Permalink
Merge pull request #5 from davel/davel/blob
Browse files Browse the repository at this point in the history
BLOB fields get corrupted
  • Loading branch information
antoniskalou authored Dec 11, 2024
2 parents db2a8cb + 1edcd6b commit 128e537
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* Pass BLOBs correctly.
* Make Kwalitee happier.

0.1.0
* Initial CPAN release.
5 changes: 5 additions & 0 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ WriteMakefile(
web => "https://github.com/Siemplexus/DBIx-Class-Storage-DBI-MariaDB/issues",
},
},
x_contributors => [
'Dave Lambley <[email protected]>',
],
},
VERSION_FROM => "lib/DBIx/Class/Storage/DBI/MariaDB.pm",
PREREQ_PM => {
'DBD::MariaDB' => '>= 1.00',
'DBIx::Class' => '>= 0.082820',
'DBI' => 0,
'perl' => '>= 5.8.9',
},
TEST_REQUIRES => {
'Test::More' => 0,
Expand Down
8 changes: 8 additions & 0 deletions lib/DBIx/Class/Storage/DBI/MariaDB.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package DBIx::Class::Storage::DBI::MariaDB;
use strict;
use warnings;

use DBI;
use base qw/DBIx::Class::Storage::DBI/;

our $VERSION = '0.1.0';
Expand Down Expand Up @@ -173,6 +174,13 @@ sub lag_behind_master {
->{Seconds_Behind_Master};
}

sub bind_attribute_by_data_type {
if ( $_[1] = ~ /^(?:tiny|medium|long)blob$/i ) {
return DBI::SQL_BINARY;
}
return;
}

1;

=head1 NAME
Expand Down
14 changes: 13 additions & 1 deletion t/01-operations.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ $dbh->do(
artistid INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
rank INTEGER NOT NULL DEFAULT 13,
charfield CHAR(10)
charfield CHAR(10),
picture MEDIUMBLOB
)"
);
$dbh->do("DROP TABLE IF EXISTS owner");
Expand Down Expand Up @@ -399,4 +400,15 @@ subtest 'mariadb_auto_reconnect' => sub {
ok( $rs->find( { name => "test" } ), 'Expected row created' );
};

subtest 'blob round trip' => sub {
my $new =
$schema->resultset('Artist')->create( { name => 'blob round trip', picture => "\302\243" } );
ok( $new->artistid, 'Auto-PK worked' );

my $artist2_rs =
$schema->resultset('Artist')->search( { artistid => $new->artistid } );

is($artist2_rs->single->picture, "\302\243", "Round-tripped a blob");
};

done_testing;
4 changes: 4 additions & 0 deletions t/lib/MyApp/Schema.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ __PACKAGE__->add_columns(
size => 10,
is_nullable => 1,
},
picture => {
data_type => 'MEDIUMBLOB',
is_nullable => 1,
},
);
__PACKAGE__->set_primary_key('artistid');
__PACKAGE__->add_unique_constraint( ['name'] );
Expand Down

0 comments on commit 128e537

Please sign in to comment.