I have found this patch to be useful.  It is built on the 1.8.X branch. 
It checks each new price being added to the pricedb and rejects any new
prices where the date, price, commodity and currency match any existing
price.  It prevents duplicate prices in the pricedb if you download
quotes and receive the same quote for any commodity.

Phil
Index: gnc-pricedb.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/engine/gnc-pricedb.c,v
retrieving revision 1.48.2.2
diff -u -r1.48.2.2 gnc-pricedb.c
--- gnc-pricedb.c	5 Jul 2003 01:36:11 -0000	1.48.2.2
+++ gnc-pricedb.c	14 Oct 2004 00:59:15 -0000
@@ -522,13 +522,52 @@
                        gnc_price_get_guid((GNCPrice *) b));
 }
 
+typedef struct {
+	GNCPrice* pPrice;
+	gboolean isDupl;
+} PriceListIsDuplStruct;
+
+static void
+price_list_is_duplicate( gpointer data, gpointer user_data )
+{
+	GNCPrice* pPrice = (GNCPrice*)data;
+	PriceListIsDuplStruct* pStruct = (PriceListIsDuplStruct*)user_data;
+	Timespec time_a, time_b;
+
+    time_a = timespecCanonicalDayTime( gnc_price_get_time( pPrice ) );
+    time_b = timespecCanonicalDayTime( gnc_price_get_time( pStruct->pPrice ) );
+
+	/* If the date, currency, commodity and price match, it's a duplicate */
+	if( !gnc_numeric_equal( gnc_price_get_value( pPrice ),  gnc_price_get_value( pStruct->pPrice ) ) ) return;
+	if( gnc_price_get_commodity( pPrice ) != gnc_price_get_commodity( pStruct->pPrice ) ) return;
+	if( gnc_price_get_currency( pPrice ) != gnc_price_get_currency( pStruct->pPrice ) ) return;
+
+  if( timespec_cmp( &time_a, &time_b ) != 0 ) return;
+
+	pStruct->isDupl = TRUE;
+}
+
 gboolean
 gnc_price_list_insert(GList **prices, GNCPrice *p)
 {
   GList *result_list;
+  PriceListIsDuplStruct* pStruct;
+  gboolean isDupl;
 
   if(!prices || !p) return FALSE;
   gnc_price_ref(p);
+
+  pStruct = malloc( sizeof( PriceListIsDuplStruct ) );
+  pStruct->pPrice = p;
+  pStruct->isDupl = FALSE;
+  g_list_foreach( *prices, price_list_is_duplicate, pStruct );
+  isDupl = pStruct->isDupl;
+  free( pStruct );
+
+  if( isDupl ) {
+	return TRUE;
+  }
+
   result_list = g_list_insert_sorted(*prices, p, compare_prices_by_date);
   if(!result_list) return FALSE;
   *prices = result_list;
_______________________________________________
gnucash-devel mailing list
[EMAIL PROTECTED]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to