Skip to content

Commit

Permalink
implement statistics_info $unique_only
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 authored and dveeden committed Sep 18, 2024
1 parent c68916f commit 684ffee
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/DBD/mysql.pm
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,11 @@ EOF
push @bind, $table;
}

if ($unique_only) {
push @where, 'NON_UNIQUE = ?';
push @bind, 0;
}

if (@where) {
$sql .= ' WHERE ';
$sql .= join ' AND ', @where;
Expand Down
11 changes: 10 additions & 1 deletion t/40keyinfo.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
if ($@) {
plan skip_all => "no database connection";
}
plan tests => 7;

$dbh->{mysql_server_prepare}= 0;

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

$sth= $dbh->statistics_info(undef, undef, 'dbd_mysql_keyinfo', 0, 0);
my $stats_info = $sth->fetchall_arrayref;
my $n_unique = grep $_->[3], @$stats_info;
$sth= $dbh->statistics_info(undef, undef, 'dbd_mysql_keyinfo', 1, 0);
$stats_info = $sth->fetchall_arrayref;
my $n_unique2 = grep $_->[3], @$stats_info;
isnt($n_unique2, $n_unique, "Check statistics_info unique_only flag has an effect");

ok($dbh->do("DROP TABLE dbd_mysql_keyinfo"), "Dropped table");

$dbh->disconnect();

done_testing;

0 comments on commit 684ffee

Please sign in to comment.