From af380e64a8286293cd57e554818aa1447f945561 Mon Sep 17 00:00:00 2001 From: Kenza Zaki Date: Mon, 5 Aug 2013 15:55:40 +0200 Subject: [PATCH] Bug 10685: Inappropriate uses of finish in C4::Accounts.pm This patch gets rid of finish. From the man page finish() Indicate that no more data will be fetched from this statement handle before it is either executed again or destroyed. You almost certainly do not need to call this method. Adding calls to "finish" after loop that fetches all rows is a common mistake, don't do it, it can mask genuine problems like uncaught fetch errors. Signed-off-by: Bernardo Gonzalez Kriegel Comment: Similar to other patches from the same author. Run prove t/db_dependent/Accounts.t without errors No koha-qa errors Signed-off-by: Chris Cormack --- C4/Accounts.pm | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/C4/Accounts.pm b/C4/Accounts.pm index f087b7a..4b4ae04 100644 --- a/C4/Accounts.pm +++ b/C4/Accounts.pm @@ -202,7 +202,6 @@ sub makepayment { my $sth = $dbh->prepare("SELECT * FROM accountlines WHERE accountlines_id=?"); $sth->execute( $accountlines_id ); my $data = $sth->fetchrow_hashref; - $sth->finish; my $payment; if ( $data->{'accounttype'} eq "Pay" ){ @@ -214,7 +213,6 @@ sub makepayment { " ); $udp->execute($accountlines_id); - $udp->finish; }else{ my $udp = $dbh->prepare( @@ -224,7 +222,6 @@ sub makepayment { " ); $udp->execute($accountlines_id); - $udp->finish; # create new line my $payment = 0 - $amount; @@ -237,7 +234,6 @@ sub makepayment { VALUES ( ?, ?, now(), ?, ?, 'Payment,thanks', 'Pay', 0, ?, ?)" ); $ins->execute($borrowernumber, $nextaccntno, $payment, $data->{'itemnumber'}, $manager_id, $payment_note); - $ins->finish; } if ( C4::Context->preference("FinesLog") ) { @@ -279,7 +275,6 @@ sub makepayment { my $sthr = $dbh->prepare("SELECT max(accountlines_id) AS lastinsertid FROM accountlines"); $sthr->execute(); my $datalastinsertid = $sthr->fetchrow_hashref; - $sthr->finish; return $datalastinsertid->{'lastinsertid'}; } @@ -364,7 +359,6 @@ sub chargelostitem{ VALUES (?,?,now(),?,?,'L',?,?,?)"); $sth2->execute($borrowernumber,$accountno,$amount, $description,$amount,$itemnumber,$manager_id); - $sth2->finish; if ( C4::Context->preference("FinesLog") ) { logaction("FINES", 'CREATE', $borrowernumber, Dumper({ @@ -532,7 +526,6 @@ sub fixcredit { my $sth = $dbh->prepare($query); $sth->execute( $borrowernumber, $item->{'itemnumber'} ); $accdata = $sth->fetchrow_hashref; - $sth->finish; if ( $accdata->{'amountoutstanding'} < $amountleft ) { $newamtos = 0; $amountleft -= $accdata->{'amountoutstanding'}; @@ -547,7 +540,6 @@ sub fixcredit { WHERE (accountlines_id = ?)" ); $usth->execute( $newamtos, $thisacct ); - $usth->finish; $usth = $dbh->prepare( "INSERT INTO accountoffsets (borrowernumber, accountno, offsetaccount, offsetamount) @@ -555,7 +547,6 @@ sub fixcredit { ); $usth->execute( $borrowernumber, $accdata->{'accountno'}, $nextaccntno, $newamtos ); - $usth->finish; } # begin transaction @@ -586,7 +577,6 @@ sub fixcredit { WHERE (accountlines_id = ?)" ); $usth->execute( $newamtos, $thisacct ); - $usth->finish; $usth = $dbh->prepare( "INSERT INTO accountoffsets (borrowernumber, accountno, offsetaccount, offsetamount) @@ -594,9 +584,7 @@ sub fixcredit { ); $usth->execute( $borrowernumber, $accdata->{'accountno'}, $nextaccntno, $newamtos ); - $usth->finish; } - $sth->finish; $type = "Credit " . $type; UpdateStats( $user, $type, $data, $user, '', '', $borrowernumber ); $amountleft *= -1; @@ -652,7 +640,6 @@ sub refund { WHERE (accountlines_id = ?)" ); $usth->execute( $newamtos, $thisacct ); - $usth->finish; $usth = $dbh->prepare( "INSERT INTO accountoffsets (borrowernumber, accountno, offsetaccount, offsetamount) @@ -660,9 +647,7 @@ sub refund { ); $usth->execute( $borrowernumber, $accdata->{'accountno'}, $nextaccntno, $newamtos ); - $usth->finish; } - $sth->finish; return ($amountleft); } -- 1.8.1.2