Skip to content

Commit

Permalink
Fixed column_info's return value order.
Browse files Browse the repository at this point in the history
DBI.pm's pod says
> The result set is ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME and
> ORDINAL_POSITION.

ref. https://github.com/CaptTofu/DBD-mysql/issues/16
  • Loading branch information
tokuhirom committed Aug 9, 2012
1 parent fd02489 commit 0bd2d36
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/DBD/mysql.pm
Expand Up @@ -452,6 +452,7 @@ sub column_info {
}

my $ordinal_pos = 0;
my @fields;
for my $row (@$desc)
{
my $type = $row->{type};
Expand All @@ -460,6 +461,7 @@ sub column_info {
my $typemod = $2;
my $attr = $3;

push @fields, $row->{field};
my $info = $col_info{ $row->{field} }= {
TABLE_CAT => $catalog,
TABLE_SCHEM => $schema,
Expand Down Expand Up @@ -583,7 +585,7 @@ sub column_info {
return $dbh->DBI::set_err($DBI::err, "DBI::Sponge: $DBI::errstr"));

my $sth = $sponge->prepare("column_info $table", {
rows => [ map { [ @{$_}{@names} ] } values %col_info ],
rows => [ map { [ @{$_}{@names} ] } map { $col_info{$_} } @fields ],
NUM_OF_FIELDS => scalar @names,
NAME => \@names,
}) or
Expand Down
9 changes: 8 additions & 1 deletion t/40catalog.t
Expand Up @@ -22,7 +22,7 @@ eval {$dbh= DBI->connect($test_dsn, $test_user, $test_password,
if ($@) {
plan skip_all => "ERROR: $DBI::errstr. Can't continue test";
}
plan tests => 77;
plan tests => 78;

ok(defined $dbh, "connecting");

Expand Down Expand Up @@ -281,6 +281,13 @@ SKIP: {
($info)= $sth->fetchall_arrayref({});
is(scalar @$info, 1);

#
# The result set is ordered by TABLE_CAT, TABLE_SCHEM, TABLE_NAME and ORDINAL_POSITION.
#
$sth= $dbh->column_info(undef, undef, "t1", undef);
my ($info)= $sth->fetchall_arrayref({});
is(join(' ++ ', map { $_->{COLUMN_NAME} } @{$info}), "a ++ b ++ a_ ++ a'b ++ bar");

ok($dbh->do(qq{DROP TABLE IF EXISTS t1}), "cleaning up");
$dbh->disconnect();
};
Expand Down

0 comments on commit 0bd2d36

Please sign in to comment.