Only start a transaction if we are not already in a transaction

This commit is contained in:
Isaac Connor 2021-10-25 11:09:06 -04:00
parent 15a7c22b94
commit 84b8e43034
1 changed files with 12 additions and 12 deletions

View File

@ -218,7 +218,7 @@ sub save {
my $serial = eval '$'.$type.'::serial';
my @identified_by = eval '@'.$type.'::identified_by';
my $ac = ZoneMinder::Database::start_transaction( $local_dbh );
my $ac = ZoneMinder::Database::start_transaction( $local_dbh ) if $local_dbh->{AutoCommit};
if ( ! $serial ) {
my $insert = $force_insert;
my %serial = eval '%'.$type.'::serial';
@ -234,8 +234,8 @@ $log->debug("No serial") if $debug;
if ( ! ( ( $_ = $local_dbh->prepare("DELETE FROM `$table` WHERE $where") ) and $_->execute( @$self{@identified_by} ) ) ) {
$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();
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
$local_dbh->rollback() if $ac;
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
return $local_dbh->errstr;
} elsif ( $debug ) {
$log->debug("SQL succesful DELETE FROM $table WHERE $where");
@ -267,8 +267,8 @@ $log->debug("No serial") if $debug;
my $error = $local_dbh->errstr;
$command =~ s/\?/\%s/g;
$log->error('SQL statement execution failed: ('.sprintf($command, , map { defined $_ ? $_ : 'undef' } ( @sql{@keys}) ).'):' . $local_dbh->errstr);
$local_dbh->rollback();
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
$local_dbh->rollback() if $ac;
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
return $error;
} # end if
if ( $debug or DEBUG_ALL ) {
@ -282,8 +282,8 @@ $log->debug("No serial") if $debug;
my $error = $local_dbh->errstr;
$command =~ s/\?/\%s/g;
$log->error('SQL failed: ('.sprintf($command, , map { defined $_ ? $_ : 'undef' } ( @sql{@keys, @$fields{@identified_by}}) ).'):' . $local_dbh->errstr);
$local_dbh->rollback();
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
$local_dbh->rollback() if $ac;
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
return $error;
} # end if
if ( $debug or DEBUG_ALL ) {
@ -321,8 +321,8 @@ $log->debug("No serial") if $debug;
$command =~ s/\?/\%s/g;
my $error = $local_dbh->errstr;
$log->error('SQL failed: ('.sprintf($command, map { defined $_ ? $_ : 'undef' } ( @sql{@keys}) ).'):' . $error);
$local_dbh->rollback();
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
$local_dbh->rollback() if $ac;
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
return $error;
} # end if
if ( $debug or DEBUG_ALL ) {
@ -340,8 +340,8 @@ $log->debug("No serial") if $debug;
my $error = $local_dbh->errstr;
$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();
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
$local_dbh->rollback() if $ac;
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
return $error;
} # end if
if ( $debug or DEBUG_ALL ) {
@ -350,7 +350,7 @@ $log->debug("No serial") if $debug;
} # end if
} # end if
} # end if
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
#$self->load();
#if ( $$fields{id} ) {
#if ( ! $ZoneMinder::Object::cache{$type}{$$self{id}} ) {