McMahon, Chris wrote:
I'm a DBI newbie. I've written a little script that reports the
description of each column in a table. The script works fine, but when it
runs it reports warnings that I don't understand. Here's the script: ***********************************
use warnings; use DBI;


<connect omitted>

my $sth1 = $dbh->table_info(); while (my(@tab) = $sth1->fetchrow_array()) {
our @colNames;

I recommend putting that 'our' outside the loop, though it doesn't appear to be causing any trouble. Why aren't you using 'my'?
@tabNames might be a better name.


push @colNames, @tab[2];

I think $tab[2] would be more appropriate than @tab[2].


}

open OUT, ">col.txt";
foreach $colName(@colNames) {
print OUT "$colName\n";
my $sth = $dbh->column_info(); while (my(@info) = $sth->fetchrow_array()) {
if ($colName eq @info[2]) {
print OUT "[EMAIL PROTECTED]"; #WARNINGS FROM THIS LINE
} #END IF
}#END WHILE }#END FOREACH


$dbh->disconnect; **************************************************

For each "@info" that gets printed, I get 4 or 5 instances of the
warning "Use of uninitalized value in join or string..." Using Win32::ODBC, I would see these warnings on a SELECT when the
row contained NULL values, but I'm not understanding what about using
column_info is producing these warnings. I'm hoping someone on this can
educate me a bit...

I would expect it to be the same thing; NULL in the database is undef in Perl. You can avoid the error by adding something like this before you use @info.


foreach ( @info ) { $_ = "" if ! defined( $_ ); }

Also, you should look in the DBI docs for the appropriate arguments for table_info() and column_info(). Your program is doing a lot more work than it has to.

http://search.cpan.org/dist/DBI/DBI.pm

--
Mac :})
** I usually forward private questions to the appropriate mail list. **
Ask Smarter: http://www.catb.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.

Reply via email to