Skip to content

Commit 63a83d6

Browse files
authored
Correct handling of mysql_enable_utf8mb4 (#363)
* Correct handling of mysql_enable_utf8mb4 Depending on where in the DSN `mysql_enable_utf8mb4` was specified it would set `imp_dbh->enable_utf8mb4` or not. But it would always call `mysql_options()` to set the charset. This commit makes sure `imp_dbh->enable_utf8mb4` is set consistently. Closes #360
1 parent b31707d commit 63a83d6

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

dbdimp.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,7 @@ MYSQL *mysql_dr_connect(
13881388

13891389
if ((svp = hv_fetch(hv, "mysql_enable_utf8mb4", 20, FALSE)) && *svp && SvTRUE(*svp)) {
13901390
mysql_options(sock, MYSQL_SET_CHARSET_NAME, "utf8mb4");
1391+
imp_dbh->enable_utf8mb4 = TRUE;
13911392
}
13921393
else if ((svp = hv_fetch(hv, "mysql_enable_utf8", 17, FALSE)) && *svp) {
13931394
/* Do not touch imp_dbh->enable_utf8 as we are called earlier

t/gh360.t

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More;
5+
use DBI;
6+
use lib 't', '.';
7+
require 'lib.pl';
8+
9+
my ($dbhA, $dbhB);
10+
use vars qw($test_dsn $test_user $test_password);
11+
12+
my $dsnA = $test_dsn . ';mysql_enable_utf8mb4=1';
13+
eval {$dbhA = DBI->connect($dsnA, $test_user, $test_password,
14+
{ RaiseError => 1, AutoCommit => 1});};
15+
16+
my $dsnB = $test_dsn;
17+
$dsnB =~ s/DBI:mysql/DBI:mysql(mysql_enable_utf8mb4=1)/;
18+
eval {$dbhB = DBI->connect($dsnB . ';mysql_enable_utf8mb4=1', $test_user, $test_password,
19+
{ RaiseError => 1, AutoCommit => 1});};
20+
21+
plan tests => 2;
22+
23+
ok($dbhA->{mysql_enable_utf8mb4} == 1, 'mysql_enable_utf8mb4 == 1 with regular DSN');
24+
25+
ok($dbhB->{mysql_enable_utf8mb4} == 1, 'mysql_enable_utf8mb4 == 1 with driver DSN');

0 commit comments

Comments
 (0)