in reply to adding database values to csv file
Buttons are GUI specific, so unless you tell us what the GUI is you want it to be implemented in, it will be hard to get working examples. perl/Tk button code won't work in Wx and vise-versa.
A callback to dump a table to CSV could be something like (untested!)
# assuming the database handle in $dbh use Text::CSV_XS; sub save_table { my $tbl = shift; # it is up to you to check for SQL-injection on $tbl ... my $sth = $dbh->prepare ("select * from $tbl"); $sth->execute; my %rec; my @fld = @{$sth->{NAME_lc}}; $sth->bind_columns (\@rec{@fld}); my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1, eol => + "\n", always_quote => 1 }); $csv->print (*STDOUT, \@fld); # Print header, change STDOUT to fil +e if required while ($sth->fetch) { $csv->print (*STDOUT, [ @rec{@fld} ]); } } # save_table
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: adding database values to csv file
by vsurend (Novice) on Sep 26, 2011 at 09:06 UTC | |
by Tux (Canon) on Sep 26, 2011 at 09:23 UTC | |
|
Re^2: adding database values to csv file
by Anonymous Monk on Sep 27, 2011 at 11:52 UTC | |
by Tux (Canon) on Sep 27, 2011 at 17:38 UTC | |
by Anonymous Monk on Sep 28, 2011 at 12:10 UTC |