Thursday, November 13, 2008

Get tables & columns from MS Access


#!/usr/bin/perl -w
use strict;
#use Data::Dumper;

use DBI;
my $dsn = 'Driver=Microsoft Access Driver (*.mdb);
DBQ=db.mdb';
my $dbh = DBI->connect("DBI:ODBC:$dsn",'','',
{RaiseError=>1}) or die $DBI::errstr;

my $sth = $dbh->table_info('','','','TABLE');

while( my ( undef, undef, $name ) =
$sth->fetchrow_array() ) {
print "$name: \n";
my $colsth = $dbh->column_info( '', '', $name, '' );
while( my ( undef, undef, undef, $col_name ) =
$colsth->fetchrow_array() ) {
print "\t$col_name\n";
}
}

No comments: