File: listtabs.pl

package info (click to toggle)
libdbd-odbc-perl 1.37-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,272 kB
  • sloc: perl: 7,932; ansic: 5,991; makefile: 33; sql: 8
file content (39 lines) | stat: -rwxr-xr-x 905 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
#!/usr/bin/perl -I./t
# $Id: listtabs.pl 11680 2008-08-28 08:23:27Z mjevans $


require DBI;

my (@row);

my $dbh = DBI->connect()
    || die "Can't connect to your $ENV{DBI_DSN} using user: $ENV{DBI_USER} and pass: $ENV{DBI_PASS}\n$DBI::errstr\n";
# ------------------------------------------------------------

my $rows = 0;
my @tables;
my $table;
$| = 1;

if (@tables = $dbh->tables) {
    print join(', ', @tables), "\n";
    foreach $table (@tables) {
	my $schema = '';
	if ($table =~ m/(.*)\.(.*)$/) {
		$schema = $1;
		$table = $2;
	}
	my $sthcols = $dbh->func('',$schema, $table,'', columns);
	if ($sthcols) {
	    while (@row = $sthcols->fetchrow_array) {
		print "\t", join(', ', @row), "\n";
	    }
	} else {
	    # hmmm...none of my drivers support this...dang.  I can't test it.
	    print "SQLColumns: $DBI::errstr\n";
	}
    }
}

$dbh->disconnect();