From 093140d84c3096537618374cae7f868fde4acead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mika=C3=ABl=20Francoeur?= Date: Mon, 14 Jul 2025 14:15:12 -0400 Subject: [PATCH] throw on empty statement --- .../javascript/__test__/better-sqlite3.spec.mjs | 13 +------------ bindings/javascript/wrapper.js | 4 ++++ 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/bindings/javascript/__test__/better-sqlite3.spec.mjs b/bindings/javascript/__test__/better-sqlite3.spec.mjs index c88290b53..9f5aaba93 100644 --- a/bindings/javascript/__test__/better-sqlite3.spec.mjs +++ b/bindings/javascript/__test__/better-sqlite3.spec.mjs @@ -96,18 +96,7 @@ inMemoryTest.both("Statment.iterate() should correctly return an iterable object } }); -inMemoryTest.both("Empty prepared statement should throw", async (t) => { - const db = t.context.db; - t.throws( - () => { - db.prepare(""); - }, - { any: true } - ); -}); - -inMemoryTest.onlySqlitePasses("Empty prepared statement should throw the correct error", async (t) => { - // the previous test can be removed once this one passes in Turso +inMemoryTest.both("Empty prepared statement should throw the correct error", async (t) => { const db = t.context.db; t.throws( () => { diff --git a/bindings/javascript/wrapper.js b/bindings/javascript/wrapper.js index 9d513f514..57235d8e5 100644 --- a/bindings/javascript/wrapper.js +++ b/bindings/javascript/wrapper.js @@ -77,6 +77,10 @@ class Database { * @param {string} sql - The SQL statement string to prepare. */ prepare(sql) { + if (!sql) { + throw new RangeError('The supplied SQL string contains no statements'); + } + try { return new Statement(this.db.prepare(sql), this); } catch (err) {