1
0
mirror of https://github.com/danog/postgres.git synced 2024-11-26 20:15:02 +01:00

Fix issue with discarded result sets; add related test

This commit is contained in:
Aaron Piotrowski 2017-11-05 18:50:52 -06:00
parent 3b1ed859ea
commit 7083d18461
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB
3 changed files with 30 additions and 0 deletions

View File

@ -16,6 +16,10 @@ class PgSqlTupleResult extends TupleResult {
parent::__construct(new Producer(static function (callable $emit) use ($handle) {
$count = \pg_num_rows($handle);
for ($i = 0; $i < $count; ++$i) {
if (!\is_resource($handle)) {
return; // Result object discarded, simply return.
}
$result = \pg_fetch_assoc($handle);
if ($result === false) {
throw new FailureException(\pg_result_error($handle));

View File

@ -228,6 +228,10 @@ class PqHandle implements Handle {
}
}
if (!$result) {
return null; // Connection closing, end result set.
}
switch ($result->status) {
case pq\Result::TUPLES_OK: // End of result set.
return null;

View File

@ -61,6 +61,28 @@ abstract class AbstractLinkTest extends TestCase {
});
}
public function testQueryWithUnconsumedTupleResult() {
Loop::run(function () {
/** @var \Amp\Postgres\TupleResult $result */
$result = yield $this->connection->query("SELECT * FROM test");
$this->assertInstanceOf(TupleResult::class, $result);
/** @var \Amp\Postgres\TupleResult $result */
$result = yield $this->connection->query("SELECT * FROM test");
$this->assertInstanceOf(TupleResult::class, $result);
$data = $this->getData();
for ($i = 0; yield $result->advance(); ++$i) {
$row = $result->getCurrent();
$this->assertSame($data[$i][0], $row['domain']);
$this->assertSame($data[$i][1], $row['tld']);
}
});
}
public function testQueryWithCommandResult() {
Loop::run(function () {
/** @var \Amp\Postgres\CommandResult $result */