From 71e2f164547b22dce6dd66f0b81864a2ee2b6ff2 Mon Sep 17 00:00:00 2001 From: hjp Date: Sun, 1 Dec 2013 09:08:38 +0000 Subject: [PATCH] moved removal of orphaned records into their own functions and after the loop. --- scripts/remove_session | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/scripts/remove_session b/scripts/remove_session index b04e011..1216c46 100755 --- a/scripts/remove_session +++ b/scripts/remove_session @@ -21,8 +21,15 @@ for my $session (@ARGV) { print "deleting session $session\n"; my $n_instances = $dbh->do("delete from instances where session=?", {}, $session); print "\t$n_instances instances deleted\n"; + $dbh->commit(); +} +remove_orphaned_sessions(); +remove_orphaned_files(); +remove_orphaned_versions(); +$dbh->disconnect(); +exit(); - # remove orphaned records: +sub remove_orphaned_sessions { my $sessions = $dbh->selectcol_arrayref( q{select s.id from instances i right outer join sessions s on i.session=s.id where i.id is null} @@ -32,7 +39,10 @@ for my $session (@ARGV) { $dbh->do(q{delete from sessions where id=?}, {}, $session); print "\tsession $session deleted\n"; } + $dbh->commit(); +} +sub remove_orphaned_files { my $files = $dbh->selectcol_arrayref( q{select f.id from instances i right outer join files f on i.file=f.id where i.id is null} @@ -42,7 +52,10 @@ for my $session (@ARGV) { $dbh->do(q{delete from files where id=?}, {}, $file); print "\tfile $file deleted\n"; } + $dbh->commit(); +} +sub remove_orphaned_versions { my $versions = $dbh->selectcol_arrayref( q{select v.id from instances i right outer join versions2 v on i.version=v.id where i.id is null} @@ -54,4 +67,3 @@ for my $session (@ARGV) { } $dbh->commit(); } -$dbh->disconnect();