PostgreSQL refactor: handle all data returned by native functions in DB_pgsql::simpleQuery()#46
Merged
schengawegga merged 3 commits intopear:trunkfrom Jun 27, 2025
Conversation
schengawegga
requested changes
Jun 25, 2025
| // this query has returned data | ||
| $this->row[$this->_resultId($result)] = 0; // reset the row counter. | ||
| $numrows = $this->numRows($result); | ||
| if (is_object($numrows)) { |
Collaborator
There was a problem hiding this comment.
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() only returns int values, so the null result comparison never achieved the proper intent.
schengawegga
approved these changes
Jun 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This refactor was inspired by the need to support a native PostgreSQL feature, that is handling data returned by DML queries such as INSERT or UPDATE.
In practical terms, PostgreSQL supports queries like "INSERT INTO ... VALUES ... RETURNING..." that can be used to easily retrieve the last insertion id, although the feature is far more extensive, as per docs: https://www.postgresql.org/docs/current/dml-returning.html
This refactor did away with the strong differentiation between the "read" and "write" code paths, while only relying on the response received from the PostgreSQL backend. This also allows for better error handling regarding errors returned during the actual query execution.