Lines 151-161
sub marc_framework_sql_list {
Link Here
|
151 |
my %cell; |
151 |
my %cell; |
152 |
my @frameworklist; |
152 |
my @frameworklist; |
153 |
map { |
153 |
map { |
154 |
my $name = substr( $_, 0, -4 ); # FIXME: restricted to 3 letter extension |
154 |
my ( $name, $ext ) = split /\./, $_; |
155 |
open my $fh, "<:encoding(UTF-8)", "$dir/$requirelevel/$name.txt"; |
155 |
my @lines; |
156 |
my $line = <$fh>; |
156 |
if ( $ext =~ /yml/ ) { |
157 |
$line = Encode::encode('UTF-8', $line) unless ( Encode::is_utf8($line) ); |
157 |
my $yaml = LoadFile("$dir/$requirelevel/$name\.$ext"); |
158 |
my @lines = split /\n/, $line; |
158 |
@lines = map { Encode::decode('UTF-8', $_) } @{ $yaml->{'description'} }; |
|
|
159 |
} else { |
160 |
open my $fh, "<:encoding(UTF-8)", "$dir/$requirelevel/$name.txt"; |
161 |
my $line = <$fh>; |
162 |
$line = Encode::encode('UTF-8', $line) unless ( Encode::is_utf8($line) ); |
163 |
@lines = split /\n/, $line; |
164 |
} |
159 |
my $mandatory = ($requirelevel =~ /(mandatory|requi|oblig|necess)/i); |
165 |
my $mandatory = ($requirelevel =~ /(mandatory|requi|oblig|necess)/i); |
160 |
push @frameworklist, |
166 |
push @frameworklist, |
161 |
{ |
167 |
{ |
Lines 232-238
sub sample_data_sql_list {
Link Here
|
232 |
my @lines; |
238 |
my @lines; |
233 |
if ( $ext =~ /yml/ ) { |
239 |
if ( $ext =~ /yml/ ) { |
234 |
my $yaml = LoadFile("$dir/$requirelevel/$name\.$ext"); |
240 |
my $yaml = LoadFile("$dir/$requirelevel/$name\.$ext"); |
235 |
@lines = @{ $yaml->{'description'} }; |
241 |
@lines = map { Encode::decode('UTF-8', $_) } @{ $yaml->{'description'} }; |
236 |
} else { |
242 |
} else { |
237 |
open my $fh, "<:encoding(UTF-8)", "$dir/$requirelevel/$name.txt"; |
243 |
open my $fh, "<:encoding(UTF-8)", "$dir/$requirelevel/$name.txt"; |
238 |
my $line = <$fh>; |
244 |
my $line = <$fh>; |
Lines 485-495
sub load_sql {
Link Here
|
485 |
my $placeholders = join ",", map { "?" } @columns; # '?,..,?' string |
491 |
my $placeholders = join ",", map { "?" } @columns; # '?,..,?' string |
486 |
my $query = "INSERT INTO $table_name ( $fields ) VALUES ( $placeholders )"; |
492 |
my $query = "INSERT INTO $table_name ( $fields ) VALUES ( $placeholders )"; |
487 |
my $sth = $dbh->prepare($query); |
493 |
my $sth = $dbh->prepare($query); |
|
|
494 |
my @multiline = @{ $table->{$table_name}->{'multiline'} }; # to check multiline values; |
488 |
foreach my $row ( @rows ) { |
495 |
foreach my $row ( @rows ) { |
489 |
my @values = map { $row->{$_} } @columns; |
496 |
my @values = map { |
|
|
497 |
my $col = $_; |
498 |
( @multiline and grep { $_ eq $col } @multiline ) |
499 |
? join "\r\n", @{$row->{$col}} # join multiline values |
500 |
: $row->{$col}; |
501 |
} @columns; |
490 |
$sth->execute( @values ); |
502 |
$sth->execute( @values ); |
491 |
} |
503 |
} |
492 |
} |
504 |
} |
|
|
505 |
for my $statement ( @{ $yaml->{'sql_statements'} } ) { # extra SQL statements |
506 |
$dbh->do($statement); |
507 |
} |
493 |
}; |
508 |
}; |
494 |
} |
509 |
} |
495 |
if ($@){ |
510 |
if ($@){ |