From c6b8004932a54b4d73b06a1b2d61e44e4027a4a9 Mon Sep 17 00:00:00 2001 From: Kenza Zaki Date: Thu, 25 Jul 2013 13:47:09 +0200 Subject: [PATCH] Bug 10642 : Inappropriate uses of $sth->finish() in C4::RotatingCollections.pm 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. http://bugs.koha-community.org/show_bug.cgi?id=10653 --- C4/RotatingCollections.pm | 18 ------------------ t/db_dependent/RotatingCollections.t | 5 +++-- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/C4/RotatingCollections.pm b/C4/RotatingCollections.pm index d8b94b3..09b5216 100644 --- a/C4/RotatingCollections.pm +++ b/C4/RotatingCollections.pm @@ -99,7 +99,6 @@ sub CreateCollection { $sth = $dbh->prepare("INSERT INTO collections ( colId, colTitle, colDesc ) VALUES ( NULL, ?, ? )"); $sth->execute( $title, $description ) or return ( 0, 3, $sth->errstr() ); - $sth->finish; return 1; @@ -145,7 +144,6 @@ sub UpdateCollection { colTitle = ?, colDesc = ? WHERE colId = ?"); $sth->execute( $title, $description, $colId ) or return ( 0, 4, $sth->errstr() ); - $sth->finish; return 1; @@ -180,7 +178,6 @@ sub DeleteCollection { $sth = $dbh->prepare("DELETE FROM collections WHERE colId = ?"); $sth->execute( $colId ) or return ( 0, 4, $sth->errstr() ); - $sth->finish; return 1; } @@ -211,8 +208,6 @@ sub GetCollections { push( @results , $row ); } - $sth->finish; - return \@results; } @@ -259,8 +254,6 @@ sub GetItemsInCollection { push( @results , $row ); } - $sth->finish; - return \@results; } @@ -288,8 +281,6 @@ sub GetCollection { my $row = $sth->fetchrow_hashref; - $sth->finish; - return ( $$row{'colId'}, $$row{'colTitle'}, @@ -338,7 +329,6 @@ sub AddItemToCollection { $sth = $dbh->prepare("INSERT INTO collections_tracking ( ctId, colId, itemnumber ) VALUES ( NULL, ?, ? )"); $sth->execute( $colId, $itemnumber ) or return ( 0, 3, $sth->errstr() ); - $sth->finish; return 1; @@ -379,7 +369,6 @@ sub RemoveItemFromCollection { $sth = $dbh->prepare("DELETE FROM collections_tracking WHERE itemnumber = ?"); $sth->execute( $itemnumber ) or return ( 0, 3, $sth->errstr() ); - $sth->finish; return 1; } @@ -420,7 +409,6 @@ sub TransferCollection { colBranchcode = ? WHERE colId = ?"); $sth->execute( $colBranchcode, $colId ) or return ( 0, 4, $sth->errstr() ); - $sth->finish; $sth = $dbh->prepare("SELECT barcode FROM items, collections_tracking WHERE items.itemnumber = collections_tracking.itemnumber @@ -430,9 +418,7 @@ sub TransferCollection { while ( my $item = $sth->fetchrow_hashref ) { my ( $dotransfer, $messages, $iteminformation ) = transferbook( $colBranchcode, $item->{'barcode'}, my $ignore_reserves = 1); } - - return 1; } @@ -461,8 +447,6 @@ sub GetCollectionItemBranches { my $row = $sth->fetchrow_hashref; - $sth->finish; - return ( $$row{'holdingbranch'}, $$row{'colBranchcode'}, @@ -505,8 +489,6 @@ sub isItemInAnyCollection { my $row = $sth->fetchrow_hashref; $itemnumber = $row->{itemnumber}; - $sth->finish; - if ( $itemnumber ) { return 1; } else { diff --git a/t/db_dependent/RotatingCollections.t b/t/db_dependent/RotatingCollections.t index f9c1e03..1dd2e51 100644 --- a/t/db_dependent/RotatingCollections.t +++ b/t/db_dependent/RotatingCollections.t @@ -36,13 +36,14 @@ $dbh->{RaiseError} = 1; $dbh->{AutoCommit} = 0; #Start Tests +$dbh->do(q|DELETE FROM issues|); +$dbh->do(q|DELETE FROM borrowers |); +$dbh->do(q|DELETE FROM items |); $dbh->do(q|DELETE FROM collections_tracking |); $dbh->do(q|DELETE FROM collections |); $dbh->do(q|DELETE FROM branches |); $dbh->do(q|DELETE FROM categories|); $dbh->do(q|DELETE FROM branchcategories|); -$dbh->do(q|DELETE FROM borrowers |); -$dbh->do(q|DELETE FROM items |); #Test CreateCollection -- 1.7.9.5