From 9bb582ea790f2f89a45ba34a82bc54f90550bfb0 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 2 Dec 2009 12:35:26 +0100 Subject: [PATCH] format load.xml better, user-selected columns --- sql2blackray.pl | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/sql2blackray.pl b/sql2blackray.pl index 83a1005..9cc5941 100755 --- a/sql2blackray.pl +++ b/sql2blackray.pl @@ -22,11 +22,11 @@ open(my $load, '>', 'load.xml'); sub dump_table { my $table = shift; + my @cols = @_; + @cols = ( '*' ) unless @cols; -my $sql = qq| - select * - from $table -|; +my $sql = 'select ' . join(',', @cols) . ' from ' . $table; +warn "# sql $sql\n"; my $sth = $dbh->prepare( $sql ); $sth->execute(); @@ -38,14 +38,14 @@ my @columns = @{ $sth->{NAME} }; warn "columns ", dump @columns; print $load qq|\n|; -print $load qq| | foreach @columns; -print $load qq||; +print $load qq|\n|; my $file = "$table.csv"; -print $load qq||; +print $load qq|\n|; foreach my $i ( 0 .. $#columns ) { print $load qq| @@ -53,7 +53,7 @@ foreach my $i ( 0 .. $#columns ) { |; } -print $load qq||; +print $load qq|\n|; open(my $fh, '>', $file) || die "$file: $!"; @@ -68,8 +68,19 @@ warn "$file ", -s $file, " bytes\n"; } print $load qq|\n|; -dump_table 'borrowers'; -dump_table 'borrower_attributes'; +dump_table 'borrowers' => qw( + borrowernumber + cardnumber + surname + firstname + email +); +dump_table 'borrower_attributes' => qw( + borrowernumber + code + attribute +); + print $load qq|\n|; #$dbh->commit; -- 2.20.1