diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index e3604d97bc5..0ca9f0d0efa 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -3445,6 +3445,11 @@ bool SQLTagStore::ResetAndBindStatement( Environment* env, StatementSync* stmt, const FunctionCallbackInfo& args) { + if (stmt->IsFinalized()) { + THROW_ERR_INVALID_STATE(env, "query contains no statement"); + return false; + } + Isolate* isolate = env->isolate(); int r = stmt->ResetStatement(); CHECK_ERROR_OR_THROW(isolate, stmt->db_.get(), r, SQLITE_OK, false); diff --git a/test/parallel/test-sqlite-template-tag.js b/test/parallel/test-sqlite-template-tag.js index 445231bef0b..3dc1901f517 100644 --- a/test/parallel/test-sqlite-template-tag.js +++ b/test/parallel/test-sqlite-template-tag.js @@ -127,6 +127,20 @@ test('rejects parameters outside of template expressions', () => { ldb.close(); }); +test('rejects queries that contain no statement', () => { + const expectedError = { + code: 'ERR_INVALID_STATE', + message: /query contains no statement/, + }; + + for (const method of ['run', 'get', 'all', 'iterate']) { + assert.throws(() => { + // eslint-disable-next-line no-unused-expressions + sql[method]`-- comment`; + }, expectedError); + } +}); + test('TagStore capacity, size, and clear', () => { assert.strictEqual(sql.capacity, 10); assert.strictEqual(sql.size, 0);