X-Git-Url: http://git.rot13.org/?p=blackray-experiments.git;a=blobdiff_plain;f=sql2blackray.pl;h=9cc5941d3612d2c2e1c98ee5fcdece94152d1a2e;hp=b1c6aa58d1aaf7f025e160f60460542487379e18;hb=a16eb0145e18cd0d740704ae1093f7f159e560c3;hpb=0f3d98ef3f71825b5c3b586c440f14bbeeb81034 diff --git a/sql2blackray.pl b/sql2blackray.pl index b1c6aa5..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;