Skip to content

sqlite: fix stale column count in StatementSync.all()#64219

Open
araujogui wants to merge 2 commits into
nodejs:mainfrom
araujogui:sqlite-all-reprepare-num-cols
Open

sqlite: fix stale column count in StatementSync.all()#64219
araujogui wants to merge 2 commits into
nodejs:mainfrom
araujogui:sqlite-all-reprepare-num-cols

Conversation

@araujogui

@araujogui araujogui commented Jun 30, 2026

Copy link
Copy Markdown
Member

If the schema changes after a statement is prepared, SQLite re-prepares it on the next sqlite3_step() call. StatementSync.prototype.all() reads the column count (sqlite3_column_count()) before that step, so on the first call after a schema change the count is stale.

const stmt = db.prepare('SELECT * FROM t'); // 2 columns
db.exec('ALTER TABLE t ADD COLUMN c'); // reprepare pending
stmt.all(); // stale count = 2

const stmt2 = db.prepare('SELECT * FROM t'); // 3 columns
db.exec('ALTER TABLE t DROP COLUMN c'); // reprepare pending
stmt2.all(); // stale count = 3

StatementSync.prototype.get() is unaffected because it reads the count after stepping.

Signed-off-by: Guilherme Araújo <arauujogui@gmail.com>
Copilot AI review requested due to automatic review settings June 30, 2026 18:02
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. sqlite Issues and PRs related to the SQLite subsystem. labels Jun 30, 2026
Comment thread test/parallel/test-sqlite-statement-sync.js Outdated
@geeksilva97 geeksilva97 added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jun 30, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 1, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

nodejs-github-bot commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

@araujogui

Copy link
Copy Markdown
Member Author

@geeksilva97 are we good to land this?

@geeksilva97

Copy link
Copy Markdown
Contributor

yes

@geeksilva97 geeksilva97 added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. and removed needs-ci PRs that need a full CI run. labels Jul 6, 2026
@nodejs-github-bot nodejs-github-bot added commit-queue-failed An error occurred while landing this pull request using GitHub Actions. and removed commit-queue Add this label to land a pull request using GitHub Actions. labels Jul 6, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator
Commit Queue failed
- Loading data for nodejs/node/pull/64219
✔  Done loading data for nodejs/node/pull/64219
----------------------------------- PR info ------------------------------------
Title      sqlite: fix stale column count in StatementSync.all() (#64219)
Author     Guilherme Araújo <arauujogui@gmail.com> (@araujogui)
Branch     araujogui:sqlite-all-reprepare-num-cols -> nodejs:main
Labels     c++, author ready, commit-queue-squash, sqlite
Commits    2
 - sqlite: read column count after step in StatementSync.all()
 - sqlite: add schema-change regression tests
Committers 1
 - Guilherme Araújo <arauujogui@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/64219
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/64219
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
--------------------------------------------------------------------------------
   ℹ  This PR was created on Tue, 30 Jun 2026 18:02:50 GMT
   ✔  Approvals: 1
   ✔  - Edy Silva (@geeksilva97): https://github.com/nodejs/node/pull/64219#pullrequestreview-4603550693
   ✘  This PR needs to wait 22 more hours to land (or 0 minutes if there is one more approval)
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2026-07-01T11:39:39Z: https://ci.nodejs.org/job/node-test-pull-request/74486/
- Querying data for job/node-test-pull-request/74486/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/28821161836

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-failed An error occurred while landing this pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. sqlite Issues and PRs related to the SQLite subsystem.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants