Revision d65bfa97
Von Moritz Bunkus vor mehr als 17 Jahren hinzugefügt
sql/Pg-upgrade2/USTVA_abstraction.pl | ||
---|---|---|
3 | 3 |
# @depends: release_2_4_2 |
4 | 4 |
|
5 | 5 |
# Abstraktionlayer between general Taxreports and USTVA |
6 |
# Most of the data and structures are not used yet, but maybe in future,
|
|
6 |
# Most of the data and structures are not used yet, but maybe in future, |
|
7 | 7 |
# if there are other international customizings are requested... |
8 | 8 |
|
9 | 9 |
################### |
10 | 10 |
|
11 | 11 |
die("This script cannot be run from the command line.") unless ($main::form); |
12 | 12 |
|
13 |
sub mydberror { |
|
14 |
my ($msg) = @_; |
|
15 |
die($dbup_locale->text("Database update error:") . |
|
16 |
"<br>$msg<br>" . $DBI::errstr); |
|
17 |
} |
|
18 |
|
|
13 | 19 |
sub do_query { |
14 | 20 |
my ($query, $may_fail) = @_; |
15 | 21 |
|
... | ... | |
32 | 38 |
description text, |
33 | 39 |
subdescription text |
34 | 40 |
); |
35 |
},
|
|
41 |
}, |
|
36 | 42 |
q{ CREATE TABLE tax.report_headings ( |
37 | 43 |
id integer NOT NULL PRIMARY KEY, |
38 | 44 |
category_id integer NOT NULL REFERENCES tax.report_categorys(id), |
... | ... | |
55 | 61 |
|
56 | 62 |
do_query("DROP SCHEMA tax CASCADE;", 1); |
57 | 63 |
map({ do_query($_, 0); } @queries); |
58 |
|
|
64 |
|
|
59 | 65 |
return 1; |
60 |
|
|
66 |
|
|
61 | 67 |
} |
62 | 68 |
|
63 | 69 |
sub do_copy { |
64 | 70 |
|
65 | 71 |
my @copy_statements = ( |
66 |
"COPY tax.report_categorys FROM STDIN WITH DELIMITER ';'",
|
|
67 |
"COPY tax.report_headings FROM STDIN WITH DELIMITER ';'",
|
|
68 |
"COPY tax.report_variables FROM STDIN WITH DELIMITER ';'",
|
|
72 |
"INSERT INTO tax.report_categorys (id, description, subdescription) VALUES (?, ?, ?)",
|
|
73 |
"INSERT INTO tax.report_headings (id, category_id, type, description, subdescription) VALUES (?, ?, ?, ?, ?)",
|
|
74 |
"INSERT INTO tax.report_variables (id, position, heading_id, description, taxbase, dec_places, valid_from) VALUES (?, ?, ?, ?, ?, ?, ?)",
|
|
69 | 75 |
); |
70 | 76 |
|
71 | 77 |
my @copy_data = ( |
... | ... | |
138 | 144 |
); |
139 | 145 |
|
140 | 146 |
for my $statement ( 0 .. $#copy_statements ) { |
147 |
my $query = $iconv->convert($copy_statements[$statement]); |
|
148 |
my $sth = $dbh->prepare($query) || mydberror($query); |
|
141 | 149 |
|
142 |
do_query($iconv->convert($copy_statements[$statement]), 0); |
|
143 |
|
|
144 | 150 |
for my $copy_line ( 1 .. $#{$copy_data[$statement]} ) { |
145 | 151 |
#print $copy_data[$statement][$copy_line] . "<br />" |
146 |
$dbh->pg_putline($iconv->convert($copy_data[$statement][$copy_line]) . "\n");
|
|
152 |
$sth->execute(split m/;/, $iconv->convert($copy_data[$statement][$copy_line]), -1) || mydberror($query);
|
|
147 | 153 |
} |
148 |
$dbh->pg_endcopy;
|
|
154 |
$sth->finish();
|
|
149 | 155 |
} |
150 | 156 |
return 1; |
151 | 157 |
} |
152 | 158 |
|
153 | 159 |
|
154 | 160 |
return create_tables() && do_copy(); |
155 |
|
Auch abrufbar als: Unified diff
1. Umstellung von der Verwendung von COPY-Statements auf normale INSERT-Statements. Grund ist, dass die dafür benötigten Befehle DBD::Pg::pg_putline() und pg_endcopy() nur in neueren Versionen von DBD::Pg existieren. Der Performancenachteil durch die Verwendung von INSERTs ist bei dieser geringen Datenmenge vernachlässigbar. Fix für Bug 668.
2. Die Funktion mydberror() muss definiert werden, wenn sie benutzt werden soll.
3. Kosmetik: Trailing whitespaces entfernt.