M
MoshiachNow
HI,
The following sub extracts data nicely from all tables,just one table
comes up empty.
Will appreciate ideas on possible issues in the code.
thanks
=======================
sub exportMDB {
my $database = shift;
my $driver = "Microsoft Access Driver (*.mdb)";
print "$database\n";
print "---------------------------------\n\n";
my $dsn = "dbi:ODBC:driver=$driver;dbq=$database";
my $dbh = DBI->connect("$dsn") or warn "Couldn't open database:
$DBI::errstr; stopped";
my $sth = $dbh->table_info( "", "", "", "TABLE" );
while ( my ($catalog, $schema, $table, $type) = $sth-
print "\n$table :\n";
print "--------\n";
my $sql = "select * from $table";
# Prepare the SQL query for execution
my $sth = $dbh->prepare($sql) or warn "Couldn't prepare
statement:$DBI::errstr; stopped";
# Execute the query
$sth->execute() or warn "Couldn't execute statement:
$DBI::errstr; stopped";
# Fetch each row and print it
while ( my (@row) = $sth->fetchrow_array() ) {
print "$_\t" foreach (@row);
print "\n";
}
}
}
$dbh->disconnect(); # Disconnect from
the database
}
The following sub extracts data nicely from all tables,just one table
comes up empty.
Will appreciate ideas on possible issues in the code.
thanks
=======================
sub exportMDB {
my $database = shift;
my $driver = "Microsoft Access Driver (*.mdb)";
print "$database\n";
print "---------------------------------\n\n";
my $dsn = "dbi:ODBC:driver=$driver;dbq=$database";
my $dbh = DBI->connect("$dsn") or warn "Couldn't open database:
$DBI::errstr; stopped";
my $sth = $dbh->table_info( "", "", "", "TABLE" );
while ( my ($catalog, $schema, $table, $type) = $sth-
if ($table) {fetchrow_array() ) {
print "\n$table :\n";
print "--------\n";
my $sql = "select * from $table";
# Prepare the SQL query for execution
my $sth = $dbh->prepare($sql) or warn "Couldn't prepare
statement:$DBI::errstr; stopped";
# Execute the query
$sth->execute() or warn "Couldn't execute statement:
$DBI::errstr; stopped";
# Fetch each row and print it
while ( my (@row) = $sth->fetchrow_array() ) {
print "$_\t" foreach (@row);
print "\n";
}
}
}
$dbh->disconnect(); # Disconnect from
the database
}