From 55883caf3f08c87ef2a5aa64c920e27eb7d86803 Mon Sep 17 00:00:00 2001 From: Mark Tompsett Date: Sun, 4 Oct 2015 03:13:26 -0400 Subject: [PATCH] [SIGNED-OFF] 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. Signed-off-by: Bernardo Gonzalez Kriegel No regressions detected, no errors --- C4/Koha.pm | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/C4/Koha.pm b/C4/Koha.pm index 052147e..115152e 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -1342,9 +1342,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 }; } -- 1.9.1