From cafc615b0f7014d1ac110d0d241e6733480366aa Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Thu, 8 Sep 2016 16:51:27 +0200 Subject: [PATCH] RC: single-dbh disconnects --- SL/RC.pm | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/SL/RC.pm b/SL/RC.pm index 1ccf7ab9e..bd77fea12 100644 --- a/SL/RC.pm +++ b/SL/RC.pm @@ -35,6 +35,7 @@ package RC; use SL::DBUtils; +use SL::DB; use strict; @@ -43,8 +44,7 @@ sub paymentaccounts { my ($self, $myconfig, $form) = @_; - # connect to database - my $dbh = $form->dbconnect($myconfig); + my $dbh = SL::DB->client->dbh; my $query = qq|SELECT accno, description | . @@ -53,7 +53,6 @@ sub paymentaccounts { qq|ORDER BY accno|; $form->{PR} = selectall_hashref_query($form, $dbh, $query); - $dbh->disconnect; $main::lxdebug->leave_sub(); } @@ -223,30 +222,30 @@ sub reconcile { my ($self, $myconfig, $form) = @_; - # connect to database - my $dbh = $form->dbconnect($myconfig); - - my ($query, $i); + SL::DB->client->with_transaction(sub { + my $dbh = SL::DB->client->dbh; - # clear flags - for $i (1 .. $form->{rowcount}) { - if ($form->{"cleared_$i"}) { - $query = - qq|UPDATE acc_trans SET cleared = '1' | . - qq|WHERE acc_trans_id = ?|; - do_query($form, $dbh, $query, $form->{"oid_$i"}); + my ($query, $i); - # clear fx_transaction - if ($form->{"fxoid_$i"}) { + # clear flags + for $i (1 .. $form->{rowcount}) { + if ($form->{"cleared_$i"}) { $query = qq|UPDATE acc_trans SET cleared = '1' | . qq|WHERE acc_trans_id = ?|; - do_query($form, $dbh, $query, $form->{"fxoid_$i"}); + do_query($form, $dbh, $query, $form->{"oid_$i"}); + + # clear fx_transaction + if ($form->{"fxoid_$i"}) { + $query = + qq|UPDATE acc_trans SET cleared = '1' | . + qq|WHERE acc_trans_id = ?|; + do_query($form, $dbh, $query, $form->{"fxoid_$i"}); + } } } - } - - $dbh->disconnect; + 1; + }) or do { die SL::DB->client->error }; $main::lxdebug->leave_sub(); } -- 2.20.1