From d65bfa97a852b44c2a713ae2f7dc266269814488 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 6 Jun 2007 07:20:32 +0000 Subject: [PATCH] =?utf8?q?1.=20Umstellung=20von=20der=20Verwendung=20von?= =?utf8?q?=20COPY-Statements=20auf=20normale=20INSERT-Statements.=20Grund?= =?utf8?q?=20ist,=20dass=20die=20daf=C3=BCr=20ben=C3=B6tigten=20Befehle=20?= =?utf8?q?DBD::Pg::pg=5Fputline()=20und=20pg=5Fendcopy()=20nur=20in=20neue?= =?utf8?q?ren=20Versionen=20von=20DBD::Pg=20existieren.=20Der=20Performanc?= =?utf8?q?enachteil=20durch=20die=20Verwendung=20von=20INSERTs=20ist=20bei?= =?utf8?q?=20dieser=20geringen=20Datenmenge=20vernachl=C3=A4ssigbar.=20Fix?= =?utf8?q?=20f=C3=BCr=20Bug=20668.=202.=20Die=20Funktion=20mydberror()=20m?= =?utf8?q?uss=20definiert=20werden,=20wenn=20sie=20benutzt=20werden=20soll?= =?utf8?q?.=203.=20Kosmetik:=20Trailing=20whitespaces=20entfernt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- sql/Pg-upgrade2/USTVA_abstraction.pl | 29 ++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/sql/Pg-upgrade2/USTVA_abstraction.pl b/sql/Pg-upgrade2/USTVA_abstraction.pl index 20f512d4d..9c2171884 100644 --- a/sql/Pg-upgrade2/USTVA_abstraction.pl +++ b/sql/Pg-upgrade2/USTVA_abstraction.pl @@ -3,13 +3,19 @@ # @depends: release_2_4_2 # Abstraktionlayer between general Taxreports and USTVA -# Most of the data and structures are not used yet, but maybe in future, +# Most of the data and structures are not used yet, but maybe in future, # if there are other international customizings are requested... ################### die("This script cannot be run from the command line.") unless ($main::form); +sub mydberror { + my ($msg) = @_; + die($dbup_locale->text("Database update error:") . + "
$msg
" . $DBI::errstr); +} + sub do_query { my ($query, $may_fail) = @_; @@ -32,7 +38,7 @@ sub create_tables { description text, subdescription text ); - }, + }, q{ CREATE TABLE tax.report_headings ( id integer NOT NULL PRIMARY KEY, category_id integer NOT NULL REFERENCES tax.report_categorys(id), @@ -55,17 +61,17 @@ sub create_tables { do_query("DROP SCHEMA tax CASCADE;", 1); map({ do_query($_, 0); } @queries); - + return 1; - + } sub do_copy { my @copy_statements = ( - "COPY tax.report_categorys FROM STDIN WITH DELIMITER ';'", - "COPY tax.report_headings FROM STDIN WITH DELIMITER ';'", - "COPY tax.report_variables FROM STDIN WITH DELIMITER ';'", + "INSERT INTO tax.report_categorys (id, description, subdescription) VALUES (?, ?, ?)", + "INSERT INTO tax.report_headings (id, category_id, type, description, subdescription) VALUES (?, ?, ?, ?, ?)", + "INSERT INTO tax.report_variables (id, position, heading_id, description, taxbase, dec_places, valid_from) VALUES (?, ?, ?, ?, ?, ?, ?)", ); my @copy_data = ( @@ -138,18 +144,17 @@ sub do_copy { ); for my $statement ( 0 .. $#copy_statements ) { + my $query = $iconv->convert($copy_statements[$statement]); + my $sth = $dbh->prepare($query) || mydberror($query); - do_query($iconv->convert($copy_statements[$statement]), 0); - for my $copy_line ( 1 .. $#{$copy_data[$statement]} ) { #print $copy_data[$statement][$copy_line] . "
" - $dbh->pg_putline($iconv->convert($copy_data[$statement][$copy_line]) . "\n"); + $sth->execute(split m/;/, $iconv->convert($copy_data[$statement][$copy_line]), -1) || mydberror($query); } - $dbh->pg_endcopy; + $sth->finish(); } return 1; } return create_tables() && do_copy(); - -- 2.20.1