7 use Data::Dump qw(dump);
9 our $dsn = 'DBI:mysql:dbname=';
14 require 'config.pl' if -e 'config.pl';
16 my $table = 'borrowers';
17 my $schema = $database;
19 my $dbh = DBI->connect($dsn . $database, $user,$passwd, { RaiseError => 1, AutoCommit => 0 }) || die $DBI::errstr;
21 open(my $load, '>', 'load.xml');
31 my $sth = $dbh->prepare( $sql );
34 warn "got ", $sth->rows, " rows\n";
36 my @columns = @{ $sth->{NAME} };
38 warn "columns ", dump @columns;
40 print $load qq|<table-def name="$table" schema="$schema">\n|;
41 print $load qq| <column-def name="$_" tyle="string" tokenizing=" "
42 searchable="yes" compress="no" wildcards="yes" />
44 print $load qq|<table-def>|;
46 my $file = "$table.csv";
48 print $load qq|<load-data table="$table" schema="$schema" file="$file">|;
49 foreach my $i ( 0 .. $#columns ) {
51 <column name="$columns[$i]" csv-column="$i">
52 <function type="trim" />
56 print $load qq|</load-data>|;
58 open(my $fh, '>', $file) || die "$file: $!";
60 while (my $row = $sth->fetchrow_arrayref) {
61 print $fh join(',', map { ! defined $_ ? '' : m/^\d+$/ ? $_ : "\"$_\"" } @$row), "\n";
66 warn "$file ", -s $file, " bytes\n";
70 print $load qq|<load-script>\n|;
71 dump_table 'borrowers';
72 dump_table 'borrower_attributes';
73 print $load qq|</load-script>\n|;