From 290b7be83766cf9815dfd91f2f0489e822beab1b Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Sun, 4 Oct 2015 03:13:26 -0400 Subject: [PATCH] Bug 14627: Improve SQL query A field=NULL condition does not run properly. If category is undefined, then don't include it in the query. --- C4/Koha.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 910d6bb..856c302 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -1262,9 +1262,16 @@ sub GetAuthorisedValueByCode { } my $field = $opac ? 'lib_opac' : 'lib'; + my @params; my $dbh = C4::Context->dbh; - my $sth = $dbh->prepare("SELECT $field FROM authorised_values WHERE category=? AND authorised_value =?"); - $sth->execute( $category, $authvalcode ); + my $sql = "SELECT $field FROM authorised_values WHERE authorised_value =?"; + push @params, $authvalcode; + if (defined $category) { + $sql .= ' AND category=?'; + push @params, $category; + } + my $sth = $dbh->prepare($sql); + $sth->execute( @params ); while ( my $data = $sth->fetchrow_hashref ) { return $data->{ $field }; } -- 2.1.4