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
2 changes: 1 addition & 1 deletion src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2947,7 +2947,7 @@ BaseObjectPtr<StatementSync> SQLTagStore::PrepareStatement(
session->database_->connection_, sql.data(), sql.size(), &s, 0);

if (r != SQLITE_OK) {
THROW_ERR_SQLITE_ERROR(isolate, "Failed to prepare statement");
THROW_ERR_SQLITE_ERROR(isolate, session->database_.get());
sqlite3_finalize(s);
return BaseObjectPtr<StatementSync>();
}
Expand Down
22 changes: 22 additions & 0 deletions test/parallel/test-sqlite-template-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,25 @@ test('TagStore capacity, size, and clear', () => {
test('sql.db returns the associated DatabaseSync instance', () => {
assert.strictEqual(sql.db, db);
});

test('sql error messages are descriptive', () => {
assert.strictEqual(sql.run`INSERT INTO foo (text) VALUES (${'test'})`.changes, 1);

// Test with non-existent column
assert.throws(() => {
const result = sql.get`SELECT nonexistent_column FROM foo`;
assert.fail(`Expected error, got: ${JSON.stringify(result)}`);
}, {
code: 'ERR_SQLITE_ERROR',
message: /no such column/i,
});

// Test with non-existent table
assert.throws(() => {
const result = sql.get`SELECT * FROM nonexistent_table`;
assert.fail(`Expected error, got: ${JSON.stringify(result)}`);
}, {
code: 'ERR_SQLITE_ERROR',
message: /no such table/i,
});
});
Loading