Skip to content

Instantly share code, notes, and snippets.

@DrHyde
Created February 19, 2015 16:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DrHyde/025ba250c13cdb37fd16 to your computer and use it in GitHub Desktop.
Save DrHyde/025ba250c13cdb37fd16 to your computer and use it in GitHub Desktop.
Work-around for the UTF-8 bug in DBD::mysql
# We found that we could successfully write ASCII to the db, and the ij-ligature,
# and the unicode snowman, and the unicode pile of poo, and text that included
# i-acute and a pile of poo. But we couldn't write just an i-acute.
#
# This is apparently a long-standing and unfixable bug in DBD::mysql
# (see https://rt.cpan.org/Public/Bug/Display.html?id=60987)
#
# This patches DBIx::Class::Storage::DBI to work around the problem.
# It's based on https://gist.github.com/anonymous/c19af1e80dcf7272e6c5
# but we're already monkey-patching DBIx::Class::Storage::DBI::_dbh_execute
# elsewhere in our code, so it makes sense to keep the unmaintainable
# insanity all locked up in one small box
use DBIx::Class::Storage::DBI;
my $old_ex = \&DBIx::Class::Storage::DBI::_dbh_execute;
my $new_ex = sub {
# we need to mangle $bind:
# my ($self, $dbh, $sql, $bind, $bind_attrs) = @_;
#
# It looks like ...
# [
# ...
# [
# {
# dbic_colname => 'message'
# },
# 'some data with funny foreign characters in it like í',
# ],
# [
# {
# dbic_colname => 'method'
# },
# undef,
# ],
# ...
# ]
# and we need to edit it in place
foreach (@{$_[3]}) {
if(exists($_->[1]) && defined($_->[1])) {
utf8::upgrade($_->[1])
}
}
return $old_ex->(@_);
};
@DrHyde
Copy link
Author

DrHyde commented Feb 19, 2015

Hasn't yet been particularly thoroughly tested. But it appears to not make the universe explode when I INSERT and then SELECT data with funny foreign characters in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment