From 49ee48451698470076e05d64342f23e903fedb74 Mon Sep 17 00:00:00 2001
From: Andreas Romeyke <art1@andreas-romeyke.de>
Date: Thu, 22 Jul 2021 13:58:13 +0200
Subject: [PATCH] - improved SQLite write - disabled check_if_dbconform()
 calls, because if something is not UTF8 ready, the SQLite will report it
 directly - improved get_files_ref()

---
 perl/exit_strategy.pl | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/perl/exit_strategy.pl b/perl/exit_strategy.pl
index 4fc8eae..79ac1b5 100644
--- a/perl/exit_strategy.pl
+++ b/perl/exit_strategy.pl
@@ -71,11 +71,19 @@ my $sourcetype="hdd"; #default value
 #   if IE.xml file found, read its metadata, create SQL add entry
 #   write SQL add entry
 ###############################################################################
-sub write_database_creation ($fh) {
+sub write_database_creation ($dbh) {
      # non standard conform SQL keywords
      #say $fh "CREATE DATABASE $db_name;";
      #say $fh "CREATE SCHEMA $schema_name;";
      #say $fh "USE ";
+  my $sql1=<<"SQL_PRAGMA_WAL";
+PRAGMA journal_mode=WAL;
+SQL_PRAGMA_WAL
+  my $sql2=<<"SQL_PRAGMA_ASYNC";
+PRAGMA synchronous = OFF;
+SQL_PRAGMA_ASYNC
+  my $sth1 = $dbh->prepare($sql1); $sth1->execute() or die "sql problem detected", $dbh->errstr;
+  my $sth2 = $dbh->prepare($sql2); $sth2->execute() or die "sql problem detected", $dbh->errstr;
   return;
 }
 
@@ -292,7 +300,7 @@ sub check_if_db_conform ($string, $filename) {
   sub get_title ($xp, $filename){
     # get title
     my $title = $xp->findvalue($compiled_xpath_titles);
-    check_if_db_conform($title, $filename);
+    #check_if_db_conform($title, $filename);
     return $title;
   }
 
@@ -301,7 +309,7 @@ sub check_if_db_conform ($string, $filename) {
     my @dcrecords = map {
         $_->[1]=~ s/\n/ /g;
         $_->[1] =~ s/'/\\'/g;
-        check_if_db_conform($_->[1], $filename);
+        #check_if_db_conform($_->[1], $filename);
       $_;
     } grep {
       defined $_->[0] &&
@@ -328,8 +336,8 @@ sub check_if_db_conform ($string, $filename) {
   }
 
   sub get_files_ref ($xp, $filename, $repid){
-    my @files_nodes = $xp->findnodes("mets:mets/mets:fileSec/mets:fileGrp[\@ADMID='$repid']/mets:file/mets:FLocat/\@xlin:href");
-    my @files =  map {s#//#/#g; $_} map { $_->nodeValue } @files_nodes;
+    my @files_nodes = $xp->findnodes("/mets:mets/mets:fileSec/mets:fileGrp[\@ADMID='$repid']/mets:file/mets:FLocat/\@xlin:href");
+    my @files =  map { my $tmp= $_->nodeValue;  $tmp=~ s#//#/#g; $tmp } @files_nodes;
     return \@files;
   }
 
@@ -340,7 +348,6 @@ sub check_if_db_conform ($string, $filename) {
     my $dom = XML::LibXML->load_xml(
         location  => $filename,
         recover   => $recovery_flag,
-        no_blanks => 1,
         compact   => 1,
         no_network    => 1,
     );
-- 
GitLab