Skip to content

Fix GH-22051: report errors from SQLite3Result reset and finalize - #22363

Closed
iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh-22051-sqlite3-result-reset
Closed

iliaal wants to merge 1 commit into
php:masterfrom
iliaal:fix/gh-22051-sqlite3-result-reset

Conversation

@iliaal

@iliaal iliaal commented Jun 18, 2026

Copy link
Copy Markdown
Member

SQLite3Stmt::reset() reports a failed sqlite3_reset() through php_sqlite3_error(), but SQLite3Result::reset() returned false silently and SQLite3Result::finalize() ignored the result. Both now report the same way; finalize() keeps its : true return type and reports without changing it. The other sqlite3_reset/sqlite3_finalize calls are left unchecked deliberately: resets after a successful step cannot fail, the reset-before-execute for bug #77051 returns the prior run's stale code, the error-path finalize calls would re-report an error already surfaced in the same function, and the destructor calls have no userland frame to report from.

Fixes #22051

SQLite3Stmt::reset() reports a failed sqlite3_reset() through
php_sqlite3_error(), but SQLite3Result::reset() returned false silently
and SQLite3Result::finalize() ignored the result. Both now surface the
underlying SQLite error the same way; finalize() keeps its : true return
type and reports without altering the return value.

Fixes phpGH-22051

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No strong opinions. Might need to hear from @ndossche to deal with this as I have zero experience in sqlite.

@ndossche ndossche left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ok to me. Could ask Saki for a double check as dbs are her cup of tea.

@ndossche
ndossche requested a review from SakiTakamachi June 19, 2026 07:47

@LamentXU123 LamentXU123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As far as I could tell.

@iliaal

iliaal commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

@SakiTakamachi Would appreciate your feedback on this one 🙏

@SakiTakamachi SakiTakamachi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The patch logic looks good to me!
I left a comment about the wording of the error message.

Comment thread ext/sqlite3/sqlite3.c
sqlite3result_clear_column_names_cache(result_obj);

if (sqlite3_reset(result_obj->stmt_obj->stmt) != SQLITE_OK) {
php_sqlite3_error(result_obj->db_obj, sqlite3_errcode(sqlite3_db_handle(result_obj->stmt_obj->stmt)), "Unable to reset statement: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Unable to reset statement may be slightly misleading here, since a non- SQLITE_OK return from sqlite3_reset() may reflect an error from the previous evaluation rather than a failure of the reset operation itself.

How about this?

Suggested change
php_sqlite3_error(result_obj->db_obj, sqlite3_errcode(sqlite3_db_handle(result_obj->stmt_obj->stmt)), "Unable to reset statement: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt)));
php_sqlite3_error(result_obj->db_obj, sqlite3_errcode(sqlite3_db_handle(result_obj->stmt_obj->stmt)), "Statement reset reported an error: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt)));

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Applied your wording to both sites in the merged commit.

Comment thread ext/sqlite3/sqlite3.c
} else {
sqlite3_reset(result_obj->stmt_obj->stmt);
if (sqlite3_reset(result_obj->stmt_obj->stmt) != SQLITE_OK) {
php_sqlite3_error(result_obj->db_obj, sqlite3_errcode(sqlite3_db_handle(result_obj->stmt_obj->stmt)), "Unable to reset statement: %s", sqlite3_errmsg(sqlite3_db_handle(result_obj->stmt_obj->stmt)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto

@iliaal iliaal closed this in e5934f4 Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistent/missing checks for sqlite3 APIs

4 participants