コード例 #1
0
ファイル: gnc-vendor-sql.cpp プロジェクト: Mechtilde/gnucash
/* ================================================================= */
bool
GncSqlVendorBackend::commit (GncSqlBackend* sql_be, QofInstance* inst)
{
    GncVendor* v;
    const GncGUID* guid;
    E_DB_OPERATION op;
    gboolean is_infant;
    gboolean is_ok = TRUE;

    g_return_val_if_fail (inst != NULL, FALSE);
    g_return_val_if_fail (GNC_IS_VENDOR (inst), FALSE);
    g_return_val_if_fail (sql_be != NULL, FALSE);

    v = GNC_VENDOR (inst);

    is_infant = qof_instance_get_infant (inst);
    if (qof_instance_get_destroying (inst))
    {
        op = OP_DB_DELETE;
    }
    else if (sql_be->pristine() || is_infant)
    {
        op = OP_DB_INSERT;
    }
    else
    {
        op = OP_DB_UPDATE;
    }
    if (op != OP_DB_DELETE)
    {
        // Ensure the commodity is in the db
        is_ok = sql_be->save_commodity (gncVendorGetCurrency(v));
    }
    if (is_ok)
    {
        is_ok = sql_be->do_db_operation(op, TABLE_NAME, GNC_ID_VENDOR, v,
                                        col_table);
    }

    if (is_ok)
    {
        // Now, commit or delete any slots
        guid = qof_instance_get_guid (inst);
        if (!qof_instance_get_destroying (inst))
        {
            is_ok = gnc_sql_slots_save (sql_be, guid, is_infant, inst);
        }
        else
        {
            is_ok = gnc_sql_slots_delete (sql_be, guid);
        }
    }

    return is_ok;
}
コード例 #2
0
static void
compare_single_vendor( QofInstance* inst, gpointer user_data )
{
    CompareInfoStruct* info = (CompareInfoStruct*)user_data;
    GncVendor* vendor_1 = GNC_VENDOR(inst);
    GncVendor* vendor_2 = gncVendorLookup( info->book_2, qof_instance_get_guid(inst) );

    if (!gncVendorEqual( vendor_1, vendor_2 ))
    {
        info->result = FALSE;
    }
}
コード例 #3
0
ファイル: gnc-vendor-sql.cpp プロジェクト: Mechtilde/gnucash
static void
write_single_vendor (QofInstance* term_p, gpointer data_p)
{
    auto s = reinterpret_cast<write_objects_t*>(data_p);

    g_return_if_fail (term_p != NULL);
    g_return_if_fail (GNC_IS_VENDOR (term_p));
    g_return_if_fail (data_p != NULL);

    if (vendor_should_be_saved (GNC_VENDOR (term_p)))
    {
        s->commit (term_p);
    }
}
コード例 #4
0
ファイル: gnc-vendor-sql.cpp プロジェクト: Isendir/gnucash
static void
write_single_vendor( QofInstance *term_p, gpointer data_p )
{
    write_objects_t* s = (write_objects_t*)data_p;

    g_return_if_fail( term_p != NULL );
    g_return_if_fail( GNC_IS_VENDOR(term_p) );
    g_return_if_fail( data_p != NULL );

    if ( s->is_ok && vendor_should_be_saved( GNC_VENDOR(term_p) ) )
    {
        s->is_ok = save_vendor( s->be, term_p );
    }
}
コード例 #5
0
static void
taxtable_scrub_vendor (QofInstance * vendor_p, gpointer ht_p)
{
    GHashTable *ht = ht_p;
    GncVendor *vendor = GNC_VENDOR(vendor_p);
    GncTaxTable *table;
    gint32 count;

    table = gncVendorGetTaxTable(vendor);
    if (table)
    {
        count = GPOINTER_TO_INT(g_hash_table_lookup(ht, table));
        count++;
        g_hash_table_insert(ht, table, GINT_TO_POINTER(count));
    }
}
コード例 #6
0
static void
billterm_scrub_vendor (QofInstance * vendor_p, gpointer ht_p)
{
    GHashTable *ht = ht_p;
    GncVendor *vendor = GNC_VENDOR(vendor_p);
    GncBillTerm *term;
    gint32 count;

    term = gncVendorGetTerms(vendor);
    if (term)
    {
        count = GPOINTER_TO_INT(g_hash_table_lookup(ht, term));
        count++;
        g_hash_table_insert(ht, term, GINT_TO_POINTER(count));
        if (billterm_is_grandchild(term))
            PWARN("vendor %s has grandchild billterm %s\n",
                  guid_to_string(qof_instance_get_guid(QOF_INSTANCE(vendor))),
                  guid_to_string(qof_instance_get_guid(QOF_INSTANCE(term))));
    }
}
コード例 #7
0
static void
billterm_scrub_vendor (QofInstance* vendor_p, gpointer ht_p)
{
    GHashTable* ht = static_cast<decltype (ht)> (ht_p);
    GncVendor* vendor = GNC_VENDOR (vendor_p);
    GncBillTerm* term;
    gint32 count;

    term = gncVendorGetTerms (vendor);
    if (term)
    {
        count = GPOINTER_TO_INT (g_hash_table_lookup (ht, term));
        count++;
        g_hash_table_insert (ht, term, GINT_TO_POINTER (count));
        if (billterm_is_grandchild (term))
        {
            gchar vendstr[GUID_ENCODING_LENGTH + 1];
            gchar termstr[GUID_ENCODING_LENGTH + 1];
            guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (vendor)), vendstr);
            guid_to_string_buff (qof_instance_get_guid (QOF_INSTANCE (term)), termstr);
            PWARN ("vendor %s has grandchild billterm %s\n", vendstr, termstr);
        }
    }
}