From e2332bfd203a5d9925034dfdd90a15b3c9c66044 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 27 Jan 2017 11:51:48 +0100 Subject: [PATCH] DB Handling: Einige executes mit Fehlerbehandlung versehen --- SL/Controller/CsvImport.pm | 25 +++++++++++++------------ SL/DB/Helper/ActsAsList.pm | 3 ++- SL/GoBD.pm | 2 +- SL/IC.pm | 5 +++-- SL/SEPA.pm | 2 +- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/SL/Controller/CsvImport.pm b/SL/Controller/CsvImport.pm index fa988cb4f..0da6e7005 100644 --- a/SL/Controller/CsvImport.pm +++ b/SL/Controller/CsvImport.pm @@ -8,6 +8,7 @@ use SL::DB::CsvImportProfile; use SL::DB::CsvImportReport; use SL::DB::Unit; use SL::DB::Helper::Paginated (); +use SL::DBUtils qw(do_statement); use SL::Helper::Flash; use SL::Locale::String; use SL::SessionFile; @@ -544,7 +545,7 @@ sub save_report_single { push @raw_methods, $self->raw_data_headers->{headers}->[$i]; } - $sth->execute($report->id, $_, 0, $headers[$_]) for 0 .. $#headers; + do_statement($::form, $sth, $query, $report->id, $_, 0, $headers[$_]) for 0 .. $#headers; # col offsets my $o1 = @info_methods; @@ -554,12 +555,12 @@ sub save_report_single { $self->track_progress(progress => $row / @{ $self->data } * 100) if $row % 1000 == 0; my $data_row = $self->{data}[$row]; - $sth->execute($report->id, $_, $row + 1, $data_row->{info_data}{ $info_methods[$_] }) for 0 .. $#info_methods; - $sth->execute($report->id, $o1 + $_, $row + 1, $data_row->{object}->${ \ $methods[$_] }) for 0 .. $#methods; - $sth->execute($report->id, $o2 + $_, $row + 1, $data_row->{raw_data}{ $raw_methods[$_] }) for 0 .. $#raw_methods; + do_statement($::form, $sth, $query, $report->id, $_, $row + 1, $data_row->{info_data}{ $info_methods[$_] }) for 0 .. $#info_methods; + do_statement($::form, $sth, $query, $report->id, $o1 + $_, $row + 1, $data_row->{object}->${ \ $methods[$_] }) for 0 .. $#methods; + do_statement($::form, $sth, $query, $report->id, $o2 + $_, $row + 1, $data_row->{raw_data}{ $raw_methods[$_] }) for 0 .. $#raw_methods; - $sth2->execute($report->id, $row + 1, 'information', $_) for @{ $data_row->{information} || [] }; - $sth2->execute($report->id, $row + 1, 'errors', $_) for @{ $data_row->{errors} || [] }; + do_statement($::form, $sth2, $query2, $report->id, $row + 1, 'information', $_) for @{ $data_row->{information} || [] }; + do_statement($::form, $sth2, $query2, $report->id, $row + 1, 'errors', $_) for @{ $data_row->{errors} || [] }; } 1; }) or do { die SL::DB->client->error }; @@ -623,7 +624,7 @@ sub save_report_multi { for my $i (0 .. $#{ $self->worker->profile }) { my $row_ident = $self->worker->profile->[$i]->{row_ident}; - $sth->execute($report->id, $_, $i, $headers->{$row_ident}->[$_]) for 0 .. $#{ $headers->{$row_ident} }; + do_statement($::form, $sth, $query, $report->id, $_, $i, $headers->{$row_ident}->[$_]) for 0 .. $#{ $headers->{$row_ident} }; } # col offsets @@ -647,12 +648,12 @@ sub save_report_multi { my $o1 = $off1->{$row_ident}; my $o2 = $off2->{$row_ident}; - $sth->execute($report->id, $_, $row + $n_header_rows, $data_row->{info_data}{ $info_methods->{$row_ident}->[$_] }) for 0 .. $#{ $info_methods->{$row_ident} }; - $sth->execute($report->id, $o1 + $_, $row + $n_header_rows, $data_row->{object}->${ \ $methods->{$row_ident}->[$_] }) for 0 .. $#{ $methods->{$row_ident} }; - $sth->execute($report->id, $o2 + $_, $row + $n_header_rows, $data_row->{raw_data}{ $raw_methods->{$row_ident}->[$_] }) for 0 .. $#{ $raw_methods->{$row_ident} }; + do_statement($::form, $sth, $query, $report->id, $_, $row + $n_header_rows, $data_row->{info_data}{ $info_methods->{$row_ident}->[$_] }) for 0 .. $#{ $info_methods->{$row_ident} }; + do_statement($::form, $sth, $query, $report->id, $o1 + $_, $row + $n_header_rows, $data_row->{object}->${ \ $methods->{$row_ident}->[$_] }) for 0 .. $#{ $methods->{$row_ident} }; + do_statement($::form, $sth, $query, $report->id, $o2 + $_, $row + $n_header_rows, $data_row->{raw_data}{ $raw_methods->{$row_ident}->[$_] }) for 0 .. $#{ $raw_methods->{$row_ident} }; - $sth2->execute($report->id, $row + $n_header_rows, 'information', $_) for @{ $data_row->{information} || [] }; - $sth2->execute($report->id, $row + $n_header_rows, 'errors', $_) for @{ $data_row->{errors} || [] }; + do_statement($::form, $sth2, $query2, $report->id, $row + $n_header_rows, 'information', $_) for @{ $data_row->{information} || [] }; + do_statement($::form, $sth2, $query2, $report->id, $row + $n_header_rows, 'errors', $_) for @{ $data_row->{errors} || [] }; } 1; }) or do { die SL::DB->client->error }; diff --git a/SL/DB/Helper/ActsAsList.pm b/SL/DB/Helper/ActsAsList.pm index ee49f4aed..abe11c063 100644 --- a/SL/DB/Helper/ActsAsList.pm +++ b/SL/DB/Helper/ActsAsList.pm @@ -7,6 +7,7 @@ our @EXPORT = qw(move_position_up move_position_down add_to_list remove_from_lis get_previous_in_list get_next_in_list get_full_list); use Carp; +use SL::X; my %list_spec; @@ -145,7 +146,7 @@ sub reorder_list { my $sth = $self->db->dbh->prepare($query) || die $self->db->dbh->errstr; foreach my $new_position (1 .. scalar(@ids)) { - $sth->execute($new_position, $ids[$new_position - 1]) || die $sth->errstr; + $sth->execute($new_position, $ids[$new_position - 1]) || die SL::X::DBUtilsError->new(error => $sth->errstr); } $sth->finish; diff --git a/SL/GoBD.pm b/SL/GoBD.pm index 2992b5f4e..45f055f85 100644 --- a/SL/GoBD.pm +++ b/SL/GoBD.pm @@ -549,7 +549,7 @@ sub do_csv_export { my $query = "SELECT " . join(', ', @select_tokens) . " FROM $table $where_clause"; my $sth = $::form->get_standard_dbh->prepare($query); - $sth->execute(@values) or die "error executing query $query: " . $sth->errstr; + $sth->execute(@values) or $::form->dberror($query); while (my $row = $sth->fetch) { for my $keep_col (@{ $known_tables{$table}{keep} || [] }) { diff --git a/SL/IC.pm b/SL/IC.pm index cf137928b..310961bfa 100644 --- a/SL/IC.pm +++ b/SL/IC.pm @@ -762,7 +762,7 @@ sub retrieve_accounts { p.id IN ($in) SQL - my $sth_tax = prepare_query($::form, $dbh, < $part_id) = each %args) { my $ref = $accno_by_part{$part_id} or next; @@ -787,7 +788,7 @@ SQL $form->{"${_}_accno_$index"} = $accounts{"${_}_accno"} for qw(inventory income expense); - $sth_tax->execute($accounts{$inc_exp}, quote_db_date($transdate)); + $sth_tax->execute($accounts{$inc_exp}, quote_db_date($transdate)) || $::form->dberror($query_tax); $ref = $sth_tax->fetchrow_hashref or next; $form->{"taxaccounts_$index"} = $ref->{"accno"}; diff --git a/SL/SEPA.pm b/SL/SEPA.pm index 7724a52aa..3231ac9e9 100644 --- a/SL/SEPA.pm +++ b/SL/SEPA.pm @@ -168,7 +168,7 @@ sub _create_export { $transfer->{reference} = "${invnumber}-${num_payments}"; } - $h_item_id->execute(); + $h_item_id->execute() || $::form->dberror($q_item_id); my ($item_id) = $h_item_id->fetchrow_array(); my $end_to_end_id = strftime "LXO%Y%m%d%H%M%S", localtime; -- 2.20.1