I thought this worked, but when I test it now, I can't get it to work.
YMMV.  -- Dave

#!/usr/bin/perl -w
# this does a 'describe' for MS access
use DBI;
use strict;
$|++;
#DBI->trace(8);
die "usage: desc.pl DSN table_name\n" if $#ARGV != 1;
my $dbh = DBI->connect("dbi:ODBC:$ARGV[0]", '', '',
                        { PrintError => 1, RaiseError => 1 });
die "connect failed: " . $DBI::errstr . "\n" if ! $dbh;

my $sth = $dbh->column_info("", "", $ARGV[1], "");
my @ar;
print "$ARGV[0].$ARGV[1]\nColumn                                   Type       Size 
Prec\n";
while (@ar = $sth->fetchrow_array()) {
    $ar[8] = 0 if !defined($ar[8]);
    printf("%-40s %-10s %4d %4d\n", $ar[3], $ar[5], $ar[6], $ar[8]);
}
$sth->finish;
$dbh->disconnect;

On Mar 25, Bart Lateur scribed:

> I'd like to automate exporting data out of an existing Access database,
> using DBI/DBD::ODBC, I guess. I need a proper description of each column
> in a table, in order to reconstruct a complete CREATE TABLE statement.
>
> My guess is that the func() method in DBD::ODBC could help. I've
> experimented a little with
>
>       $sth->func($col, 'DescribeCol')
>
> but the results don't mean too much to me. I'm stuck. Help?
>
> --
>       Bart.
>

Reply via email to