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