static void run_test (void) { int i; QofSession *sess; QofBook *book; QofInstance *ent; QofCollection *col; QofIdType type; GncGUID guid; sess = get_random_session (); book = qof_session_get_book (sess); do_test ((NULL != book), "book not created"); col = qof_book_get_collection (book, "asdf"); type = qof_collection_get_type (col); for (i = 0; i < NENT; i++) { ent = static_cast<QofInstance*>(g_object_new(QOF_TYPE_INSTANCE, NULL)); guid_replace(&guid); ent = static_cast<QofInstance*>(g_object_new(QOF_TYPE_INSTANCE, "guid", &guid, NULL)); do_test ((NULL == qof_collection_lookup_entity (col, &guid)), "duplicate guid"); ent->e_type = type; qof_collection_insert_entity (col, ent); do_test ((NULL != qof_collection_lookup_entity (col, &guid)), "guid not found"); } /* Make valgrind happy -- destroy the session. */ qof_session_destroy(sess); }
static void load_slot_for_list_item( GncSqlBackend* be, GncSqlRow* row, QofCollection* coll ) { slot_info_t slot_info = { NULL, NULL, TRUE, NULL, 0, NULL, FRAME, NULL, NULL }; const GncGUID* guid; QofInstance* inst; g_return_if_fail( be != NULL ); g_return_if_fail( row != NULL ); g_return_if_fail( coll != NULL ); guid = load_obj_guid( be, row ); g_assert( guid != NULL ); inst = qof_collection_lookup_entity( coll, guid ); slot_info.be = be; slot_info.pKvpFrame = qof_instance_get_slots( inst ); slot_info.context = NONE; gnc_sql_load_object( be, row, TABLE_NAME, &slot_info, col_table ); if ( slot_info.path != NULL ) { (void)g_string_free( slot_info.path, TRUE ); } }
void qof_instance_init_data (QofInstance *inst, QofIdType type, QofBook *book) { QofInstancePrivate *priv; QofCollection *col; QofIdType col_type; g_return_if_fail(QOF_IS_INSTANCE(inst)); priv = GET_PRIVATE(inst); g_return_if_fail(!priv->book); priv->book = book; col = qof_book_get_collection (book, type); g_return_if_fail(col != NULL); /* XXX We passed redundant info to this routine ... but I think that's * OK, it might eliminate programming errors. */ col_type = qof_collection_get_type(col); if (safe_strcmp(col_type, type)) { PERR ("attempt to insert \"%s\" into \"%s\"", type, col_type); return; } priv = GET_PRIVATE(inst); inst->e_type = CACHE_INSERT (type); do { guid_new(&priv->guid); if (NULL == qof_collection_lookup_entity (col, &priv->guid)) break; PWARN("duplicate id created, trying again"); } while (1); priv->collection = col; qof_collection_insert_entity (col, inst); }
static void qof_instance_coll_foreach(QofInstance *original, gpointer user_data) { QofInstanceCopyData *qecd; const GncGUID *g; QofBook *targetBook; QofCollection *coll; QofInstance *copy; g_return_if_fail(original != NULL); g_return_if_fail(user_data != NULL); copy = NULL; qecd = (QofInstanceCopyData*)user_data; targetBook = qof_session_get_book(qecd->new_session); g = qof_instance_get_guid(original); coll = qof_book_get_collection(targetBook, original->e_type); copy = qof_collection_lookup_entity(coll, g); if (copy) { qecd->error = TRUE; } }
static gboolean validate_type(const char *url_type, const char *location, const char *entity_type, GNCURLResult *result, GncGUID *guid, QofInstance **entity) { QofCollection *col; QofBook * book = gnc_get_current_book(); if (!string_to_guid (location + strlen(url_type), guid)) { result->error_message = g_strdup_printf (_("Bad URL: %s"), location); return FALSE; } col = qof_book_get_collection (book, entity_type); *entity = qof_collection_lookup_entity (col, guid); if (NULL == *entity) { result->error_message = g_strdup_printf (_("Entity Not Found: %s"), location); return FALSE; } return TRUE; }
static gboolean qof_instance_guid_match(QofSession *new_session, QofInstance *original) { QofInstance *copy; const GncGUID *g; QofIdTypeConst type; QofBook *targetBook; QofCollection *coll; copy = NULL; g_return_val_if_fail(original != NULL, FALSE); targetBook = qof_session_get_book(new_session); g_return_val_if_fail(targetBook != NULL, FALSE); g = qof_instance_get_guid(original); type = g_strdup(original->e_type); coll = qof_book_get_collection(targetBook, type); copy = qof_collection_lookup_entity(coll, g); if (copy) { return TRUE; } return FALSE; }
QofInstance * qof_instance_lookup_twin (const QofInstance *src, QofBook *target_book) { QofCollection *col; KvpFrame *fr; GncGUID * twin_guid; QofInstance * twin; QofInstancePrivate *bpriv; if (!src || !target_book) return NULL; ENTER (" "); bpriv = GET_PRIVATE(QOF_INSTANCE(target_book)); fr = gnc_kvp_bag_find_by_guid (src->kvp_data, "gemini", "book_guid", &bpriv->guid); twin_guid = kvp_frame_get_guid (fr, "inst_guid"); col = qof_book_get_collection (target_book, src->e_type); twin = (QofInstance *) qof_collection_lookup_entity (col, twin_guid); LEAVE (" found twin=%p", twin); return twin; }
static void load_slot_for_list_item (GncSqlBackend* sql_be, GncSqlRow& row, QofCollection* coll) { slot_info_t slot_info = { NULL, NULL, TRUE, NULL, KvpValue::Type::INVALID, NULL, FRAME, NULL, "" }; const GncGUID* guid; QofInstance* inst; g_return_if_fail (sql_be != NULL); g_return_if_fail (coll != NULL); guid = load_obj_guid (sql_be, row); g_assert (guid != NULL); inst = qof_collection_lookup_entity (coll, guid); slot_info.be = sql_be; slot_info.pKvpFrame = qof_instance_get_slots (inst); slot_info.context = NONE; gnc_sql_load_object (sql_be, row, TABLE_NAME, &slot_info, col_table); }