SQLite3: Have to finalize statements before closing database handle #185
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.
By submitting this pull request, I confirm the following (please check boxes, eg [X]) Failure to fill the template will close your PR:
Please submit all pull requests against the
development
branch. Failure to do so will delay or deny your requestHow familiar are you with the codebase?:
10
Imagine the following situation: A user queries some extensive data on the log term dashboard. This will cause the database to be locked for maybe up to 30 seconds. If
FTL
wants to write in this time window to the database, it is actually allowed to open and use it asPHP
is explicitly requesting only read-only access to the database. We can even prepare all queries we want to add to the database in aTRANSACTION
, however, at the end of the transaction, we won't be able to save them as the database is locked against any writes.Problem: Since the statement that was supposed to write queries to the database is not yet finalized,
sqlite3_close()
actually fails andFTL
keeps the database handle open forever (in an undefined status) as we haven't even considered thatclose
can fail due to locked (I though closing will be just fine and unlock, but that is not guaranteed to be the case!).Solution: We finalize all statements before calling
sqlite3_close()
after an error, that may or not be caused by a database lock. In addition, we now also check the return value ofsqlite3_close()
and print some error message in the future if closing the database failed (although we don't expect this to happen anymore).This template was created based on the work of
udemy-dl
.