From: Moritz Bunkus Date: Tue, 14 Feb 2006 16:38:49 +0000 (+0000) Subject: Jedes Datenbankupdate wird in einer Transaktion gekapselt. Somit wird ein Upgradescri... X-Git-Tag: release-2.4.0^2~341 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=df9b211eecc3fdcc8ca143fcdff4d0a002e150e3;p=kivitendo-erp.git Jedes Datenbankupdate wird in einer Transaktion gekapselt. Somit wird ein Upgradescript entweder ganz oder gar nicht ausgefuehrt. Ausserdem wird die Versionsnummer automatisch hochgesetzt und muss nicht mehr im Upgrade-Script gesetzt werden. --- diff --git a/SL/User.pm b/SL/User.pm index 39d40c4e3..f989e86f5 100644 --- a/SL/User.pm +++ b/SL/User.pm @@ -393,7 +393,7 @@ sub dbcreate { sub process_query { $main::lxdebug->enter_sub(); - my ($self, $form, $dbh, $filename) = @_; + my ($self, $form, $dbh, $filename, $version) = @_; # return unless (-f $filename); @@ -402,6 +402,8 @@ sub process_query { my $sth; my @quote_chars; + $dbh->begin_work(); + while () { # Remove DOS and Unix style line endings. @@ -429,8 +431,13 @@ sub process_query { # Query is complete. Send it. $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - $sth->finish; + if (!$sth->execute()) { + $sth->finish(); + $dbh->rollback(); + $form->dberror("The database update/creation did not succeed. The file ${filename} containing the following query failed:
${query}
" . + "All changes in that file have been reverted."); + } + $sth->finish(); $char = ""; $query = ""; @@ -441,6 +448,11 @@ sub process_query { } } + if ($version) { + $dbh->do("UPDATE defaults SET version = " . $dbh->quote($version)); + } + $dbh->commit(); + close FH; $main::lxdebug->leave_sub(); @@ -696,6 +708,7 @@ sub dbupdate { $a =~ s/^$form->{dbdriver}-upgrade-|\.sql$//g; my ($mindb, $maxdb) = split /-/, $a; + my $str_maxdb = $maxdb; ## LINET $mindb = calc_version($mindb); $maxdb = calc_version($maxdb); @@ -707,7 +720,7 @@ sub dbupdate { last if ($version < $mindb); # apply upgrade - $self->process_query($form, $dbh, "sql/$upgradescript"); + $self->process_query($form, $dbh, "sql/$upgradescript", $str_maxdb); $version = $maxdb;