void GncSqlSchedXactionBackend::load_all (GncSqlBackend* sql_be) { g_return_if_fail (sql_be != NULL); std::stringstream sql; sql << "SELECT * FROM " << SCHEDXACTION_TABLE; auto stmt = sql_be->create_statement_from_sql(sql.str()); if (stmt == NULL) return; auto result = sql_be->execute_select_statement(stmt); SchedXactions* sxes; InstanceVec instances; sxes = gnc_book_get_schedxactions (sql_be->book()); for (auto row : *result) { SchedXaction* sx; sx = load_single_sx (sql_be, row); if (sx != nullptr) { gnc_sxes_add_sx (sxes, sx); instances.push_back(QOF_INSTANCE(sx)); } } if (!instances.empty()) gnc_sql_slots_load_for_instancevec (sql_be, instances); }
void GncSqlBillTermBackend::load_all (GncSqlBackend* sql_be) { g_return_if_fail (sql_be != NULL); std::stringstream sql; sql << "SELECT * FROM " << TABLE_NAME; auto stmt = sql_be->create_statement_from_sql(sql.str()); auto result = sql_be->execute_select_statement(stmt); InstanceVec instances; BillTermParentGuidVec l_billterms_needing_parents; for (auto row : *result) { auto pBillTerm = load_single_billterm (sql_be, row, l_billterms_needing_parents); if (pBillTerm != nullptr) instances.push_back(QOF_INSTANCE(pBillTerm)); } if (!instances.empty()) gnc_sql_slots_load_for_instancevec (sql_be, instances); /* While there are items on the list of billterms needing parents, try to see if the parent has now been loaded. Theory says that if items are removed from the front and added to the back if the parent is still not available, then eventually, the list will shrink to size 0. */ if (!l_billterms_needing_parents.empty()) { bool progress_made = true; std::reverse(l_billterms_needing_parents.begin(), l_billterms_needing_parents.end()); auto end = l_billterms_needing_parents.end(); while (progress_made) { progress_made = false; end = std::remove_if(l_billterms_needing_parents.begin(), end, [&](BillTermParentGuidPtr s) { auto pBook = qof_instance_get_book (QOF_INSTANCE (s->billterm)); auto parent = gncBillTermLookup (pBook, &s->guid); if (parent != nullptr) { gncBillTermSetParent (s->billterm, parent); gncBillTermSetChild (parent, s->billterm); progress_made = true; delete s; return true; } return false; }); } } }
void GncSqlBudgetBackend::load_all (GncSqlBackend* sql_be) { InstanceVec instances; g_return_if_fail (sql_be != NULL); std::stringstream sql; sql << "SELECT * FROM " << BUDGET_TABLE; auto stmt = sql_be->create_statement_from_sql(sql.str()); auto result = sql_be->execute_select_statement(stmt); for (auto row : *result) { auto b = load_single_budget (sql_be, row); if (b != nullptr) instances.push_back(QOF_INSTANCE(b)); } if (!instances.empty()) gnc_sql_slots_load_for_instancevec (sql_be, instances); }
void GncSqlOrderBackend::load_all (GncSqlBackend* be) { g_return_if_fail (be != NULL); std::stringstream sql; sql << "SELECT * FROM " << TABLE_NAME; auto stmt = be->create_statement_from_sql(sql.str()); auto result = be->execute_select_statement(stmt); InstanceVec instances; for (auto row : *result) { GncOrder* pOrder = load_single_order (be, row); if (pOrder != nullptr) instances.push_back(QOF_INSTANCE(pOrder)); } if (!instances.empty()) gnc_sql_slots_load_for_instancevec (be, instances); }
void gnc_sql_slots_load_for_instancevec (GncSqlBackend* sql_be, InstanceVec& instances) { QofCollection* coll; std::stringstream sql; g_return_if_fail (sql_be != NULL); // Ignore empty list if (instances.empty()) return; coll = qof_instance_get_collection (instances[0]); // Create the query for all slots for all items on the list sql << "SELECT * FROM " << TABLE_NAME << " WHERE " << obj_guid_col_table[0]->name(); if (instances.size() != 1) sql << " IN ("; else sql << " = "; gnc_sql_append_guids_to_sql (sql, instances); if (instances.size() > 1) sql << ")"; // Execute the query and load the slots auto stmt = sql_be->create_statement_from_sql(sql.str()); if (stmt == nullptr) { PERR ("stmt == NULL, SQL = '%s'\n", sql.str().c_str()); return; } auto result = sql_be->execute_select_statement (stmt); for (auto row : *result) load_slot_for_list_item (sql_be, row, coll); }