projects
/
blackray-experiments.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' of mjesec.ffzg.hr:/git/blackray-experiments
[blackray-experiments.git]
/
sql2blackray.pl
diff --git
a/sql2blackray.pl
b/sql2blackray.pl
index
b1c6aa5
..
9cc5941
100755
(executable)
--- a/
sql2blackray.pl
+++ b/
sql2blackray.pl
@@
-22,11
+22,11
@@
open(my $load, '>', 'load.xml');
sub dump_table {
my $table = shift;
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();
my $sth = $dbh->prepare( $sql );
$sth->execute();
@@
-38,14
+38,14
@@
my @columns = @{ $sth->{NAME} };
warn "columns ", dump @columns;
print $load qq|<table-def name="$table" schema="$schema">\n|;
warn "columns ", dump @columns;
print $load qq|<table-def name="$table" schema="$schema">\n|;
-print $load qq| <column-def name="$_" ty
l
e="string" tokenizing=" "
+print $load qq| <column-def name="$_" ty
p
e="string" tokenizing=" "
searchable="yes" compress="no" wildcards="yes" />
| foreach @columns;
searchable="yes" compress="no" wildcards="yes" />
| foreach @columns;
-print $load qq|<
table-def>
|;
+print $load qq|<
/table-def>\n
|;
my $file = "$table.csv";
my $file = "$table.csv";
-print $load qq|<load-data table="$table" schema="$schema" file="$file">|;
+print $load qq|<load-data table="$table" schema="$schema" file="$file">
\n
|;
foreach my $i ( 0 .. $#columns ) {
print $load qq|
<column name="$columns[$i]" csv-column="$i">
foreach my $i ( 0 .. $#columns ) {
print $load qq|
<column name="$columns[$i]" csv-column="$i">
@@
-53,7
+53,7
@@
foreach my $i ( 0 .. $#columns ) {
</column>
|;
}
</column>
|;
}
-print $load qq|</load-data>|;
+print $load qq|</load-data>
\n
|;
open(my $fh, '>', $file) || die "$file: $!";
open(my $fh, '>', $file) || die "$file: $!";
@@
-68,8
+68,19
@@
warn "$file ", -s $file, " bytes\n";
}
print $load qq|<load-script>\n|;
}
print $load qq|<load-script>\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|</load-script>\n|;
#$dbh->commit;
print $load qq|</load-script>\n|;
#$dbh->commit;