This is a non DBI related question, but rather a question of how to write
out comma delimeted info. See perldoc -f join, then find out why you only
have one row, which is probably due to there being only one row to fetch for
the query you are running.
Ilya
-----Original Message-----
From: Tim Bunce
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: 07/16/2001 9:39 AM
Subject: (Fwd) How to write records from table to csv file?
----- Forwarded message from Vinod Patel <[EMAIL PROTECTED]> -----
From: Vinod Patel <[EMAIL PROTECTED]>
To: "'Tim Bunce'" <[EMAIL PROTECTED]>
Subject: How to write records from table to csv file?
Date: Mon, 16 Jul 2001 09:32:50 -0400
Return-Receipt-To: Vinod Patel <[EMAIL PROTECTED]>
Hi,
I am trying to write a comma delimited file from table.
Its writing only first record not all of the records. I also need to
place
comma between fields.
Could you check my code please? any suggestion.
# Select records from table and save into array.
sub select_records {
my $sth;
my ($pass_owner_name, $pass_table_name) = @_;
my $rows;
my $line;
my @rows;
my $dirlog = $ENV{'ARCHIEVE_FILE_DIR'};
my $curr_dt = sprintf
"%4d%02d%02d",$time->year+1900,($time->mon)+1,$time->md
y;
my $archfile=sprintf "%s/%s.%s_%d.csv%s", $dirlog, $pass_owner_name,
$pass_ta
le_name, $curr_dt;
open(ARCH_FILE, ">$archfile") || process_die ("Can't open $archfile
file
\n")
$sth=
$dbh->prepare( "
select *
from tablename
" );
if ( !defined $sth ) {
process_die("Cannot prepare select from table $DBI::errstr\n");
}
# execute the statement
$sth->execute() || process_die( $sth->errstr() );
while ( (@rows) = $sth->fetchrow_array() ) {
print "ROW: @rows\n";
print(ARCH_FILE @rows);
close(ARCH_FILE);
} # while
}
Thanks,
Vinod.
----- End forwarded message -----