Skip to content

sqlite: bind undefined to null - #62008

Closed
mike-git374 wants to merge 1 commit into
nodejs:mainfrom
mike-git374:sqlite-bind-undefined-to-null
Closed

sqlite: bind undefined to null#62008
mike-git374 wants to merge 1 commit into
nodejs:mainfrom
mike-git374:sqlite-bind-undefined-to-null

Conversation

@mike-git374

@mike-git374 mike-git374 commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Fixes: #61824
Refs: #61472

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/sqlite

@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 Feb 26, 2026
@mike-git374
mike-git374 force-pushed the sqlite-bind-undefined-to-null branch from 4cfb494 to f24c817 Compare April 2, 2026 05:28
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been marked as stale due to 90 days of inactivity.
It will be automatically closed in 30 days if no further activity occurs. If this is still relevant, please leave a comment or update it to keep it open.

@github-actions github-actions Bot added the stale Issues and PRs marked stale due to inactivity and scheduled for automatic closure. label Jul 28, 2026
@mike-git374

Copy link
Copy Markdown
Contributor Author

Not stale, should be merged

@github-actions github-actions Bot removed the stale Issues and PRs marked stale due to inactivity and scheduled for automatic closure. label Aug 5, 2026
@trivikr

trivikr commented Aug 5, 2026

Copy link
Copy Markdown
Member

@mike-git374 Can you please sign the commit message and push?

It's needed as per updated instructions

Your commit must contain the Signed-off-by line with your name and email address as an acknowledgement that you agree to the Developer Certificate of Origin

@TrevorBurnham TrevorBurnham left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the idea here is solid. The existing inconsistency is easy to miss:

s.run({ k: 1 });               // v binds to NULL
s.run({ k: 2, v: undefined }); // throws ERR_INVALID_ARG_TYPE

Binding undefined to NULL is the only way to make this consistent. And SQLite's own WASM oo1 API has the same behavior:

a value of undefined as an array or object property when binding an array/object… is treated the same as null

But I'd like to see a few changes before this lands:

  1. Rebase.

  2. Use the existing IsNullOrUndefined helper, matching JSValueToSQLiteResult.

  3. Update doc/api/sqlite.md. It currently describes the opposite of the new behavior in three places: the NULL row of the type-conversion table, "Attempting to write an unsupported data type to SQLite will result in an exception", and "Binding any other value throws an ERR_INVALID_ARG_TYPE error". The ...anonymousParameters / ...boundParameters type unions also need undefined added, plus a changes: entry with pr-url on each affected method.

  4. Add two more test cases to cover undefined being passed in the named-parameters slot, and undefined being passed beyond the statement's parameter count.

  5. Adjust the indentation in the new test block from 8 spaces to 6 to satisfy @stylistic/js/indent.

  6. Add the Signed-off-by line @trivikr asked about.

@trivikr

trivikr commented Aug 12, 2026

Copy link
Copy Markdown
Member

@mike-git374 Can you work on the two comments posted above?

We're prioritizing reviewing sqlite PRs in the last week.

TrevorBurnham added a commit to TrevorBurnham/node that referenced this pull request Sep 1, 2026
Omitting a named parameter binds NULL, but passing `undefined` for that
same parameter threw ERR_INVALID_ARG_TYPE. Bind `undefined` to NULL so
the two forms agree. This matches the conversion already applied to a
user-defined function's `undefined` return value, as well as SQLite's
own WASM oo1 API.

Fixes: nodejs#61824
Refs: nodejs#61472
Refs: nodejs#62008
Co-authored-by: mike-git374 <217764531+mike-git374@users.noreply.github.com>
Assisted-by: claude:opus-5
Signed-off-by: Trevor Burnham <trevorburnham@gmail.com>
@TrevorBurnham

Copy link
Copy Markdown
Contributor

I've sent over another PR to implement this same fix: #65709

@trivikr

trivikr commented Sep 1, 2026

Copy link
Copy Markdown
Member

Closing as commits were cherry-picked and posted in a new PR in #65709

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

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sqlite: inconsistent undefined bind to null

4 participants