Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/node_sqlite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2865,12 +2865,16 @@ MaybeLocal<Value> StatementExecutionHelper::All(Environment* env,
Isolate* isolate = env->isolate();
EscapableHandleScope scope(isolate);
int r;
int num_cols = sqlite3_column_count(stmt);
int num_cols = 0;
LocalVector<Value> rows(isolate);
LocalVector<Value> row_values(isolate);
LocalVector<Name> row_keys(isolate);

while ((r = sqlite3_step(stmt)) == SQLITE_ROW) {
if (num_cols == 0) {
num_cols = sqlite3_column_count(stmt);
}

if (ExtractRowValues(env, stmt, num_cols, use_big_ints, &row_values)
.IsNothing()) {
return MaybeLocal<Value>();
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-sqlite-statement-sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,33 @@ suite('StatementSync.prototype.all()', () => {
{ __proto__: null, key: 'key2', val: 'val2' },
]);
});

test('reflects an added column on first use after the schema changes', (t) => {
const db = new DatabaseSync(nextDb());
Comment thread
araujogui marked this conversation as resolved.
Outdated
t.after(() => { db.close(); });
db.exec('CREATE TABLE storage(key TEXT, val TEXT)');
db.prepare('INSERT INTO storage (key, val) VALUES (?, ?)').run('key1', 'val1');

const stmt = db.prepare('SELECT * FROM storage ORDER BY key');
db.exec("ALTER TABLE storage ADD COLUMN extra TEXT DEFAULT 'def'");
t.assert.deepStrictEqual(stmt.all(), [
{ __proto__: null, key: 'key1', val: 'val1', extra: 'def' },
]);
});

test('reflects a dropped column on first use after the schema changes', (t) => {
const db = new DatabaseSync(nextDb());
t.after(() => { db.close(); });
db.exec('CREATE TABLE storage(key TEXT, val TEXT, extra TEXT)');
db.prepare('INSERT INTO storage (key, val, extra) VALUES (?, ?, ?)')
.run('key1', 'val1', 'x');

const stmt = db.prepare('SELECT * FROM storage ORDER BY key');
db.exec('ALTER TABLE storage DROP COLUMN extra');
t.assert.deepStrictEqual(stmt.all(), [
{ __proto__: null, key: 'key1', val: 'val1' },
]);
});
});

suite('StatementSync.prototype.iterate()', () => {
Expand Down
Loading