From 196164663c7c837e3a2d1dfe3231ac8ff949542c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 30 Apr 2015 10:52:13 +0200 Subject: [PATCH] =?utf8?q?convert=5Ftaxzones-Upgrade:=20prepared=20stateme?= =?utf8?q?nt=20f=C3=BCr=20Fehlermeldungen=20und=20Performance?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sql/Pg-upgrade2/convert_taxzone.pl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/sql/Pg-upgrade2/convert_taxzone.pl b/sql/Pg-upgrade2/convert_taxzone.pl index b1e1a0bb6..3343c6f12 100644 --- a/sql/Pg-upgrade2/convert_taxzone.pl +++ b/sql/Pg-upgrade2/convert_taxzone.pl @@ -39,22 +39,27 @@ SQL } $sth->finish; + my $taxzone_charts_update_query = "INSERT INTO taxzone_charts (taxzone_id, buchungsgruppen_id, income_accno_id, expense_accno_id) VALUES (?, ?, ?, ?)"; + $sth = $self->dbh->prepare($taxzone_charts_update_query); + # convert Buchungsgruppen to taxzone_charts if any exist # the default swiss COA doesn't have any, for example - if ( scalar @{ $::form->{buchungsgruppen} } > 0 ) { - my $taxzone_charts_update_query; + if ( scalar @{ $::form->{buchungsgruppen} } > 0 ) { foreach my $taxzone ( @{$::form->{taxzones}} ) { foreach my $buchungsgruppe ( @{$::form->{buchungsgruppen}} ) { my $id = $taxzone->{id}; my $income_accno_id = $buchungsgruppe->{"income_accno_id_$id"}; my $expense_accno_id = $buchungsgruppe->{"expense_accno_id_$id"}; - # TODO: check if the variables have a value - $taxzone_charts_update_query .= "INSERT INTO taxzone_charts (taxzone_id, buchungsgruppen_id, income_accno_id, expense_accno_id) VALUES ('$taxzone->{id}', '$buchungsgruppe->{id}', $income_accno_id, $expense_accno_id);\n"; + my @values = ($taxzone->{id}, $buchungsgruppe->{id}, $income_accno_id, $expense_accno_id); + $sth->execute(@values) && next; + $taxzone_charts_update_query =~ s{\?}{shift(@values)}eg; + $::form->dberror($taxzone_charts_update_query); }; }; - $self->db_query($taxzone_charts_update_query) if $taxzone_charts_update_query; }; + $sth->finish; + my $clean_buchungsgruppen_query = <