static void test_null_guid(void) { GncGUID g; GncGUID *gp; g = guid_new_return(); gp = guid_new(); do_test(guid_equal(guid_null(), guid_null()), "null guids equal"); do_test(!guid_equal(&g, gp), "two guids equal"); guid_free(gp); }
static /*@ null @*/ Split* load_single_split( GncSqlBackend* be, GncSqlRow* row ) { const GncGUID* guid; GncGUID split_guid; Split* pSplit = NULL; gboolean bad_guid = FALSE; g_return_val_if_fail( be != NULL, NULL ); g_return_val_if_fail( row != NULL, NULL ); guid = gnc_sql_load_guid( be, row ); if ( guid == NULL ) return NULL; if (guid_equal(guid, guid_null())) { PWARN("Bad GUID, creating new"); bad_guid = TRUE; split_guid = guid_new_return(); } else { split_guid = *guid; pSplit = xaccSplitLookup( &split_guid, be->book ); } if ( pSplit == NULL ) { pSplit = xaccMallocSplit( be->book ); } /* If the split is dirty, don't overwrite it */ if ( !qof_instance_is_dirty( QOF_INSTANCE(pSplit) ) ) { gnc_sql_load_object( be, row, GNC_ID_SPLIT, pSplit, split_col_table ); } /*# -ifempty */ if (pSplit != xaccSplitLookup( &split_guid, be->book )) { gchar guidstr[GUID_ENCODING_LENGTH+1]; guid_to_string_buff(qof_instance_get_guid(pSplit), guidstr); PERR("A malformed split with id %s was found in the dataset.", guidstr); qof_backend_set_error( &be->be, ERR_BACKEND_DATA_CORRUPT); pSplit = NULL; } return pSplit; }
/** * Commits a split to the database * * @param be SQL backend * @param inst Split * @return TRUE if successful, FALSE if error */ static gboolean commit_split( GncSqlBackend* be, QofInstance* inst ) { gint op; gboolean is_infant; gboolean is_ok; GncGUID *guid = (GncGUID*)qof_instance_get_guid(inst); g_return_val_if_fail( inst != NULL, FALSE ); g_return_val_if_fail( be != NULL, FALSE ); is_infant = qof_instance_get_infant( inst ); if ( qof_instance_get_destroying( inst ) ) { op = OP_DB_DELETE; } else if ( be->is_pristine_db || is_infant ) { op = OP_DB_INSERT; } else { op = OP_DB_UPDATE; } if (guid_equal (guid, guid_null ())) { *guid = guid_new_return (); qof_instance_set_guid (inst, guid); } is_ok = gnc_sql_do_db_operation( be, op, SPLIT_TABLE, GNC_ID_SPLIT, inst, split_col_table ); if ( is_ok && !qof_instance_get_destroying (inst)) { is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) ); } return is_ok; }
static void save_slot( const gchar* key, KvpValue* value, gpointer data ) { slot_info_t* pSlot_info = (slot_info_t*)data; gsize curlen; g_return_if_fail( key != NULL ); g_return_if_fail( value != NULL ); g_return_if_fail( data != NULL ); // Ignore if we've already run into a failure if ( !pSlot_info->is_ok ) { return; } curlen = pSlot_info->path->len; pSlot_info->pKvpValue = value; if ( curlen != 0 ) { (void)g_string_append( pSlot_info->path, "/" ); } (void)g_string_append( pSlot_info->path, key ); pSlot_info->value_type = kvp_value_get_type( value ); switch ( pSlot_info->value_type ) { case KVP_TYPE_FRAME: { KvpFrame* pKvpFrame = kvp_value_get_frame( value ); GncGUID guid = guid_new_return(); slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid ); KvpValue *oldValue = pSlot_info->pKvpValue; pSlot_info->pKvpValue = kvp_value_new_guid( &guid ); pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table ); g_return_if_fail( pSlot_info->is_ok ); kvp_frame_for_each_slot( pKvpFrame, save_slot, pNewInfo ); kvp_value_delete( pSlot_info->pKvpValue ); pSlot_info->pKvpValue = oldValue; g_string_free( pNewInfo->path, TRUE ); g_slice_free( slot_info_t, pNewInfo ); } break; case KVP_TYPE_GLIST: { GList *cursor; GncGUID guid = guid_new_return(); slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid ); KvpValue *oldValue = pSlot_info->pKvpValue; pSlot_info->pKvpValue = kvp_value_new_guid( &guid ); pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table ); g_return_if_fail( pSlot_info->is_ok ); for (cursor = kvp_value_get_glist(value); cursor; cursor = cursor->next) { kvp_value *val = (kvp_value*)cursor->data; save_slot("", val, pNewInfo); } kvp_value_delete( pSlot_info->pKvpValue ); pSlot_info->pKvpValue = oldValue; g_string_free( pNewInfo->path, TRUE ); g_slice_free( slot_info_t, pNewInfo ); } break; default: { pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table ); } break; } (void)g_string_truncate( pSlot_info->path, curlen ); }
static void save_slot( const gchar* key, KvpValue* value, gpointer data ) { slot_info_t* pSlot_info = (slot_info_t*)data; gsize curlen; g_return_if_fail( key != NULL ); g_return_if_fail( value != NULL ); g_return_if_fail( data != NULL ); // Ignore if we've already run into a failure if ( !pSlot_info->is_ok ) { return; } curlen = pSlot_info->path->len; pSlot_info->pKvpValue = value; if ( curlen != 0 ) { (void)g_string_append( pSlot_info->path, "/" ); } (void)g_string_append( pSlot_info->path, key ); pSlot_info->value_type = value->get_type(); switch ( pSlot_info->value_type ) { case KvpValue::Type::FRAME: { auto pKvpFrame = value->get<KvpFrame*>(); auto guid = guid_new(); slot_info_t *pNewInfo = slot_info_copy( pSlot_info, guid ); KvpValue *oldValue = pSlot_info->pKvpValue; pSlot_info->pKvpValue = new KvpValue{guid}; pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table ); g_return_if_fail( pSlot_info->is_ok ); pKvpFrame->for_each_slot(save_slot, pNewInfo); delete pSlot_info->pKvpValue; pSlot_info->pKvpValue = oldValue; g_string_free( pNewInfo->path, TRUE ); g_slice_free( slot_info_t, pNewInfo ); } break; case KvpValue::Type::GLIST: { GncGUID guid = guid_new_return(); slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid ); KvpValue *oldValue = pSlot_info->pKvpValue; pSlot_info->pKvpValue = new KvpValue{&guid}; pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table ); g_return_if_fail( pSlot_info->is_ok ); for (auto cursor = value->get<GList*>(); cursor; cursor = cursor->next) { auto val = static_cast<KvpValue*>(cursor->data); save_slot("", val, pNewInfo); } delete pSlot_info->pKvpValue; pSlot_info->pKvpValue = oldValue; g_string_free( pNewInfo->path, TRUE ); g_slice_free( slot_info_t, pNewInfo ); } break; default: { pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be, OP_DB_INSERT, TABLE_NAME, TABLE_NAME, pSlot_info, col_table ); } break; } (void)g_string_truncate( pSlot_info->path, curlen ); }
GncGUID * guid_new (void) { auto ret = guid_new_return (); return guid_copy (&ret); }