Subject: | primary_key_info fails to return names for named primary keys |
Date: | Fri, 9 May 2014 13:00:47 -0600 |
To: | <bug-DBD-SQLite [...] rt.cpan.org> |
From: | Kenneth Kroenlein <kenneth.kroenlein [...] nist.gov> |
Feature request:
For DBD::SQLite, v. 1.40 and v.142, all calls to primary_key_info return
the name of the primary key to be 'PRIMARY KEY', despite SQLite
supporting named constraints. Modifying the lines that read (start 453
in v.1.40):
my $key_seq = 0;
foreach my $pk_field (@pk) {
push @pk_info, {
TABLE_SCHEM => $dbname,
TABLE_NAME => $tbname,
COLUMN_NAME => $pk_field,
KEY_SEQ => ++$key_seq,
PK_NAME => 'PRIMARY KEY',
};
}
to
my $key_name = $row->{sql} =~
/\bCONSTRAINT\s+(\S+|"[^"]+")\s+PRIMARY\s+KEY\s*\(/i ? $1 : 'PRIMARY KEY';
my $key_seq = 0;
foreach my $pk_field (@pk) {
push @pk_info, {
TABLE_SCHEM => $dbname,
TABLE_NAME => $tbname,
COLUMN_NAME => $pk_field,
KEY_SEQ => ++$key_seq,
PK_NAME => $key_name,
};
}
should correct the oversight and should be quite robust (barring some
fairly pathological conditions).
Thanks,
Ken