From 0a47d3444dfa749f5b9c99252cd129bc80cee54a Mon Sep 17 00:00:00 2001 From: root Date: Thu, 25 Jul 2013 14:03:32 +0200 Subject: [PATCH] Bug 10643: fix inappropriate uses of $sth->finish() in C4::ClassSource.pm This patch gets rid of finish() and replace prepare_cached by prepare. 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: Srdjan Signed-off-by: Kyle M Hall Signed-off-by: Galen Charlton (cherry picked from commit 5cba6457aa00f3f3b2038f70057df300d9c6b9c3) Signed-off-by: Tomas Cohen Arazi (cherry picked from commit cfb48010ad23e50fc93d893963164a17d4208c7b) Signed-off-by: Bernardo Gonzalez Kriegel (cherry picked from commit cfb48010ad23e50fc93d893963164a17d4208c7b) --- C4/ClassSource.pm | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/C4/ClassSource.pm b/C4/ClassSource.pm index 63f6c678be..ada9540704 100644 --- a/C4/ClassSource.pm +++ b/C4/ClassSource.pm @@ -93,12 +93,11 @@ sub GetClassSources { my %class_sources = (); my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("SELECT * FROM `class_sources`"); + my $sth = $dbh->prepare("SELECT * FROM `class_sources`"); $sth->execute(); while (my $source = $sth->fetchrow_hashref) { $class_sources{ $source->{'cn_source'} } = $source; } - $sth->finish(); return \%class_sources; @@ -116,11 +115,10 @@ sub AddClassSource { my ($cn_source, $description, $used, $class_sort_rule) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("INSERT INTO `class_sources` + my $sth = $dbh->prepare("INSERT INTO `class_sources` (`cn_source`, `description`, `used`, `class_sort_rule`) VALUES (?, ?, ?, ?)"); $sth->execute($cn_source, $description, $used, $class_sort_rule); - $sth->finish(); } @@ -136,10 +134,9 @@ sub GetClassSource { my ($cn_source) = (@_); my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("SELECT * FROM `class_sources` WHERE cn_source = ?"); + my $sth = $dbh->prepare("SELECT * FROM `class_sources` WHERE cn_source = ?"); $sth->execute($cn_source); my $row = $sth->fetchrow_hashref(); - $sth->finish(); return $row; } @@ -155,13 +152,12 @@ sub ModClassSource { my ($cn_source, $description, $used, $class_sort_rule) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("UPDATE `class_sources` + my $sth = $dbh->prepare("UPDATE `class_sources` SET `description` = ?, `used` = ?, `class_sort_rule` = ? WHERE `cn_source` = ?"); $sth->execute($description, $used, $class_sort_rule, $cn_source); - $sth->finish(); } @@ -177,9 +173,8 @@ sub DelClassSource { my ($cn_source) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("DELETE FROM `class_sources` WHERE `cn_source` = ?"); + my $sth = $dbh->prepare("DELETE FROM `class_sources` WHERE `cn_source` = ?"); $sth->execute($cn_source); - $sth->finish(); } @@ -210,12 +205,11 @@ sub GetClassSortRules { my %class_sort_rules = (); my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("SELECT * FROM `class_sort_rules`"); + my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules`"); $sth->execute(); while (my $sort_rule = $sth->fetchrow_hashref) { $class_sort_rules{ $sort_rule->{'class_sort_rule'} } = $sort_rule; } - $sth->finish(); return \%class_sort_rules; @@ -233,11 +227,10 @@ sub AddClassSortRule { my ($class_sort_rule, $description, $sort_routine) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("INSERT INTO `class_sort_rules` + my $sth = $dbh->prepare("INSERT INTO `class_sort_rules` (`class_sort_rule`, `description`, `sort_routine`) VALUES (?, ?, ?)"); $sth->execute($class_sort_rule, $description, $sort_routine); - $sth->finish(); } @@ -253,10 +246,9 @@ sub GetClassSortRule { my ($class_sort_rule) = (@_); my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?"); + my $sth = $dbh->prepare("SELECT * FROM `class_sort_rules` WHERE `class_sort_rule` = ?"); $sth->execute($class_sort_rule); my $row = $sth->fetchrow_hashref(); - $sth->finish(); return $row; } @@ -272,12 +264,11 @@ sub ModClassSortRule { my ($class_sort_rule, $description, $sort_routine) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("UPDATE `class_sort_rules` + my $sth = $dbh->prepare("UPDATE `class_sort_rules` SET `description` = ?, `sort_routine` = ? WHERE `class_sort_rule` = ?"); $sth->execute($description, $sort_routine, $class_sort_rule); - $sth->finish(); } @@ -293,9 +284,8 @@ sub DelClassSortRule { my ($class_sort_rule) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?"); + my $sth = $dbh->prepare("DELETE FROM `class_sort_rules` WHERE `class_sort_rule` = ?"); $sth->execute($class_sort_rule); - $sth->finish(); } @@ -313,13 +303,12 @@ sub GetSourcesForSortRule { my ($class_sort_rule) = @_; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare_cached("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?"); + my $sth = $dbh->prepare("SELECT cn_source FROM class_sources WHERE class_sort_rule = ?"); $sth->execute($class_sort_rule); my @sources = (); while (my ($source) = $sth->fetchrow_array()) { push @sources, $source; } - $sth->finish(); return @sources; } -- 2.39.5