Load all objects of m_type in the database into memory.
211{
213 ParentGuidVec l_accounts_needing_parents;
214 g_return_if_fail (sql_be != NULL);
215
217
218 pBook = sql_be->book();
219
220 std::string sql("SELECT * FROM " TABLE_NAME);
221 auto stmt = sql_be->create_statement_from_sql(sql);
223 for (auto row : *result)
224 load_single_account (sql_be, row, l_accounts_needing_parents);
225
226 sql = "SELECT DISTINCT guid FROM " TABLE_NAME;
227 gnc_sql_slots_load_for_sql_subquery (sql_be, sql,
229
230
231
232
233
234
235 if (!l_accounts_needing_parents.empty())
236 {
237 auto progress_made = true;
238 std::reverse(l_accounts_needing_parents.begin(),
239 l_accounts_needing_parents.end());
240 auto end = l_accounts_needing_parents.end();
241 while (progress_made)
242 {
243 progress_made = false;
244 end = std::remove_if(l_accounts_needing_parents.begin(), end,
246 {
247 auto pParent = xaccAccountLookup (&s->guid,
248 sql_be->book());
249 if (pParent != nullptr)
250 {
251 gnc_account_append_child (pParent,
252 s->pAccount);
253 progress_made = true;
254 delete s;
255 return true;
256 }
257 return false;
258 });
259 }
260
261
262 auto root = gnc_book_get_root_account (pBook);
263 end = std::remove_if(l_accounts_needing_parents.begin(), end,
265 {
266 if (xaccAccountGetType (s->pAccount) != ACCT_TYPE_ROOT)
267 gnc_account_append_child (root, s->pAccount);
268 delete s;
269 return true;
270 });
271 }
272
274}
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
The xaccAccountLookup() subroutine will return the account associated with the given id,...