1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#!/usr/bin/perl -w -I./t
# $Id: testkeys.pl 11680 2008-08-28 08:23:27Z mjevans $
# use strict;
use DBI qw(:sql_types);
# use DBD::ODBC::Const qw(:sql_types);
my (@row);
my $dbh = DBI->connect('dbi:ODBC:PERL_TEST_ACCESS', '', '', {PrintError=>1})
or exit(0);
# ------------------------------------------------------------
my @tables;
my $table;
my $sth;
$| = 1;
if (@tables = $dbh->tables) {
# print join(', ', @tables), "\n";
foreach $table (@tables) {
my $schema = '';
if ($table =~ m/(.*)\.(.*)$/) {
$schema = $1;
$table = $2;
}
# DBI->trace(3);
$sth = $dbh->func('', $schema, $table, GetPrimaryKeys);
if (!$sth) {
print "No Primary keys for $schema.$table (", $dbh->errstr, ")\n";
} else {
print "$table\n";
my @row;
while (@row = $sth->fetchrow_array) {
print "\t", join(', ', @row), "\n";
}
}
}
}
$dbh->disconnect();
sub nullif ($) {
my $val = shift;
$val ? $val : "(null)";
}
|