Bug 23624: (QA follow-up) Test error cases

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
(cherry picked from commit 6c90c6f7d9)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
(cherry picked from commit 34f49c908c)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
Tomas Cohen Arazi 2019-09-25 10:44:03 -03:00 committed by Lucas Gass
parent 85cc23c651
commit d340a6766f
2 changed files with 18 additions and 4 deletions

View File

@ -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

View File

@ -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;
};