From 120da5e35f04fd5365392b71a1079987a1ecede4 Mon Sep 17 00:00:00 2001 From: Dave Lambley Date: Tue, 10 Dec 2024 14:11:54 +0000 Subject: [PATCH 1/4] Test whether a BLOB can be round-tripped When a BLOB type bound parameter is sent to MariaDB (or MySQL for that matter) over the socket, UTF-8 is not used. This test will therefore fail unless the database driver is given the correct type when transmitting the data. --- t/01-operations.t | 14 +++++++++++++- t/lib/MyApp/Schema.pm | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/t/01-operations.t b/t/01-operations.t index d882c87..d5ca3d0 100644 --- a/t/01-operations.t +++ b/t/01-operations.t @@ -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"); @@ -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; diff --git a/t/lib/MyApp/Schema.pm b/t/lib/MyApp/Schema.pm index 6a2b9e5..2da4a61 100644 --- a/t/lib/MyApp/Schema.pm +++ b/t/lib/MyApp/Schema.pm @@ -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'] ); From 1cd087250dff900d12bed585c7670ca0f963d7f6 Mon Sep 17 00:00:00 2001 From: Dave Lambley Date: Tue, 10 Dec 2024 14:42:42 +0000 Subject: [PATCH 2/4] Use correct bind type for BLOB fields --- Makefile.PL | 1 + lib/DBIx/Class/Storage/DBI/MariaDB.pm | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Makefile.PL b/Makefile.PL index 446ceb5..e1b3121 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -24,6 +24,7 @@ WriteMakefile( PREREQ_PM => { 'DBD::MariaDB' => '>= 1.00', 'DBIx::Class' => '>= 0.082820', + 'DBI' => 0, }, TEST_REQUIRES => { 'Test::More' => 0, diff --git a/lib/DBIx/Class/Storage/DBI/MariaDB.pm b/lib/DBIx/Class/Storage/DBI/MariaDB.pm index 8a76685..155a0a1 100644 --- a/lib/DBIx/Class/Storage/DBI/MariaDB.pm +++ b/lib/DBIx/Class/Storage/DBI/MariaDB.pm @@ -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'; @@ -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 From f838626b7dbb8ba3a0f05ddf9800e71dc5b556e5 Mon Sep 17 00:00:00 2001 From: Dave Lambley Date: Tue, 10 Dec 2024 20:26:25 +0000 Subject: [PATCH 3/4] Add changelog and declare perl version Fixes Kwalitee objections. Perl 5.8.9 determined by CPAN Testers. --- Changes | 5 +++++ Makefile.PL | 1 + 2 files changed, 6 insertions(+) create mode 100644 Changes diff --git a/Changes b/Changes new file mode 100644 index 0000000..06f530e --- /dev/null +++ b/Changes @@ -0,0 +1,5 @@ + * Pass BLOBs correctly. + * Make Kwalitee happier. + +0.1.0 + * Initial CPAN release. diff --git a/Makefile.PL b/Makefile.PL index e1b3121..d8c7857 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -25,6 +25,7 @@ WriteMakefile( 'DBD::MariaDB' => '>= 1.00', 'DBIx::Class' => '>= 0.082820', 'DBI' => 0, + 'perl' => '>= 5.8.9', }, TEST_REQUIRES => { 'Test::More' => 0, From 1edcd6b4c39e5ba708b670d7eb3a40bf070199de Mon Sep 17 00:00:00 2001 From: Dave Lambley Date: Tue, 10 Dec 2024 20:29:25 +0000 Subject: [PATCH 4/4] Add myself --- Makefile.PL | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile.PL b/Makefile.PL index d8c7857..052f63a 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -19,6 +19,9 @@ WriteMakefile( web => "https://github.com/Siemplexus/DBIx-Class-Storage-DBI-MariaDB/issues", }, }, + x_contributors => [ + 'Dave Lambley ', + ], }, VERSION_FROM => "lib/DBIx/Class/Storage/DBI/MariaDB.pm", PREREQ_PM => {