Skip to content

sqlite: StatementSync.run() loses precision for lastInsertRowid instead of throwing ERR_OUT_OF_RANGE #65177

Description

@trivikr

Version

main

Platform

macOS 26.6.0

Subsystem

sqlite

What steps will reproduce the bug?

import { DatabaseSync } from 'node:sqlite';

const db = new DatabaseSync(':memory:');
db.exec('CREATE TABLE t (id INTEGER PRIMARY KEY)');

const result = db
  .prepare('INSERT INTO t VALUES (?)')
  .run(9007199254740993n);

console.log(result);

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

It should use the documented integer-conversion behavior: throw ERR_OUT_OF_RANGE by default

It should return a BigInt when BigInt reading is enabled.

What do you see instead?

{ changes: 1, lastInsertRowid: 9007199254740992 }

sqlite3_last_insert_rowid() returns the correct 64-bit integer, but StatementSync.run() converts it directly to a JavaScript Number, silently rounding values beyond the safe-integer range.

Additional information

No response

Metadata

Metadata

Assignees

Labels

sqliteIssues and PRs related to the SQLite subsystem.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions