in reply to DBI determine primary key

I'm not sure if the DBI primary_key methods are implemented in DBD::mysql. There is a MySQL-specific way to find the keys using $sth->{mysql_is_pri_key} like so:

#!perl -w use strict; use DBI; my($db,$table)=('test','tmp1'); my $dbh=DBI->connect("dbi:mysql(RaiseError=1):dbname=$db"); $dbh->do(qq/DROP TABLE IF EXISTS $table/); $dbh->do(qq/CREATE TABLE $table (id INTEGER PRIMARY KEY, name VARCHAR( +10))/); for my $field(qw( id name )) { my $sth = $dbh->prepare("SELECT $field FROM $table WHERE 1=0"); $sth->execute; for my $k($sth->{'mysql_is_pri_key'}) { my $n = 'IS'; $n .= " NOT" unless $k->[0]; print "$field $n A PRIMARY KEY\n"; } $sth->finish; } $dbh->do(qq/DROP TABLE $table/); $dbh->disconnect;