Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3445,6 +3445,11 @@ bool SQLTagStore::ResetAndBindStatement(
Environment* env,
StatementSync* stmt,
const FunctionCallbackInfo<Value>& 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);
Expand Down
14 changes: 14 additions & 0 deletions test/parallel/test-sqlite-template-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading