Skip to content

Commit

Permalink
Fix primary_key_info result ordering
Browse files Browse the repository at this point in the history
DBI documentation says

> The statement handle will return one row per column, ordered by
> TABLE_CAT, TABLE_SCHEM, TABLE_NAME, and KEY_SEQ.

But since we're only querying one table the three first ones are by
definition the same, so it's only necessary to sort by KEY_SEQ.

This happened to come out in the same order on previous versions of
perl, but as of 5.17.10, hash insertion and traversal order is more
randomised, so now it fails mos of the time.
  • Loading branch information
ilmari committed Mar 24, 2013
1 parent 6e75c2e commit 2ff0f35
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/DBD/mysql.pm
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,11 @@ sub primary_key_info {
return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr"));

my $sth= $sponge->prepare("primary_key_info $table", {
rows => [ map { [ @{$_}{@names} ] } values %col_info ],
rows => [
map { [ @{$_}{@names} ] }
sort { $a->{KEY_SEQ} <=> $b->{KEY_SEQ} }
values %col_info
],
NUM_OF_FIELDS => scalar @names,
NAME => \@names,
}) or
Expand Down

0 comments on commit 2ff0f35

Please sign in to comment.