File: testkeys.pl

package info (click to toggle)
libdbd-odbc-perl 1.24-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,012 kB
  • ctags: 398
  • sloc: perl: 6,314; ansic: 4,875; makefile: 29; sql: 8
file content (48 lines) | stat: -rwxr-xr-x 950 bytes parent folder | download | duplicates (2)
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)";
}