diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 89dba430ed6b9b..a7745dd8d3a928 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -757,32 +757,23 @@ void StatementSync::All(const FunctionCallbackInfo& args) { auto reset = OnScopeLeave([&]() { sqlite3_reset(stmt->statement_); }); int num_cols = sqlite3_column_count(stmt->statement_); LocalVector rows(isolate); - LocalVector row_keys(isolate); while ((r = sqlite3_step(stmt->statement_)) == SQLITE_ROW) { - if (row_keys.size() == 0) { - row_keys.reserve(num_cols); - - for (int i = 0; i < num_cols; ++i) { - Local key; - if (!stmt->ColumnNameToName(i).ToLocal(&key)) return; - row_keys.emplace_back(key); - } - } - + LocalVector row_keys(isolate); + row_keys.reserve(num_cols); LocalVector row_values(isolate); row_values.reserve(num_cols); - for (size_t i = 0; i < row_keys.size(); ++i) { + for (int i = 0; i < num_cols; ++i) { + Local key; + if (!stmt->ColumnNameToName(i).ToLocal(&key)) return; Local val; if (!stmt->ColumnToValue(i).ToLocal(&val)) return; + row_keys.emplace_back(key); row_values.emplace_back(val); } - Local row = Object::New(isolate, - Null(isolate), - row_keys.data(), - row_values.data(), - row_keys.size()); + Local row = Object::New( + isolate, Null(isolate), row_keys.data(), row_values.data(), num_cols); rows.emplace_back(row); }