| Bug #26786 | primary_key_info() returns info on non-primary indexes | ||
|---|---|---|---|
| Submitted: | 2 Mar 2007 7:41 | Modified: | 3 Mar 2007 1:36 |
| Reporter: | Dave Rolsky | Email Updates: | |
| Status: | Closed | Impact on me: | |
| Category: | Connectors: DBD::mysql ( Perl ) | Severity: | S3 (Non-critical) |
| Version: | 4.001 | OS: | |
| Assigned to: | Jim Winstead | CPU Architecture: | Any |
[2 Mar 2007 9:05]
Sveta Smirnova
test case
Attachment: bug26786.pl (text/plain), 667 bytes.
[2 Mar 2007 9:07]
Sveta Smirnova
Thank you for the report. Verified as described.
[3 Mar 2007 1:36]
Jim Winstead
Fix committed to the DBD::mysql repository. Thanks for the report.

Description: See description How to repeat: To replicate, just look at the return values of primary_key_info() on a table with a non-primary index. For example: CREATE TABLE UserGroup ( user_id integer primary key, group_id integer primary_key, index(group_id) ); (Not sure if that's 100% the right SQL, but you get the idea) Suggested fix: --- lib/DBD/mysql.pm~ 2007-03-01 16:34:46.000000000 -0600 +++ lib/DBD/mysql.pm 2007-03-02 01:38:31.000000000 -0600 @@ -546,7 +546,7 @@ my $desc_sth = $dbh->prepare("SHOW KEYS FROM $table_id"); my $desc = $dbh->selectall_arrayref($desc_sth, { Columns=>{} }); my $ordinal_pos = 0; - foreach my $row (@$desc) { + foreach my $row (grep { $_->{key_name} eq 'PRIMARY'} @$desc) { $col_info{ $row->{column_name} } = { TABLE_CAT => $catalog, TABLE_SCHEM => $schema,