Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions DB/pgsql.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,32 +353,32 @@ function simpleQuery($query)
/*
* Determine whether queries produce affected rows, result or nothing.
*
* This logic was introduced in version 1.1 of the file by ssb,
* though the regex has been modified slightly since then.
*
* PostgreSQL commands:
* ABORT, ALTER, BEGIN, CLOSE, CLUSTER, COMMIT, COPY,
* CREATE, DECLARE, DELETE, DROP TABLE, EXPLAIN, FETCH,
* GRANT, INSERT, LISTEN, LOAD, LOCK, MOVE, NOTIFY, RESET,
* REVOKE, ROLLBACK, SELECT, SELECT INTO, SET, SHOW,
* UNLISTEN, UPDATE, VACUUM, WITH
*/
if ($ismanip) {
$this->affected = @pg_affected_rows($result);
return DB_OK;
} elseif (preg_match('/^\s*\(*\s*(SELECT|EXPLAIN|FETCH|SHOW|WITH)\s/si',
$query))
{
$this->row[$this->_resultId($result)] = 0; // reset the row counter.

$this->affected = @pg_affected_rows($result);
$result_status = @pg_result_status($result);
if ($result_status === PGSQL_TUPLES_OK) {
// this query has returned data
$this->row[$this->_resultId($result)] = 0; // reset the row counter.
$numrows = $this->numRows($result);
if (is_object($numrows)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a problem with this if-statement.
According to the documentation, the function pg_num_rows() returns a '-1' value on error.
In the method numRows() here, it checks for a 'null' response, to identify an error.
I think this is not correct in numRows().
Can you check this, please?
I don´t have any PG instance to check this on my own.
Maybe the failure handling in this method has never worked well...... ;-)

The other changes looks good to me.

// pg_num_rows() has returned -1, so we then got an
// exception object returned from our numRows() method
return $numrows;
}
$this->_num_rows[$this->_resultId($result)] = $numrows;
$this->affected = 0;
return $result;
} elseif (in_array($result_status, [PGSQL_BAD_RESPONSE, PGSQL_NONFATAL_ERROR, PGSQL_FATAL_ERROR])) {
// unexpected response from pg_query
return $this->pgsqlRaiseError();
} else {
$this->affected = 0;
// catch all for non-error statuses
return DB_OK;
}
}
Expand Down Expand Up @@ -573,7 +573,7 @@ function numCols($result)
function numRows($result)
{
$rows = @pg_num_rows($result);
if ($rows === null) {
if ($rows == -1) {
return $this->pgsqlRaiseError();
}
return $rows;
Expand Down