Commit 4dfcf1d2e9f for nodejs

commit 4dfcf1d2e9f0afcb9e24b0bb960cc750a18cb077
Author: Trivikram Kamat <trivikr.dev@gmail.com>
Date:   Tue Oct 6 23:41:31 2026 -0700

    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>

diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc
index 8f9e2018d3b..6aae7e60cfc 100644
--- a/src/node_sqlite.cc
+++ b/src/node_sqlite.cc
@@ -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) {
diff --git a/test/parallel/test-sqlite-config.js b/test/parallel/test-sqlite-config.js
index 0988bdb14a3..16457accdb5 100644
--- a/test/parallel/test-sqlite-config.js
+++ b/test/parallel/test-sqlite-config.js
@@ -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 });