Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #12 from hoelzro/master
Fix bug where Pg driver would still have truthy results from fetchrow-hash
  • Loading branch information
moritz committed Jun 30, 2015
2 parents 36e66e8 + 03738e3 commit 2cfecb9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/DBDish/Pg.pm6
Expand Up @@ -269,7 +269,7 @@ class DBDish::Pg::StatementHandle does DBDish::StatementHandle {

method fetchrow() {
my @row_array;
return if $!current_row >= $!row_count;
return () if $!current_row >= $!row_count;

unless defined $!field_count {
$!field_count = PQnfields($!result);
Expand Down Expand Up @@ -317,7 +317,7 @@ class DBDish::Pg::StatementHandle does DBDish::StatementHandle {
method fetchall_hashref(Str $key) {
my %results;

return if $!current_row >= $!row_count;
return () if $!current_row >= $!row_count;

while my $row = self.fetchrow_hashref {
%results{$row{$key}} = $row;
Expand Down
23 changes: 22 additions & 1 deletion t/99-common.pl6
Expand Up @@ -5,7 +5,7 @@
#use Test; # "use" dies in a runtime EVAL
#use DBIish;
diag "Testing MiniDBD::$*mdriver";
plan 42;
plan 44;

sub magic_cmp(@a, @b) {
my $res = @a[0] eq @b[0]
Expand Down Expand Up @@ -226,6 +226,27 @@ $sth.finish;
}
}

# test that a query with no results has a falsy value
{
$sth = $dbh.prepare('SELECT * FROM nom WHERE 1 = 0');
$sth.execute;

my $row = $sth.fetchrow-hash;

ok !?$row, 'a query with no results should have a falsy value';
}

# test that a query that's exhausted its result set has a falsy value
{
$sth = $dbh.prepare('SELECT COUNT(*) FROM nom');
$sth.execute;

my $row = $sth.fetchrow-hash;
$row = $sth.fetchrow-hash;

ok !?$row, 'a query with no more results should have a falsy value';
}


# Drop the table when finished, and disconnect
ok $dbh.do("DROP TABLE nom"), "final cleanup";
Expand Down

0 comments on commit 2cfecb9

Please sign in to comment.