Пример #1
0
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);
}
Пример #2
0
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;
				 });
        }
    }
}
Пример #3
0
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);
}
Пример #4
0
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);
}