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
In reply to Re: adding database values to csv file
by Tux
in thread adding database values to csv file
by vsurend
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |