sqlite: persist enableDefensive() across reopen

`enableDefensive()` updated only the live connection, so after
`close()` and `open()` the defensive flag went back to the value
passed to the constructor. Store the new value in the open
configuration so that `open()` applies it again.

Signed-off-by: Trivikram Kamat <16024985+trivikr@users.noreply.github.com>
Assisted-by: claude:opus-5.5
PR-URL: https://github.com/nodejs/node/pull/66404
Fixes: https://github.com/nodejs/node/issues/66403
Reviewed-By: Guilherme Araújo <arauujogui@gmail.com>
This commit is contained in:
Trivikram Kamat authored and GitHub committed 2026-10-07 06:41:31 +00:00
1 parent a0db728137
commit 4dfcf1d2e9
2 files changed
+21

No files matched your search

+1
View File
@@ -3550,6 +3550,7 @@ void Database::EnableDefensive(const FunctionCallbackInfo<Value>& args) {
enable,
&defensive_enabled);
CHECK_ERROR_OR_THROW(isolate, db, defensive_ret, SQLITE_OK, void());
db->open_config_.set_enable_defensive(enable);
}
void Database::LoadExtension(const FunctionCallbackInfo<Value>& args) {
+20
View File
@@ -53,6 +53,26 @@ test('defensive mode off after calling db.enableDefensive(false)', (t) => {
t.assert.strictEqual(checkDefensiveMode(db), false);
});
test('db.enableDefensive(true) persists across close() and open()', (t) => {
const db = new Database(':memory:', {
defensive: false
});
db.enableDefensive(true);
db.close();
db.open();
t.assert.strictEqual(checkDefensiveMode(db), true);
});
test('db.enableDefensive(false) persists across close() and open()', (t) => {
const db = new Database(':memory:', {
defensive: true
});
db.enableDefensive(false);
db.close();
db.open();
t.assert.strictEqual(checkDefensiveMode(db), false);
});
test('throws if options.defensive is provided but is not a boolean', (t) => {
t.assert.throws(() => {
new Database(':memory:', { defensive: 42 });