Created
February 19, 2015 16:26
-
-
Save DrHyde/025ba250c13cdb37fd16 to your computer and use it in GitHub Desktop.
Work-around for the UTF-8 bug in DBD::mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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->(@_); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.