コード例 #1
0
ファイル: gnc-bill-term-sql.cpp プロジェクト: Bob-IT/gnucash
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;
				 });
        }
    }
}
コード例 #2
0
static void
load_all_billterms (GncSqlBackend* be)
{
    GncSqlStatement* stmt;
    GncSqlResult* result;

    g_return_if_fail (be != NULL);

    stmt = gnc_sql_create_select_statement (be, TABLE_NAME);
    result = gnc_sql_execute_select_statement (be, stmt);
    gnc_sql_statement_dispose (stmt);
    if (result != NULL)
    {
        GncSqlRow* row;
        GList* list = NULL;
        GList* l_billterms_needing_parents = NULL;

        row = gnc_sql_result_get_first_row (result);
        while (row != NULL)
        {
            GncBillTerm* pBillTerm = load_single_billterm (be, row,
                                                           &l_billterms_needing_parents);
            if (pBillTerm != NULL)
            {
                list = g_list_append (list, pBillTerm);
            }
            row = gnc_sql_result_get_next_row (result);
        }
        gnc_sql_result_dispose (result);

        if (list != NULL)
        {
            gnc_sql_slots_load_for_list (be, list);
            g_list_free (list);
        }

        /* 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 != NULL)
        {
            gboolean progress_made = TRUE;
            GList* elem;

            while (progress_made)
            {
                progress_made = FALSE;
                for (elem = l_billterms_needing_parents; elem != NULL;
                     elem = g_list_next (elem))
                {
                    billterm_parent_guid_struct* s = (billterm_parent_guid_struct*)elem->data;
                    bt_set_parent (s->billterm, &s->guid);
                    l_billterms_needing_parents = g_list_delete_link (l_billterms_needing_parents,
                                                                      elem);
                    progress_made = TRUE;
                }
            }
        }
    }
}