Revision df9b211e
Von Moritz Bunkus vor fast 19 Jahren hinzugefügt
SL/User.pm | ||
---|---|---|
393 | 393 |
sub process_query { |
394 | 394 |
$main::lxdebug->enter_sub(); |
395 | 395 |
|
396 |
my ($self, $form, $dbh, $filename) = @_; |
|
396 |
my ($self, $form, $dbh, $filename, $version) = @_;
|
|
397 | 397 |
|
398 | 398 |
# return unless (-f $filename); |
399 | 399 |
|
... | ... | |
402 | 402 |
my $sth; |
403 | 403 |
my @quote_chars; |
404 | 404 |
|
405 |
$dbh->begin_work(); |
|
406 |
|
|
405 | 407 |
while (<FH>) { |
406 | 408 |
|
407 | 409 |
# Remove DOS and Unix style line endings. |
... | ... | |
429 | 431 |
# Query is complete. Send it. |
430 | 432 |
|
431 | 433 |
$sth = $dbh->prepare($query); |
432 |
$sth->execute || $form->dberror($query); |
|
433 |
$sth->finish; |
|
434 |
if (!$sth->execute()) { |
|
435 |
$sth->finish(); |
|
436 |
$dbh->rollback(); |
|
437 |
$form->dberror("The database update/creation did not succeed. The file ${filename} containing the following query failed:<br>${query}<br>" . |
|
438 |
"All changes in that file have been reverted."); |
|
439 |
} |
|
440 |
$sth->finish(); |
|
434 | 441 |
|
435 | 442 |
$char = ""; |
436 | 443 |
$query = ""; |
... | ... | |
441 | 448 |
} |
442 | 449 |
} |
443 | 450 |
|
451 |
if ($version) { |
|
452 |
$dbh->do("UPDATE defaults SET version = " . $dbh->quote($version)); |
|
453 |
} |
|
454 |
$dbh->commit(); |
|
455 |
|
|
444 | 456 |
close FH; |
445 | 457 |
|
446 | 458 |
$main::lxdebug->leave_sub(); |
... | ... | |
696 | 708 |
$a =~ s/^$form->{dbdriver}-upgrade-|\.sql$//g; |
697 | 709 |
|
698 | 710 |
my ($mindb, $maxdb) = split /-/, $a; |
711 |
my $str_maxdb = $maxdb; |
|
699 | 712 |
## LINET |
700 | 713 |
$mindb = calc_version($mindb); |
701 | 714 |
$maxdb = calc_version($maxdb); |
... | ... | |
707 | 720 |
last if ($version < $mindb); |
708 | 721 |
|
709 | 722 |
# apply upgrade |
710 |
$self->process_query($form, $dbh, "sql/$upgradescript"); |
|
723 |
$self->process_query($form, $dbh, "sql/$upgradescript", $str_maxdb);
|
|
711 | 724 |
|
712 | 725 |
$version = $maxdb; |
713 | 726 |
|
Auch abrufbar als: Unified diff
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.