[POC] Fix #64531: SQLite3Result::fetchArray runs the query again #5204
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.
SQLite3::query()
andSQLite3Stmt::execute()
callsqlite3_step()
to determine whether to return a
SQLite3Result
orfalse
. Then theycall
sqlite3_reset()
, so thatSQLite3Result::fetchArray()
can fetchvalues from the first row. This obviously leads to issues if the SQL
query causes any side effects. We solve this by not calling
sqlite_reset()
anymore, but instead storing the last fetch resultcode on the statement object, and to use this in
::fetchArray()
whenthe first row is to be fetched.
This also allows us to prevent an SQLite3 quirk which automatically
resets a statement when
sqlite_fetch()
is called after the last fetchreturned anything else than
SQLITE_ROW
; thus fixing bug #79293.As is, this would break
SQLite3::lastErrorCode()
and::lastErrorMsg()
, so should not really go into PHP-7.3. However, these are brittle anyway (and actually not necessarily correct), since almost any SQLite3 API can change the error code, but PHP users are likely only interested in relevant API calls.