Revision 19616466
Von Moritz Bunkus vor mehr als 9 Jahren hinzugefügt
sql/Pg-upgrade2/convert_taxzone.pl | ||
---|---|---|
39 | 39 |
} |
40 | 40 |
$sth->finish; |
41 | 41 |
|
42 |
my $taxzone_charts_update_query = "INSERT INTO taxzone_charts (taxzone_id, buchungsgruppen_id, income_accno_id, expense_accno_id) VALUES (?, ?, ?, ?)"; |
|
43 |
$sth = $self->dbh->prepare($taxzone_charts_update_query); |
|
44 |
|
|
42 | 45 |
# convert Buchungsgruppen to taxzone_charts if any exist |
43 | 46 |
# the default swiss COA doesn't have any, for example |
44 |
if ( scalar @{ $::form->{buchungsgruppen} } > 0 ) { |
|
45 |
my $taxzone_charts_update_query; |
|
47 |
if ( scalar @{ $::form->{buchungsgruppen} } > 0 ) { |
|
46 | 48 |
foreach my $taxzone ( @{$::form->{taxzones}} ) { |
47 | 49 |
foreach my $buchungsgruppe ( @{$::form->{buchungsgruppen}} ) { |
48 | 50 |
my $id = $taxzone->{id}; |
49 | 51 |
my $income_accno_id = $buchungsgruppe->{"income_accno_id_$id"}; |
50 | 52 |
my $expense_accno_id = $buchungsgruppe->{"expense_accno_id_$id"}; |
51 |
# TODO: check if the variables have a value |
|
52 |
$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"; |
|
53 |
my @values = ($taxzone->{id}, $buchungsgruppe->{id}, $income_accno_id, $expense_accno_id); |
|
54 |
$sth->execute(@values) && next; |
|
55 |
$taxzone_charts_update_query =~ s{\?}{shift(@values)}eg; |
|
56 |
$::form->dberror($taxzone_charts_update_query); |
|
53 | 57 |
}; |
54 | 58 |
}; |
55 |
$self->db_query($taxzone_charts_update_query) if $taxzone_charts_update_query; |
|
56 | 59 |
}; |
57 | 60 |
|
61 |
$sth->finish; |
|
62 |
|
|
58 | 63 |
my $clean_buchungsgruppen_query = <<SQL; |
59 | 64 |
alter table buchungsgruppen drop column income_accno_id_0; |
60 | 65 |
alter table buchungsgruppen drop column income_accno_id_1; |
Auch abrufbar als: Unified diff
convert_taxzones-Upgrade: prepared statement für Fehlermeldungen und Performance