Skip to content

Commit

Permalink
Result: add hasAffectedRows() method
Browse files Browse the repository at this point in the history
  • Loading branch information
forrest79 committed Mar 14, 2024
1 parent f76de64 commit 62e081e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Db/Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,12 @@ public function getAffectedRows(): int
}


public function hasAffectedRows(): bool
{
return $this->getAffectedRows() > 0;
}


/**
* @throws Exceptions\ResultException
*/
Expand Down
19 changes: 19 additions & 0 deletions tests/Integration/FetchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,25 @@ public function testAffectedRows(): void
$result = $this->connection->query('INSERT INTO test(name) SELECT \'name\' || generate_series FROM generate_series(3, 1, -1)');

Tester\Assert::same(3, $result->getAffectedRows());
Tester\Assert::true($result->hasAffectedRows());

$result->free();
}


public function testNoAffectedRows(): void
{
$this->connection->query('
CREATE TABLE test(
id serial,
name text
);
');

$result = $this->connection->query('UPDATE test SET name = \'name\' WHERE id = 1');

Tester\Assert::same(0, $result->getAffectedRows());
Tester\Assert::false($result->hasAffectedRows());

$result->free();
}
Expand Down

0 comments on commit 62e081e

Please sign in to comment.