GeezerVison is showing github.com — src: return `undefined` if no rows are returned in SQLite · nodejs/node@3fdcf7a
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_sqlite.cc +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -480,7 +480,8 @@ void StatementSync::Get(const FunctionCallbackInfo<Value>& args) { |
480 | 480 |
|
481 | 481 | auto reset = OnScopeLeave([&]() { sqlite3_reset(stmt->statement_); }); |
482 | 482 | r = sqlite3_step(stmt->statement_); |
483 | | - if (r != SQLITE_ROW && r != SQLITE_DONE) { |
| 483 | + if (r == SQLITE_DONE) return; |
| 484 | + if (r != SQLITE_ROW) { |
484 | 485 | THROW_ERR_SQLITE_ERROR(env->isolate(), stmt->db_); |
485 | 486 | return; |
486 | 487 | } |
|
Collapse file
Copy file name to clipboardExpand all lines: test/parallel/test-sqlite.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -219,7 +219,9 @@ suite('StatementSync() constructor', () => { |
219 | 219 | suite('StatementSync.prototype.get()', () => { |
220 | 220 | test('executes a query and returns undefined on no results', (t) => { |
221 | 221 | 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'); |
223 | 225 | t.assert.strictEqual(stmt.get(), undefined); |
224 | 226 | }); |
225 | 227 |
|
|