Bug 10685: remove inappropriate uses of finish in C4::Accounts.pm
authorKenza Zaki <kenza.zaki@biblibre.com>
Mon, 5 Aug 2013 13:55:40 +0000 (15:55 +0200)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 9 Oct 2013 03:35:37 +0000 (03:35 +0000)
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 <bgkriegel@gmail.com>
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 <chrisc@catalyst.net.nz>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
C4/Accounts.pm

index f087b7a..4b4ae04 100644 (file)
@@ -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);
 }