mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
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: https://github.com/nodejs/node/pull/53981
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
@@ -480,7 +480,8 @@ void StatementSync::Get(const FunctionCallbackInfo<Value>& args) {
|
||||
|
||||
auto reset = OnScopeLeave([&]() { sqlite3_reset(stmt->statement_); });
|
||||
r = sqlite3_step(stmt->statement_);
|
||||
if (r != SQLITE_ROW && r != SQLITE_DONE) {
|
||||
if (r == SQLITE_DONE) return;
|
||||
if (r != SQLITE_ROW) {
|
||||
THROW_ERR_SQLITE_ERROR(env->isolate(), stmt->db_);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -219,7 +219,9 @@ suite('StatementSync() constructor', () => {
|
||||
suite('StatementSync.prototype.get()', () => {
|
||||
test('executes a query and returns undefined on no results', (t) => {
|
||||
const db = new DatabaseSync(nextDb());
|
||||
const stmt = db.prepare('CREATE TABLE storage(key TEXT, val TEXT)');
|
||||
let stmt = db.prepare('CREATE TABLE storage(key TEXT, val TEXT)');
|
||||
t.assert.strictEqual(stmt.get(), undefined);
|
||||
stmt = db.prepare('SELECT * FROM storage');
|
||||
t.assert.strictEqual(stmt.get(), undefined);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user