pg_get_result
bputt opened this issue · 8 comments
I'm getting the following exception:
pg_send_query(): There are results on this connection. Call pg_get_result() until it returns FALSE
File: lib/PhSqlHandle.php
Line: 216
Please can you provide more info about what your code looks like that led to this?
This indicates that you are attempting to re-use a connection (issue a new query) while there is still an active result set from a previous query, so look for things like:
- You accidentally used a
Connection
when you intended to use aPool
- You are still holding a reference to a previous result set somewhere, preventing it from being destroyed
Sure, here's the code:
$queries = [
[
'key' => 'totalRows',
'statement' => 'SELECT COUNT(*) as numRows FROM mytable WHERE x = ?',
'where' => [
'vals' => [ 'abc' ]
],
'params' => []
]
];
$pool = Postgres\pool('DSN string');
Loop::run(function() use ($queries, $pool, &$returnData) {
$promises = [];
foreach ($queries as $query) {
$promises[$query['key']] = \Amp\call(function() use ($pool, $query) {
$statement = yield $pool->prepare($query['statement'], $query['params']);
$result = yield $statement->execute($query['where']['vals']);
while (yield $result->advance()) {
$item = $result->getCurrent();
$results[] = $item;
}
return $results ?? [];
});
}
$returnData = yield $promises;
});
just to confirm, you are running this code with only a single query in the $queries
array?
No, there's always multiple.
In case this is a non-issue, it happens when I run a query that doesn't succeed: crate/crate#7373
Also, can you please define "failed" more specifically? Does query result in an error or just produce no results? If error, what?
It's conceivable (although unlikely) this could be a bug in ext/pg, can you repro this when using pecl/pq as the back end?
I'm working on duplicating the issue, we've only seen it happen when an error occurs upstream. Should be able to provide more details early next week.