copy in start and end transaction

This commit is contained in:
Isaac Connor 2017-10-27 21:06:11 -07:00
parent ad96d29b31
commit 2003798e64
2 changed files with 31 additions and 7 deletions

View File

@ -205,6 +205,30 @@ sub zmDbGetMonitorAndControl {
return( $monitor ); 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; 1;
__END__ __END__
# Below is stub documentation for your module. You'd better edit it! # Below is stub documentation for your module. You'd better edit it!

View File

@ -153,7 +153,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 = sql::start_transaction( $local_dbh ); my $ac = ZoneMinder::Database::start_transaction( $local_dbh );
if ( ! $serial ) { if ( ! $serial ) {
my $insert = $force_insert; my $insert = $force_insert;
my %serial = eval '%'.$type.'::serial'; my %serial = eval '%'.$type.'::serial';
@ -170,7 +170,7 @@ $log->debug("No serial") if $debug;
$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();
sql::end_transaction( $local_dbh, $ac ); ZoneMinder::Database::end_transaction( $local_dbh, $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");
@ -200,7 +200,7 @@ $log->debug("No serial") if $debug;
$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();
sql::end_transaction( $local_dbh, $ac ); ZoneMinder::Database::end_transaction( $local_dbh, $ac );
return $error; return $error;
} # end if } # end if
if ( $debug or DEBUG_ALL ) { if ( $debug or DEBUG_ALL ) {
@ -215,7 +215,7 @@ $log->debug("No serial") if $debug;
$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();
sql::end_transaction( $local_dbh, $ac ); ZoneMinder::Database::end_transaction( $local_dbh, $ac );
return $error; return $error;
} # end if } # end if
if ( $debug or DEBUG_ALL ) { if ( $debug or DEBUG_ALL ) {
@ -247,7 +247,7 @@ $log->debug("No serial") if $debug;
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();
sql::end_transaction( $local_dbh, $ac ); ZoneMinder::Database::end_transaction( $local_dbh, $ac );
return $error; return $error;
} # end if } # end if
if ( $debug or DEBUG_ALL ) { if ( $debug or DEBUG_ALL ) {
@ -264,7 +264,7 @@ $log->debug("No serial") if $debug;
$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();
sql::end_transaction( $local_dbh, $ac ); ZoneMinder::Database::end_transaction( $local_dbh, $ac );
return $error; return $error;
} # end if } # end if
if ( $debug or DEBUG_ALL ) { if ( $debug or DEBUG_ALL ) {
@ -273,7 +273,7 @@ $log->debug("No serial") if $debug;
} # end if } # end if
} # end if } # end if
} # end if } # end if
sql::end_transaction( $local_dbh, $ac ); ZoneMinder::Database::end_transaction( $local_dbh, $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}} ) {