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:
parent
3b1ed859ea
commit
7083d18461
@ -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));
|
||||
|
@ -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;
|
||||
|
@ -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 */
|
||||
|
Loading…
Reference in New Issue
Block a user