in reply to DBI determine primary key
And here's some demo code checking what we've got:CREATE TABLE foo( id int(10) unsigned NOT NULL AUTO_INCREMENT, letter char(1) NOT NULL, name text NOT NULL, num float NULL, PRIMARY KEY (id) );
#!/usr/local/bin/perl -w use DBI; my $dbh = DBI->connect('dbi:mysql:test', "", "", { PrintError => 0 , R +aiseError => 1}); END { $dbh->disconnect if $dbh } use Data::Dumper; my $sth = $dbh->prepare('DESCRIBE foo'); $sth->execute; while(my $r = $sth->fetchrow_hashref) { print Dumper $r; }
$VAR1 = { 'Extra' => 'auto_increment', 'Field' => 'id', 'Default' => undef, 'Key' => 'PRI', 'Type' => 'int(10) unsigned', 'Null' => '' }; $VAR1 = { 'Extra' => '', 'Field' => 'letter', 'Default' => '', 'Key' => '', 'Type' => 'char(1)', 'Null' => '' }; $VAR1 = { 'Extra' => '', 'Field' => 'name', 'Default' => '', 'Key' => '', 'Type' => 'text', 'Null' => '' }; $VAR1 = { 'Extra' => '', 'Field' => 'num', 'Default' => undef, 'Key' => '', 'Type' => 'float', 'Null' => 'YES' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: DBI determine primary key
by Anonymous Monk on Apr 09, 2004 at 02:37 UTC |