From 8f3c40e3844a2cb35fe0da5b65ac734506355969 Mon Sep 17 00:00:00 2001 From: Colin Campbell Date: Mon, 7 Sep 2009 17:31:28 +0100 Subject: [PATCH] Update some DBI interactions remove unnecessary calls to finish let DBI return an array instead of looping to create one make some SQL oneliners more succinct Signed-off-by: Galen Charlton --- C4/Bookfund.pm | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) diff --git a/C4/Bookfund.pm b/C4/Bookfund.pm index 8e9c95f25a..da82b8a777 100644 --- a/C4/Bookfund.pm +++ b/C4/Bookfund.pm @@ -166,7 +166,6 @@ sub GetBookFunds { while ( my $data = $sth->fetchrow_hashref ) { push( @results, $data ); } - $sth->finish; return @results; } @@ -185,18 +184,9 @@ keys are the fields from the currency table in the Koha database. sub GetCurrencies { my $dbh = C4::Context->dbh; - my $query = " - SELECT * - FROM currency - "; - my $sth = $dbh->prepare($query); - $sth->execute; - my @results = (); - while ( my $data = $sth->fetchrow_hashref ) { - push( @results, $data ); - } - $sth->finish; - return @results; + my $results = $dbh->selectall_arrayref( + 'SELECT * FROM currency', { Slice => {} } ); + return @{$results}; } #-------------------------------------------------------------# @@ -284,7 +274,6 @@ sub GetBookFundBreakdown { # use Data::Dumper; warn Dumper($data); } - $sth->finish; return ( $spent, $comtd ); } @@ -419,13 +408,8 @@ Sets the exchange rate for C<$currency> to be C<$newrate>. sub ModCurrencies { my ( $currency, $rate ) = @_; my $dbh = C4::Context->dbh; - my $query = " - UPDATE currency - SET rate=? - WHERE currency=? - "; - my $sth = $dbh->prepare($query); - $sth->execute( $rate, $currency ); + $dbh->do('UPDATE currency SET rate=? WHERE currency=?', {}, $rate, $currency ); + return; } #-------------------------------------------------------------# @@ -500,20 +484,9 @@ sub DelBookFund { my $bookfundid = shift; my $branchcode=shift; my $dbh = C4::Context->dbh; - my $query = " - DELETE FROM aqbookfund - WHERE bookfundid=? - AND branchcode=? - "; - my $sth=$dbh->prepare($query); - $sth->execute($bookfundid,$branchcode); - $sth->finish; - $query = " - DELETE FROM aqbudget where bookfundid=? and branchcode=? - "; - $sth=$dbh->prepare($query); - $sth->execute($bookfundid,$branchcode); - $sth->finish; + $dbh->do('DELETE FROM aqbookfund WHERE bookfundid=? AND branchcode=?', {}, $bookfundid,$branchcode); + $dbh->do('DELETE FROM aqbudget where bookfundid=? and branchcode=?', {}, $bookfundid,$branchcode); + return; } END { } # module clean-up code here (global destructor) -- 2.39.5