Skip to content

Commit a7e50a5

Browse files
deokjinkimpull[bot]
authored andcommittedOct 29, 2024
src: return undefined if no rows are returned in SQLite
For now, { key: null, value: null} is returned even though no rows are returned from database when `statement.get()` is called. So return empty value if return value of `sqlite3_step` is `SQLITE_DONE`. PR-URL: #53981 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent b5bc586 commit a7e50a5

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed
 

‎src/node_sqlite.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ void StatementSync::Get(const FunctionCallbackInfo<Value>& args) {
480480

481481
auto reset = OnScopeLeave([&]() { sqlite3_reset(stmt->statement_); });
482482
r = sqlite3_step(stmt->statement_);
483-
if (r != SQLITE_ROW && r != SQLITE_DONE) {
483+
if (r == SQLITE_DONE) return;
484+
if (r != SQLITE_ROW) {
484485
THROW_ERR_SQLITE_ERROR(env->isolate(), stmt->db_);
485486
return;
486487
}

‎test/parallel/test-sqlite.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ suite('StatementSync() constructor', () => {
219219
suite('StatementSync.prototype.get()', () => {
220220
test('executes a query and returns undefined on no results', (t) => {
221221
const db = new DatabaseSync(nextDb());
222-
const stmt = db.prepare('CREATE TABLE storage(key TEXT, val TEXT)');
222+
let stmt = db.prepare('CREATE TABLE storage(key TEXT, val TEXT)');
223+
t.assert.strictEqual(stmt.get(), undefined);
224+
stmt = db.prepare('SELECT * FROM storage');
223225
t.assert.strictEqual(stmt.get(), undefined);
224226
});
225227

0 commit comments

Comments
 (0)