[Dbix-class] Monkey-patching around a MySQL/UTF8 bug

David Cantrell david at cantrell.org.uk
Thu Feb 26 14:43:33 GMT 2015


This bug in DBD::mysql is apparently not going to be fixed:
  https://rt.cpan.org/Ticket/Display.html?id=60987

and it's preventing us from inserting, eg, an i-acute character into our
database. Our customer Mr. García is Quite Irritated at this. It appears
that any non-ASCII character with code-point below 0x100 is affected
(higher codepoints like ij and ψ and ☃ are OK). As a work-around I've
done this in my application:

BEGIN {
    my $old_ex = \&DBIx::Class::Storage::DBI::_dbh_execute;
    my $new_ex = sub {
        foreach (@{$_[3]}) {
            if(exists($_->[1]) && defined($_->[1])) {
                utf8::upgrade($_->[1])
            }
        }
        return $old_ex->(@_);
    };

    {
        no strict qw/ refs /;
        no warnings 'redefine';
        *DBIx::Class::Storage::DBI::_dbh_execute = $new_ex;
    }
}

And it appears to work. However, I don't like monkey-patching like that.
Is there a better way that I haven't been able to find in the
DBIx::Class doco?

-- 
David Cantrell | Hero of the Information Age

  Sobol's Law of Telecom Utilities:
    Telcos are malicious; cablecos are simply clueless.



More information about the DBIx-Class mailing list