Only start a transaction if we are not already in a transaction
This commit is contained in:
parent
15a7c22b94
commit
84b8e43034
|
@ -218,7 +218,7 @@ sub save {
|
||||||
my $serial = eval '$'.$type.'::serial';
|
my $serial = eval '$'.$type.'::serial';
|
||||||
my @identified_by = eval '@'.$type.'::identified_by';
|
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 ) {
|
if ( ! $serial ) {
|
||||||
my $insert = $force_insert;
|
my $insert = $force_insert;
|
||||||
my %serial = eval '%'.$type.'::serial';
|
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} ) ) ) {
|
if ( ! ( ( $_ = $local_dbh->prepare("DELETE FROM `$table` WHERE $where") ) and $_->execute( @$self{@identified_by} ) ) ) {
|
||||||
$where =~ s/\?/\%s/g;
|
$where =~ s/\?/\%s/g;
|
||||||
$log->error("Error deleting: DELETE FROM $table WHERE " . sprintf($where, map { defined $_ ? $_ : 'undef' } ( @$self{@identified_by}) ).'):' . $local_dbh->errstr);
|
$log->error("Error deleting: DELETE FROM $table WHERE " . sprintf($where, map { defined $_ ? $_ : 'undef' } ( @$self{@identified_by}) ).'):' . $local_dbh->errstr);
|
||||||
$local_dbh->rollback();
|
$local_dbh->rollback() if $ac;
|
||||||
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
|
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
|
||||||
return $local_dbh->errstr;
|
return $local_dbh->errstr;
|
||||||
} elsif ( $debug ) {
|
} elsif ( $debug ) {
|
||||||
$log->debug("SQL succesful DELETE FROM $table WHERE $where");
|
$log->debug("SQL succesful DELETE FROM $table WHERE $where");
|
||||||
|
@ -267,8 +267,8 @@ $log->debug("No serial") if $debug;
|
||||||
my $error = $local_dbh->errstr;
|
my $error = $local_dbh->errstr;
|
||||||
$command =~ s/\?/\%s/g;
|
$command =~ s/\?/\%s/g;
|
||||||
$log->error('SQL statement execution failed: ('.sprintf($command, , map { defined $_ ? $_ : 'undef' } ( @sql{@keys}) ).'):' . $local_dbh->errstr);
|
$log->error('SQL statement execution failed: ('.sprintf($command, , map { defined $_ ? $_ : 'undef' } ( @sql{@keys}) ).'):' . $local_dbh->errstr);
|
||||||
$local_dbh->rollback();
|
$local_dbh->rollback() if $ac;
|
||||||
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
|
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
|
||||||
return $error;
|
return $error;
|
||||||
} # end if
|
} # end if
|
||||||
if ( $debug or DEBUG_ALL ) {
|
if ( $debug or DEBUG_ALL ) {
|
||||||
|
@ -282,8 +282,8 @@ $log->debug("No serial") if $debug;
|
||||||
my $error = $local_dbh->errstr;
|
my $error = $local_dbh->errstr;
|
||||||
$command =~ s/\?/\%s/g;
|
$command =~ s/\?/\%s/g;
|
||||||
$log->error('SQL failed: ('.sprintf($command, , map { defined $_ ? $_ : 'undef' } ( @sql{@keys, @$fields{@identified_by}}) ).'):' . $local_dbh->errstr);
|
$log->error('SQL failed: ('.sprintf($command, , map { defined $_ ? $_ : 'undef' } ( @sql{@keys, @$fields{@identified_by}}) ).'):' . $local_dbh->errstr);
|
||||||
$local_dbh->rollback();
|
$local_dbh->rollback() if $ac;
|
||||||
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
|
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
|
||||||
return $error;
|
return $error;
|
||||||
} # end if
|
} # end if
|
||||||
if ( $debug or DEBUG_ALL ) {
|
if ( $debug or DEBUG_ALL ) {
|
||||||
|
@ -321,8 +321,8 @@ $log->debug("No serial") if $debug;
|
||||||
$command =~ s/\?/\%s/g;
|
$command =~ s/\?/\%s/g;
|
||||||
my $error = $local_dbh->errstr;
|
my $error = $local_dbh->errstr;
|
||||||
$log->error('SQL failed: ('.sprintf($command, map { defined $_ ? $_ : 'undef' } ( @sql{@keys}) ).'):' . $error);
|
$log->error('SQL failed: ('.sprintf($command, map { defined $_ ? $_ : 'undef' } ( @sql{@keys}) ).'):' . $error);
|
||||||
$local_dbh->rollback();
|
$local_dbh->rollback() if $ac;
|
||||||
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
|
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
|
||||||
return $error;
|
return $error;
|
||||||
} # end if
|
} # end if
|
||||||
if ( $debug or DEBUG_ALL ) {
|
if ( $debug or DEBUG_ALL ) {
|
||||||
|
@ -340,8 +340,8 @@ $log->debug("No serial") if $debug;
|
||||||
my $error = $local_dbh->errstr;
|
my $error = $local_dbh->errstr;
|
||||||
$command =~ s/\?/\%s/g;
|
$command =~ s/\?/\%s/g;
|
||||||
$log->error('SQL failed: ('.sprintf($command, map { defined $_ ? $_ : 'undef' } ( @sql{@keys}, @sql{@$fields{@identified_by}} ) ).'):' . $error) if $log;
|
$log->error('SQL failed: ('.sprintf($command, map { defined $_ ? $_ : 'undef' } ( @sql{@keys}, @sql{@$fields{@identified_by}} ) ).'):' . $error) if $log;
|
||||||
$local_dbh->rollback();
|
$local_dbh->rollback() if $ac;
|
||||||
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
|
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
|
||||||
return $error;
|
return $error;
|
||||||
} # end if
|
} # end if
|
||||||
if ( $debug or DEBUG_ALL ) {
|
if ( $debug or DEBUG_ALL ) {
|
||||||
|
@ -350,7 +350,7 @@ $log->debug("No serial") if $debug;
|
||||||
} # end if
|
} # end if
|
||||||
} # end if
|
} # end if
|
||||||
} # end if
|
} # end if
|
||||||
ZoneMinder::Database::end_transaction( $local_dbh, $ac );
|
ZoneMinder::Database::end_transaction( $local_dbh, $ac ) if $ac;
|
||||||
#$self->load();
|
#$self->load();
|
||||||
#if ( $$fields{id} ) {
|
#if ( $$fields{id} ) {
|
||||||
#if ( ! $ZoneMinder::Object::cache{$type}{$$self{id}} ) {
|
#if ( ! $ZoneMinder::Object::cache{$type}{$$self{id}} ) {
|
||||||
|
|
Loading…
Reference in New Issue