From 32ddb71c1b2a113b297e729817dda69a1afa203c Mon Sep 17 00:00:00 2001 From: Niclas Zimmermann Date: Thu, 21 Feb 2013 09:50:08 +0100 Subject: [PATCH] Verbesserung Upgrade-Script MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Dieser Commit enthält noch einige kleine Verbesserungen zum Update tax_constraints.pl. Es wurden Einrückungen verändert, trailing white- spaces entfernt und eine Abhängigkeit hinzugefügt. --- sql/Pg-upgrade2/tax_constraints.pl | 200 ++++++++++++++--------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/sql/Pg-upgrade2/tax_constraints.pl b/sql/Pg-upgrade2/tax_constraints.pl index 7567930a2..70fe83d35 100644 --- a/sql/Pg-upgrade2/tax_constraints.pl +++ b/sql/Pg-upgrade2/tax_constraints.pl @@ -1,6 +1,6 @@ # @tag: tax_constraints # @description: Setzt Fremdschlüssel und andere constraints auf die Tabellen tax und taxkeys -# @depends: release_3_0_0 +# @depends: release_3_0_0 charts_without_taxkey # @charset: utf-8 use utf8; @@ -25,30 +25,30 @@ sub do_query { } sub do_update { -#CHECK CONSISTANCY OF tax + #CHECK CONSISTANCY OF tax #update tax.rate and tax.taxdescription in order to set later NOT NULL constraints -my $query= <selectrow_array($query); - + if ($invalid_tax_account > 0){ #list all invalid tax accounts $query = <prepare($query); @@ -63,25 +63,25 @@ SQL $main::form->{invalid_tax_account} = 1; print_error_message(); return 0; - } + } #check entry tax.taxkey of NOT NULL $query= <selectrow_array($query); - + if ($taxkey_is_null > 0){ #list all invalid tax accounts $query = <prepare($query); @@ -96,58 +96,58 @@ SQL $main::form->{taxkey_is_null} = 1; print_error_message(); return 0; - } -#END CHECK OF tax + } + #END CHECK OF tax -#CHECK CONSISTANCY OF taxkeys + #CHECK CONSISTANCY OF taxkeys #delete invalide entries in taxkeys $query= <prepare($query); @@ -160,39 +160,39 @@ SQL $rowcount++; } $sth->finish; - + my $insertquery; my $updatequery; my $tax_id; for my $i (0 .. $rowcount-1){ $query= qq| -SELECT id FROM tax WHERE rate = 0 and taxkey=| . $main::form->{TAXID}[$i]->{taxkey_id} . qq| LIMIT 1 -|; - ($tax_id) = $dbh->selectrow_array($query); + SELECT id FROM tax WHERE rate = 0 and taxkey=| . $main::form->{TAXID}[$i]->{taxkey_id} . qq| LIMIT 1 +|; + ($tax_id) = $dbh->selectrow_array($query); if ( not $tax_id ){ $insertquery=qq| -INSERT INTO tax (rate, taxdescription, taxkey) VALUES (0, '| . $::locale->text('0% tax with taxkey') . $main::form->{TAXID}[$i]->{taxkey_id} . $::locale->text('. Automatically generated.') . -qq|', | . $main::form->{TAXID}[$i]->{taxkey_id} . qq|); + INSERT INTO tax (rate, taxdescription, taxkey) VALUES (0, '| . $::locale->text('0% tax with taxkey') . $main::form->{TAXID}[$i]->{taxkey_id} . $::locale->text('. Automatically generated.') . + qq|', | . $main::form->{TAXID}[$i]->{taxkey_id} . qq|); |; do_query($insertquery); ($tax_id) = $dbh->selectrow_array($query); - $tax_id || $main::form->dberror($query); + $tax_id || $main::form->dberror($query); } $updatequery = qq| -UPDATE taxkeys SET tax_id= | . $tax_id . qq| WHERE taxkey_id = | . $main::form->{TAXID}[$i]->{taxkey_id} . qq| AND tax_id IS NULL + UPDATE taxkeys SET tax_id= | . $tax_id . qq| WHERE taxkey_id = | . $main::form->{TAXID}[$i]->{taxkey_id} . qq| AND tax_id IS NULL |; do_query($updatequery); } -#The triple taxkey_id, chart_id, startdate in taxkeys has to be unique + #The triple taxkey_id, chart_id, startdate in taxkeys has to be unique #Select these entries: $query= < 1; + SELECT DISTINCT tk1.chart_id AS chart_id, tk1.startdate AS startdate + FROM taxkeys tk1 + WHERE (SELECT count(*) + FROM taxkeys tk2 + WHERE tk2.chart_id = tk1.chart_id + AND tk2.startdate = tk1.startdate) > 1; SQL $sth = $dbh->prepare($query); @@ -207,91 +207,91 @@ SQL $sth->finish; for my $i (0 .. $rowcount-1){ - $query= qq| -DELETE FROM taxkeys tk1 -WHERE (SELECT count(*) - FROM taxkeys tk2 - WHERE tk2.chart_id = tk1.chart_id - AND tk2.startdate = tk1.startdate) > 1 -AND NOT tk1.id = (SELECT id - FROM taxkeys - WHERE chart_id = | . $main::form->{TAXKEYS}[$i]->{chart_id} . qq| - AND startdate = '| . $main::form->{TAXKEYS}[$i]->{startdate} . qq|' - LIMIT 1) + $query= qq| + DELETE FROM taxkeys tk1 + WHERE (SELECT count(*) + FROM taxkeys tk2 + WHERE tk2.chart_id = tk1.chart_id + AND tk2.startdate = tk1.startdate) > 1 + AND NOT tk1.id = (SELECT id + FROM taxkeys + WHERE chart_id = | . $main::form->{TAXKEYS}[$i]->{chart_id} . qq| + AND startdate = '| . $main::form->{TAXKEYS}[$i]->{startdate} . qq|' + LIMIT 1) |; do_query($query); } -#END CHECK OF taxkeys + #END CHECK OF taxkeys -#ADD CONSTRAINTS: -#Now the database is consistent, so we can add constraints: + #ADD CONSTRAINTS: + #Now the database is consistent, so we can add constraints: #Crate NOT NULL constraint for tax.rate with default value 0 $query= <