From d340a6766f9c343c4a1cd3f657d5ade29c301e63 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 25 Sep 2019 10:44:03 -0300 Subject: [PATCH] Bug 23624: (QA follow-up) Test error cases Signed-off-by: Tomas Cohen Arazi Signed-off-by: Martin Renvoize (cherry picked from commit 6c90c6f7d9e0f04ce148b723fc3a4828f03e9079) Signed-off-by: Fridolin Somers (cherry picked from commit 34f49c908c430ff63d1419cab9f1f5dcfd7d6055) Signed-off-by: Lucas Gass --- C4/Reports/Guided.pm | 9 ++++++--- t/db_dependent/Reports/Guided.t | 13 ++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/C4/Reports/Guided.pm b/C4/Reports/Guided.pm index a9fd635a47..ea1dac0550 100644 --- a/C4/Reports/Guided.pm +++ b/C4/Reports/Guided.pm @@ -426,10 +426,13 @@ sub nb_rows { }); $sth->execute(); - my $results = $sth->fetch; - my $n = $results ? $results->[0] : 0; - return $n; + if ( $sth->errstr ) { + return 0; + } + else { + return $sth->fetch->[0]; + } } =head2 execute_query diff --git a/t/db_dependent/Reports/Guided.t b/t/db_dependent/Reports/Guided.t index efbc786e83..11b750d59e 100644 --- a/t/db_dependent/Reports/Guided.t +++ b/t/db_dependent/Reports/Guided.t @@ -360,7 +360,7 @@ $schema->storage->txn_rollback; subtest 'nb_rows() tests' => sub { - plan tests => 1; + plan tests => 3; $schema->storage->txn_begin; @@ -377,6 +377,17 @@ subtest 'nb_rows() tests' => sub { is( $nb_rows, $items_count, 'nb_rows returns the right value' ); + my $bad_query = q{ + SELECT * items xxx + }; + + warning_like + { $nb_rows = nb_rows( $bad_query ) } + qr/^DBD::mysql::st execute failed:/, + 'Bad queries raise a warning'; + + is( $nb_rows, 0, 'nb_rows returns 0 on bad queries' ); + $schema->storage->txn_rollback; }; -- 2.39.5