Skip to content

Commit 684ffee

Browse files
mohawk2dveeden
authored andcommitted
implement statistics_info $unique_only
1 parent c68916f commit 684ffee

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/DBD/mysql.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,11 @@ EOF
755755
push @bind, $table;
756756
}
757757

758+
if ($unique_only) {
759+
push @where, 'NON_UNIQUE = ?';
760+
push @bind, 0;
761+
}
762+
758763
if (@where) {
759764
$sql .= ' WHERE ';
760765
$sql .= join ' AND ', @where;

t/40keyinfo.t

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
1515
if ($@) {
1616
plan skip_all => "no database connection";
1717
}
18-
plan tests => 7;
1918

2019
$dbh->{mysql_server_prepare}= 0;
2120

@@ -42,6 +41,16 @@ is_deeply($key_info, $expect, "Check primary_key_info results");
4241
is_deeply([ $dbh->primary_key(undef, undef, 'dbd_mysql_keyinfo') ], [ 'a', 'b' ],
4342
"Check primary_key results");
4443

44+
$sth= $dbh->statistics_info(undef, undef, 'dbd_mysql_keyinfo', 0, 0);
45+
my $stats_info = $sth->fetchall_arrayref;
46+
my $n_unique = grep $_->[3], @$stats_info;
47+
$sth= $dbh->statistics_info(undef, undef, 'dbd_mysql_keyinfo', 1, 0);
48+
$stats_info = $sth->fetchall_arrayref;
49+
my $n_unique2 = grep $_->[3], @$stats_info;
50+
isnt($n_unique2, $n_unique, "Check statistics_info unique_only flag has an effect");
51+
4552
ok($dbh->do("DROP TABLE dbd_mysql_keyinfo"), "Dropped table");
4653

4754
$dbh->disconnect();
55+
56+
done_testing;

0 commit comments

Comments
 (0)