Skip to content

Commit 4956108

Browse files
authored
Add support for compression algorighm selection (#372)
1 parent 63a83d6 commit 4956108

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

dbdimp.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,11 +1233,13 @@ MYSQL *mysql_dr_connect(
12331233
if ((svp = hv_fetch(hv, "mysql_compression", 17, FALSE)) &&
12341234
*svp && SvTRUE(*svp))
12351235
{
1236+
char* calg = SvPV(*svp, lna);
1237+
if (strncmp(calg,"1",1) == 0) calg="zlib";
12361238
if (DBIc_TRACE_LEVEL(imp_xxh) >= 2)
12371239
PerlIO_printf(DBIc_LOGPIO(imp_xxh),
12381240
"imp_dbh->mysql_dr_connect: Enabling" \
1239-
" compression.\n");
1240-
mysql_options(sock, MYSQL_OPT_COMPRESS, NULL);
1241+
" compression algorithms: %s\n", calg);
1242+
mysql_options(sock, MYSQL_OPT_COMPRESSION_ALGORITHMS, calg);
12411243
}
12421244
if ((svp = hv_fetch(hv, "mysql_connect_timeout", 21, FALSE))
12431245
&& *svp && SvTRUE(*svp))

lib/DBD/mysql.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,8 +1060,12 @@ specify "mysql_client_found_rows=0" in the DSN.
10601060
10611061
=item mysql_compression
10621062
1063-
If your DSN contains the option "mysql_compression=1", then the communication
1064-
between client and server will be compressed.
1063+
If your DSN contains the option "mysql_compression", then this will be used
1064+
to set the compression algorithms for the connection.
1065+
1066+
If your DSN contains the option "mysql_compression=1", then the compression
1067+
algorithms will be set to "zlib". This is for backwards compatibility with
1068+
older versions of DBD::mysql.
10651069
10661070
=item mysql_connect_timeout
10671071

t/99compression.t

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More;
5+
use DBI;
6+
use lib 't', '.';
7+
require 'lib.pl';
8+
9+
foreach my $compression ( "zlib", "zstd", "0", "1" ) {
10+
my ($dbh, $sth, $row);
11+
use vars qw($test_dsn $test_user $test_password);
12+
13+
eval {$dbh = DBI->connect($test_dsn . ";mysql_compression=$compression", $test_user, $test_password,
14+
{ RaiseError => 1, AutoCommit => 1});};
15+
16+
ok ($sth= $dbh->prepare("SHOW SESSION STATUS LIKE 'Compression_algorithm'"));
17+
18+
ok $sth->execute();
19+
20+
ok ($row= $sth->fetchrow_arrayref);
21+
22+
my $exp = $compression;
23+
if ($exp eq "1") { $exp = "zlib" };
24+
if ($exp eq "0") { $exp = "" };
25+
cmp_ok $row->[1], 'eq', $exp, "\$row->[1] eq $exp";
26+
27+
ok $sth->finish;
28+
}
29+
30+
plan tests => 4*5;

0 commit comments

Comments
 (0)