From 85cc23c6512a576eb872c8809096e3f14f31c841 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Fri, 20 Sep 2019 07:14:34 -0400 Subject: [PATCH] Bug 23624: (QA follow-up) Don't fetch the count unless the query was successful Signed-off-by: Liz Rea Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize (cherry picked from commit f2b27975679e64722f06b175e759801227a313fc) Signed-off-by: Fridolin Somers (cherry picked from commit 528aa88b7e7978b25331258f4f69274a3c21945f) Signed-off-by: Lucas Gass --- C4/Reports/Guided.pm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm index d3ad9a5f99..a9fd635a47 100644 --- a/C4/Reports/Guided.pm +++ b/C4/Reports/Guided.pm @@ -419,12 +419,15 @@ sub nb_rows { while ( $sql =~ m/$derived_name/ ) { $derived_name .= 'x'; } + my $sth = C4::Context->dbh->prepare(qq{ SELECT COUNT(*) FROM ( $sql ) $derived_name }); + $sth->execute(); - my $n = $sth->fetch->[0]; + my $results = $sth->fetch; + my $n = $results ? $results->[0] : 0; return $n; } -- 2.39.5