|
From: Bob T. <bt...@us...> - 2004-03-01 22:39:40
|
Update of /cvsroot/benson/benson3/handlers In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27033/handlers Modified Files: R85historical.pm Log Message: Made the changes for the historical handler and tests. Index: R85historical.pm =================================================================== RCS file: /cvsroot/benson/benson3/handlers/R85historical.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -r1.2 -r1.3 *** R85historical.pm 23 Feb 2004 16:10:38 -0000 1.2 --- R85historical.pm 1 Mar 2004 22:28:15 -0000 1.3 *************** *** 13,52 **** } - my $insert_into_historical = <<EOSQL; - INSERT INTO - alerts_historical - SELECT - * - FROM - alerts - WHERE - received > now() - interval '? days' - EOSQL - - my $select_max_historical = <<EOSQL; - SELECT - max(identity) - FROM - alerts_historical - EOSQL - my $delete_historical_from_alerts = <<EOSQL; - DELETE FROM - alerts - WHERE - identity < '?' - EOSQL - my $delete_historical_from_alerts_status_log = <<EOSQL; - DELETE FROM - alerts_status_log - WHERE - identity < '?' - EOSQL sub handler { my ($self, $s) = @_; $s->trace(" R85historical is running...",3); ! my $days_kept_online = $s->HistoricalDKO || "7"; # --- 13,23 ---- } sub handler { my ($self, $s) = @_; $s->trace(" R85historical is running...",3); ! my $days_kept_online = $s->HistoricalOnline || "7"; # *************** *** 62,65 **** --- 33,48 ---- # Move historical alerts to alerts_historical table # + my $insert_into_historical = <<EOSQL; + INSERT INTO + alerts_history + SELECT + * + FROM + alerts + WHERE + received < now() - interval '$days_kept_online days' + EOSQL + + $dbh->begin_work; my $sth = $dbh->prepare($insert_into_historical); if($sth eq undef) { *************** *** 67,72 **** return 1; } ! my $rc = $sth->execute($days_kept_online); if($rc eq undef) { return 1; } --- 50,56 ---- return 1; } ! my $rc = $sth->execute(); if($rc eq undef) { + $dbh->rollback; return 1; } *************** *** 78,84 **** --- 62,75 ---- # Get latest row inserted identity # + my $select_max_historical = <<EOSQL; + SELECT + max(identity) + FROM + alerts_history + EOSQL $sth = $dbh->prepare($select_max_historical); if($sth eq undef) { $s->log("(DBI error) select_max_historical prepare failed.", FATAL); + $dbh->rollback; return 1; } *************** *** 86,89 **** --- 77,81 ---- if($rc eq undef) { $s->log("(DBI error) select_max_historical execute failed.", FATAL); + $dbh->rollback; return 1; } *************** *** 91,138 **** if($row eq undef) { $s->log("(DBI error) last row not found.", FATAL); return 0; } my $latest_historical_row = $row->[0]; if($latest_historical_row eq undef) { return 0; } $s->trace("R85historical: latest_historical_row id ($latest_historical_row)", 4); # # Delete rows from alerts and alerts_status_log # $sth = $dbh->prepare($delete_historical_from_alerts); if($sth eq undef) { $s->log("(DBI error) delete_historical_from_alerts prepare failed.", FATAL); return 1; } ! $rc = $sth->execute($latest_historical_row); if($rc eq undef) { $s->log("(DBI error) delete_historical_from_alerts execute failed.", FATAL); return 1; } my $rows_processed = $sth->rows; if($rows_processed != $rows_inserted) { ! $s->log("(DBI error) rows being deleted is not equal to rows inserted, aborting.", FATAL); return 1; } $sth = $dbh->prepare($delete_historical_from_alerts_status_log); if($sth eq undef) { $s->log("(DBI error) delete_historical_from_alerts_status_log prepare failed.", FATAL); return 1; } ! $rc = $sth->execute($latest_historical_row); if($rc eq undef) { $s->log("(DBI error) delete_historical_from_alerts_status_log execute failed.", FATAL); return 1; } ! $rows_processed = $sth->rows; ! if($rows_processed != $rows_inserted) { ! $s->log("(DBI error) rows being deleted is not equal to rows inserted, aborting.", FATAL); ! return 1; ! } ! # # Disconnect from database --- 83,145 ---- if($row eq undef) { $s->log("(DBI error) last row not found.", FATAL); + $dbh->rollback; return 0; } my $latest_historical_row = $row->[0]; if($latest_historical_row eq undef) { + $dbh->rollback; return 0; } $s->trace("R85historical: latest_historical_row id ($latest_historical_row)", 4); + # # Delete rows from alerts and alerts_status_log # + my $delete_historical_from_alerts = <<EOSQL; + DELETE FROM + alerts + WHERE + identity <= '$latest_historical_row' + EOSQL $sth = $dbh->prepare($delete_historical_from_alerts); if($sth eq undef) { $s->log("(DBI error) delete_historical_from_alerts prepare failed.", FATAL); + $dbh->rollback; return 1; } ! $rc = $sth->execute(); if($rc eq undef) { $s->log("(DBI error) delete_historical_from_alerts execute failed.", FATAL); + $dbh->rollback; return 1; } my $rows_processed = $sth->rows; if($rows_processed != $rows_inserted) { ! $s->log("(DBI error) rows being deleted($rows_processed) is not equal to rows inserted, aborting.", FATAL); ! $dbh->rollback; return 1; } + my $delete_historical_from_alerts_status_log = <<EOSQL; + DELETE FROM + alerts_status_log + WHERE + identity <= '$latest_historical_row' + EOSQL $sth = $dbh->prepare($delete_historical_from_alerts_status_log); if($sth eq undef) { $s->log("(DBI error) delete_historical_from_alerts_status_log prepare failed.", FATAL); + $dbh->rollback; return 1; } ! $rc = $sth->execute(); if($rc eq undef) { $s->log("(DBI error) delete_historical_from_alerts_status_log execute failed.", FATAL); + $dbh->rollback; return 1; } ! $dbh->commit; # # Disconnect from database |