From 2003798e6406fc4afd23c6889a4bb290de1692cc Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Fri, 27 Oct 2017 21:06:11 -0700 Subject: [PATCH] copy in start and end transaction --- scripts/ZoneMinder/lib/ZoneMinder/Database.pm | 24 +++++++++++++++++++ scripts/ZoneMinder/lib/ZoneMinder/Object.pm | 14 +++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Database.pm b/scripts/ZoneMinder/lib/ZoneMinder/Database.pm index 8d752600d..bd0877e0e 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Database.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Database.pm @@ -205,6 +205,30 @@ sub zmDbGetMonitorAndControl { return( $monitor ); } +sub start_transaction { + #my ( $caller, undef, $line ) = caller; +#$openprint::log->debug("Called start_transaction from $caller : $line"); + my $d = shift; + $d = $dbh if ! $d; + my $ac = $d->{AutoCommit}; + $d->{AutoCommit} = 0; + return $ac; +} # end sub start_transaction + +sub end_transaction { + #my ( $caller, undef, $line ) = caller; +#$openprint::log->debug("Called end_transaction from $caller : $line"); + my ( $d, $ac ) = @_; +if ( ! defined $ac ) { + $log->error("Undefined ac"); +} + $d = $dbh if ! $d; + if ( $ac ) { + #$log->debug("Committing"); + $d->commit(); + } # end if + $d->{AutoCommit} = $ac; +} # end sub end_transaction 1; __END__ # Below is stub documentation for your module. You'd better edit it! diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Object.pm b/scripts/ZoneMinder/lib/ZoneMinder/Object.pm index a2d9fa021..dfcc02ea9 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Object.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Object.pm @@ -153,7 +153,7 @@ sub save { my $serial = eval '$'.$type.'::serial'; my @identified_by = eval '@'.$type.'::identified_by'; - my $ac = sql::start_transaction( $local_dbh ); + my $ac = ZoneMinder::Database::start_transaction( $local_dbh ); if ( ! $serial ) { my $insert = $force_insert; my %serial = eval '%'.$type.'::serial'; @@ -170,7 +170,7 @@ $log->debug("No serial") if $debug; $where =~ s/\?/\%s/g; $log->error("Error deleting: DELETE FROM $table WHERE " . sprintf($where, map { defined $_ ? $_ : 'undef' } ( @$self{@identified_by}) ).'):' . $local_dbh->errstr); $local_dbh->rollback(); - sql::end_transaction( $local_dbh, $ac ); + ZoneMinder::Database::end_transaction( $local_dbh, $ac ); return $local_dbh->errstr; } elsif ( $debug ) { $log->debug("SQL succesful DELETE FROM $table WHERE $where"); @@ -200,7 +200,7 @@ $log->debug("No serial") if $debug; $command =~ s/\?/\%s/g; $log->error('SQL statement execution failed: ('.sprintf($command, , map { defined $_ ? $_ : 'undef' } ( @sql{@keys}) ).'):' . $local_dbh->errstr); $local_dbh->rollback(); - sql::end_transaction( $local_dbh, $ac ); + ZoneMinder::Database::end_transaction( $local_dbh, $ac ); return $error; } # end if if ( $debug or DEBUG_ALL ) { @@ -215,7 +215,7 @@ $log->debug("No serial") if $debug; $command =~ s/\?/\%s/g; $log->error('SQL failed: ('.sprintf($command, , map { defined $_ ? $_ : 'undef' } ( @sql{@keys, @$fields{@identified_by}}) ).'):' . $local_dbh->errstr); $local_dbh->rollback(); - sql::end_transaction( $local_dbh, $ac ); + ZoneMinder::Database::end_transaction( $local_dbh, $ac ); return $error; } # end if if ( $debug or DEBUG_ALL ) { @@ -247,7 +247,7 @@ $log->debug("No serial") if $debug; my $error = $local_dbh->errstr; $log->error('SQL failed: ('.sprintf($command, map { defined $_ ? $_ : 'undef' } ( @sql{@keys}) ).'):' . $error); $local_dbh->rollback(); - sql::end_transaction( $local_dbh, $ac ); + ZoneMinder::Database::end_transaction( $local_dbh, $ac ); return $error; } # end if if ( $debug or DEBUG_ALL ) { @@ -264,7 +264,7 @@ $log->debug("No serial") if $debug; $command =~ s/\?/\%s/g; $log->error('SQL failed: ('.sprintf($command, map { defined $_ ? $_ : 'undef' } ( @sql{@keys}, @sql{@$fields{@identified_by}} ) ).'):' . $error) if $log; $local_dbh->rollback(); - sql::end_transaction( $local_dbh, $ac ); + ZoneMinder::Database::end_transaction( $local_dbh, $ac ); return $error; } # end if if ( $debug or DEBUG_ALL ) { @@ -273,7 +273,7 @@ $log->debug("No serial") if $debug; } # end if } # end if } # end if - sql::end_transaction( $local_dbh, $ac ); + ZoneMinder::Database::end_transaction( $local_dbh, $ac ); $self->load(); #if ( $$fields{id} ) { #if ( ! $ZoneMinder::Object::cache{$type}{$$self{id}} ) {