Metainformationen einer Datenbank II

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]

tables.pl
my @tables = ();
my $st = $db->prepare("show tables");
$st->execute;
my $record;
while (defined($record = $st->fetch())) {
   push(@tables, $record->[0]);
}
$st->finish;

foreach my $table (@tables) {
   $st = $db->prepare("show columns from $table");
   $st->execute;
   my @fields = (); my @pkey = ();
   while (defined($record = $st->fetchrow_hashref())) {
      if (defined($record->{'Key'}) &&
          $record->{'Key'} eq "PRI") {
         push(@pkey, $record->{'Field'});
      } else {
         push(@fields, $record->{'Field'});
      }
   }
   print "$table: ";
   print "primary key = (", join(", ", @pkey), "), "
      if @pkey > 0;
   print "other fields = (", join(", ", @fields), ")\n";
}
$st->finish;

$db->disconnect;

 [Vorheriges Kapitel]  [Vorherige Seite]  [Inhaltsverzeichnis]  [Nächste Seite]  [Nächstes Kapitel]
Copyright © 1996, 1998, 1999, 2000 Andreas Borchert, in HTML konvertiert am 07.02.2000