From cec1e0d280c9637644bc80ab9f67b7fc8b1df9ec Mon Sep 17 00:00:00 2001 From: Andreas Romeyke <art1@andreas-romeyke.de> Date: Fri, 22 Apr 2022 10:46:51 +0200 Subject: [PATCH] - added table creation --- perl/exit_strategy.pl | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/perl/exit_strategy.pl b/perl/exit_strategy.pl index 7b49c7b..45cffba 100644 --- a/perl/exit_strategy.pl +++ b/perl/exit_strategy.pl @@ -140,12 +140,24 @@ SQL_CREATE4 PRIMARY KEY(id AUTOINCREMENT) ); SQL_CREATE5 + my $sql6=<<"SQL_CREATE6"; +CREATE TABLE deleted ( + id INTEGER, + aip_id INTEGER NOT NULL REFERENCES aip (id), + state TEXT NOT NULL, + reason TEXT NOT NULL, + date DATE, + authorized_by TEXT NOT NULL, + PRIMARY KEY(id AUTOINCREMENT) + ); +SQL_CREATE6 + 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; my $sth3 = $dbh->prepare($sql3); $sth3->execute() or die "sql problem detected", $dbh->errstr; my $sth4 = $dbh->prepare($sql4); $sth4->execute() or die "sql problem detected", $dbh->errstr; my $sth5 = $dbh->prepare($sql5); $sth5->execute() or die "sql problem detected", $dbh->errstr; - + my $sth6 = $dbh->prepare($sql6); $sth6->execute() or die "sql problem detected", $dbh->errstr; return 1; } @@ -177,22 +189,30 @@ SQL_FILE_PLAN sourcedatafile.name=\$3), \$4, \$5 ); SQL_LOCAT_PLAN - my $sql_dc_pan=<<"SQL_DC_PLAN"; + my $sql_dc_plan=<<"SQL_DC_PLAN"; INSERT INTO dc (aip_id, element, value) VALUES ( (SELECT id FROM aip WHERE aip.ie_id=\$1 AND aip.version=\$2), \$3, \$4 ); SQL_DC_PLAN + my $sql_deleted_plan=<<"SQL_DELETE_PLAN"; + INSERT INTO deleted (aip_id, state, reason, date, authorized_by) VALUES ( + (SELECT id FROM aip WHERE aip.ie_id=\$1 AND aip.version=\$2), \$3, \$4, \$5, \$6 + ); +SQL_DELETE_PLAN + my $sth_aip_plan = $dbh->prepare($sql_aip_plan); my $sth_ie_plan = $dbh->prepare($sql_ie_plan); my $sth_file_plan = $dbh->prepare($sql_file_plan); my $sth_locat_plan = $dbh->prepare($sql_locat_plan); - my $sth_dc_plan = $dbh->prepare($sql_dc_pan); + my $sth_dc_plan = $dbh->prepare($sql_dc_plan); + my $sth_deleted_plan = $dbh->prepare($sql_deleted_plan); my $plans; $plans->{aip} = $sth_aip_plan; $plans->{ie} = $sth_ie_plan; $plans->{file} = $sth_file_plan; $plans->{locat} = $sth_locat_plan; $plans->{dc} = $sth_dc_plan; + $plans->{deleted} = $sth_deleted_plan; return $plans; } @@ -218,6 +238,8 @@ SQL_DC_PLAN # $ret{"dcrecords"} = \@dcrecords; ############################################################################### sub write_addsql ($dbh, $plans, $refhash) { + use Data::Printer; + p( $refhash); my $iefile = basename($refhash->{"filename"}); my ($ieid,$ieversion); if ($iefile =~ m/^V(\d+)-(IE\d*)\.xml$/) { -- GitLab