Get Max Fields Lengths
#!/usr/bin/perl
use DBI;
my $dsn = "DBI:mysql:dbname";
my $dbh = DBI->connect($dsn,"user","pass") or die "Could not connect to $dsn";
my $sth = $dbh->prepare("select * from tablename");
$sth->execute();
my (@wid) = @{$sth->{mysql_max_length}};
my (@col) = @{$sth->{NAME}};
my $ncols = scalar(@col);
my $i;
for($i=0; $i < $ncols; $i++) {
$marker = ($wid[$i] == 0) ? "<==" : "";
printf "%-20s\t%3d\t%s\n", $col[$i], $wid[$i], $marker;
}
$sth->finish();
$dbh->disconnect();