r14892 - gnucash/trunk - Add a new QOF_TYPE_NUMSTRING to add numeric sorts. (#150799).

Derek Atkins warlord at cvs.gnucash.org
Mon Sep 25 20:36:33 EDT 2006


Author: warlord
Date: 2006-09-25 20:36:30 -0400 (Mon, 25 Sep 2006)
New Revision: 14892
Trac: http://svn.gnucash.org/trac/changeset/14892

Modified:
   gnucash/trunk/
   gnucash/trunk/ChangeLog
   gnucash/trunk/lib/libqof/qof/qofbookmerge.c
   gnucash/trunk/lib/libqof/qof/qofclass.c
   gnucash/trunk/lib/libqof/qof/qofclass.h
   gnucash/trunk/lib/libqof/qof/qofquery-deserial.c
   gnucash/trunk/lib/libqof/qof/qofquery-serialize.c
   gnucash/trunk/lib/libqof/qof/qofquery.c
   gnucash/trunk/lib/libqof/qof/qofquerycore.c
   gnucash/trunk/lib/libqof/qof/qofquerycore.h
   gnucash/trunk/lib/libqof/qof/qofsession.c
   gnucash/trunk/lib/libqof/qof/qofsql.c
   gnucash/trunk/lib/libqof/qof/qofutil.c
   gnucash/trunk/src/backend/postgres/gncquery.c
   gnucash/trunk/src/engine/Query.c
   gnucash/trunk/src/engine/Query.h
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/engine-helpers.c
   gnucash/trunk/src/gnome-search/search-core-type.c
   gnucash/trunk/src/gnome-search/search-string.c
   gnucash/trunk/src/gnome-search/search-string.h
Log:
	  Add a new QOF_TYPE_NUMSTRING to add numeric sorts.  (#150799).
	  This new type is like QOF_TYPE_STRING but it sorts numerically
	  (first) and then sorts alphanumerically (by the tail of the
	  number).  Added the QOF Type, the gnome-search support, and
	  modified TRANS_NUM to use the new type.




Property changes on: gnucash/trunk
___________________________________________________________________
Name: svk:merge
   - d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk:13344
   + d2ab10a8-8a95-4986-baff-8d511d9f15b2:/local/gnucash/trunk:13351

Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/ChangeLog	2006-09-26 00:36:30 UTC (rev 14892)
@@ -1,3 +1,12 @@
+2006-09-25  Derek Atkins  <derek at ihtfp.com>
+
+	[ Lots of files ]:
+	  Add a new QOF_TYPE_NUMSTRING to add numeric sorts.  (#150799).
+	  This new type is like QOF_TYPE_STRING but it sorts numerically
+	  (first) and then sorts alphanumerically (by the tail of the
+	  number).  Added the QOF Type, the gnome-search support, and
+	  modified TRANS_NUM to use the new type.
+
 2006-09-23  Derek Atkins  <derek at ihtfp.com>
 
 	* src/ledger-core/split-register*.c:

Modified: gnucash/trunk/lib/libqof/qof/qofbookmerge.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofbookmerge.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofbookmerge.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -126,7 +126,8 @@
 		mergeParamName = qtparam->param_name;
 		g_return_val_if_fail(mergeParamName != NULL, -1);
 		mergeType = qtparam->param_type;
-		if(safe_strcmp(mergeType, QOF_TYPE_STRING) == 0)  { 
+		if(safe_strcmp(mergeType, QOF_TYPE_STRING) == 0 ||
+		   safe_strcmp(mergeType, QOF_TYPE_NUMSTRING) == 0)  { 
 			stringImport = qtparam->param_getfcn(mergeEnt,qtparam);
 			stringTarget = qtparam->param_getfcn(targetEnt,qtparam);
 			/* very strict string matches may need to be relaxed. */
@@ -643,7 +644,8 @@
 		g_return_if_fail(rule->mergeParam->data);
 		cm_param = rule->mergeParam->data;
 		rule->mergeType = cm_param->param_type;
-		if(safe_strcmp(rule->mergeType, QOF_TYPE_STRING) == 0)  { 
+		if(safe_strcmp(rule->mergeType, QOF_TYPE_STRING) == 0 ||
+		   safe_strcmp(rule->mergeType, QOF_TYPE_NUMSTRING) == 0)  { 
 			cm_string = cm_param->param_getfcn(rule->importEnt, cm_param);
 			string_setter = (void(*)(QofEntity*, const gchar*))cm_param->param_setfcn;
 			if(string_setter != NULL) { string_setter(rule->targetEnt, cm_string); }
@@ -836,7 +838,8 @@
 
 	param_string = NULL;
 	paramType = qtparam->param_type;
-	if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0)  { 
+	if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0 ||
+	   safe_strcmp(paramType, QOF_TYPE_NUMSTRING) == 0)  { 
 			param_string = g_strdup(qtparam->param_getfcn(qtEnt,qtparam));
 			if(param_string == NULL) { param_string = ""; }
 			return param_string;

Modified: gnucash/trunk/lib/libqof/qof/qofclass.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofclass.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofclass.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -274,6 +274,7 @@
 	b = (struct param_ref_list*)user_data;
 	if((param->param_getfcn == NULL)||(param->param_setfcn == NULL)) { return; }
 	if(0 == safe_strcmp(param->param_type, QOF_TYPE_STRING)) { return; }
+	if(0 == safe_strcmp(param->param_type, QOF_TYPE_NUMSTRING)) { return; }
 	if(0 == safe_strcmp(param->param_type, QOF_TYPE_NUMERIC)) { return; }
 	if(0 == safe_strcmp(param->param_type, QOF_TYPE_DATE)) { return; }
 	if(0 == safe_strcmp(param->param_type, QOF_TYPE_CHAR)) { return; }

Modified: gnucash/trunk/lib/libqof/qof/qofclass.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofclass.h	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofclass.h	2006-09-26 00:36:30 UTC (rev 14892)
@@ -83,6 +83,8 @@
  */
 
 #define QOF_TYPE_STRING    "string"
+#define QOF_TYPE_NUMSTRING "numstring" /**< a string that sorts in numeric
+					  order instead of typological order */
 #define QOF_TYPE_DATE      "date"
 #define QOF_TYPE_NUMERIC   "numeric"
 #define QOF_TYPE_DEBCRED   "debcred"

Modified: gnucash/trunk/lib/libqof/qof/qofquery-deserial.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofquery-deserial.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofquery-deserial.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -694,6 +694,7 @@
 		{ "aflt", QOF_TYPE_DOUBLE, NULL, NULL},
 		{ "abool", QOF_TYPE_BOOLEAN, NULL, NULL},
 		{ "astr", QOF_TYPE_STRING, NULL, NULL},
+		{ "nstr", QOF_TYPE_NUMSTRING, NULL, NULL},
 		{ "adate", QOF_TYPE_DATE, NULL, NULL},
 		{ "anum", QOF_TYPE_NUMERIC, NULL, NULL},
 		{ "achar", QOF_TYPE_CHAR, NULL, NULL},

Modified: gnucash/trunk/lib/libqof/qof/qofquery-serialize.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofquery-serialize.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofquery-serialize.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -240,7 +240,8 @@
 		}
 		return topnode;
 	}
-	if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING))
+	if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING) ||
+	    !safe_strcmp (pd->type_name, QOF_TYPE_NUMSTRING))
 	{
 		topnode = xmlNewNode (NULL, "qofquery:pred-string");
 		PUT_HOW ("qofquery:compare", pd->how, LT, LTE, EQUAL, GT, GTE, NEQ);
@@ -555,6 +556,7 @@
 		{ "aint",   QOF_TYPE_INT32, NULL, NULL},
 		{ "aint64", QOF_TYPE_INT64, NULL, NULL},
 		{ "astr",   QOF_TYPE_STRING, NULL, NULL},
+		{ "nstr",   QOF_TYPE_NUMSTRING, NULL, NULL},
 		{ NULL },
 	};
 

Modified: gnucash/trunk/lib/libqof/qof/qofquery.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofquery.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofquery.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -1693,7 +1693,8 @@
     }
     return;
   }
-  if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING))
+  if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING) ||
+      !safe_strcmp (pd->type_name, QOF_TYPE_NUMSTRING))
   {
     query_string_t pdata = (query_string_t) pd;
     g_string_append_printf (gs, " Match type %s",

Modified: gnucash/trunk/lib/libqof/qof/qofquerycore.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofquerycore.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofquerycore.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -24,6 +24,7 @@
 #include "config.h"
 
 #include <glib.h>
+#include <stdlib.h>
 
 #include "qof.h"
 #include "qofquerycore-p.h"
@@ -54,6 +55,7 @@
 /* Core Type Predicate helpers */
 typedef const char * (*query_string_getter) (gpointer, QofParam *);
 static const char * query_string_type = QOF_TYPE_STRING;
+static const char * query_numstring_type = QOF_TYPE_NUMSTRING;
 
 typedef Timespec (*query_date_getter) (gpointer, QofParam *);
 static const char * query_date_type = QOF_TYPE_DATE;
@@ -124,19 +126,17 @@
 /* *******************************************************************/
 /* TYPE-HANDLING FUNCTIONS */
 
-/* QOF_TYPE_STRING */
+/* QOF_TYPE_STRING and QOF_TYPE_NUMSTRING / common functions */
 
 static int
-string_match_predicate (gpointer object,
-                        QofParam *getter,
-                        QofQueryPredData *pd)
+string_match_predicate_common (gpointer object,
+			       QofParam *getter,
+			       QofQueryPredData *pd)
 {
   query_string_t pdata = (query_string_t) pd;
   const char *s;
   int ret = 0;
 
-  VERIFY_PREDICATE (query_string_type);
-
   s = ((query_string_getter)getter->param_getfcn) (object, getter);
 
   if (!s) s = "";
@@ -166,29 +166,11 @@
   }
 }
 
-static int
-string_compare_func (gpointer a, gpointer b, gint options,
-                     QofParam *getter)
-{
-  const char *s1, *s2;
-  g_return_val_if_fail (a && b && getter &&getter->param_getfcn, COMPARE_ERROR);
-
-  s1 = ((query_string_getter)getter->param_getfcn) (a, getter);
-  s2 = ((query_string_getter)getter->param_getfcn) (b, getter);
-
-  if (options == QOF_STRING_MATCH_CASEINSENSITIVE)
-    return safe_strcasecmp (s1, s2);
-
-  return safe_strcmp (s1, s2);
-}
-
 static void
-string_free_pdata (QofQueryPredData *pd)
+string_free_pdata_common (QofQueryPredData *pd)
 {
   query_string_t pdata = (query_string_t) pd;
 
-  VERIFY_PDATA (query_string_type);
-
   if (pdata->is_regex)
     regfree (&pdata->compiled);
   else
@@ -198,33 +180,11 @@
 }
 
 static QofQueryPredData *
-string_copy_predicate (QofQueryPredData *pd)
+qof_query_string_predicate_common (QofQueryCompare how,
+				   const char *str, QofStringMatch options,
+				   gboolean is_regex,
+				   const char* type)
 {
-  query_string_t pdata = (query_string_t) pd;
-
-  VERIFY_PDATA_R (query_string_type);
-
-  return qof_query_string_predicate (pd->how, pdata->matchstring,
-                                     pdata->options,
-                                     pdata->is_regex);
-}
-
-static gboolean
-string_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2)
-{
-  query_string_t pd1 = (query_string_t) p1;
-  query_string_t pd2 = (query_string_t) p2;
-
-  if (pd1->options != pd2->options) return FALSE;
-  if (pd1->is_regex != pd2->is_regex) return FALSE;
-  return (safe_strcmp (pd1->matchstring, pd2->matchstring) == 0);
-}
-
-QofQueryPredData *
-qof_query_string_predicate (QofQueryCompare how,
-                            const char *str, QofStringMatch options,
-                            gboolean is_regex)
-{
   query_string_t pdata;
 
   g_return_val_if_fail (str, NULL);
@@ -232,7 +192,7 @@
   g_return_val_if_fail (how == QOF_COMPARE_EQUAL || how == QOF_COMPARE_NEQ, NULL);
 
   pdata = g_new0 (query_string_def, 1);
-  pdata->pd.type_name = query_string_type;
+  pdata->pd.type_name = type;
   pdata->pd.how = how;
   pdata->options = options;
   pdata->matchstring = g_strdup (str);
@@ -249,6 +209,17 @@
   return ((QofQueryPredData*)pdata);
 }
 
+static gboolean
+string_predicate_equal (QofQueryPredData *p1, QofQueryPredData *p2)
+{
+  query_string_t pd1 = (query_string_t) p1;
+  query_string_t pd2 = (query_string_t) p2;
+
+  if (pd1->options != pd2->options) return FALSE;
+  if (pd1->is_regex != pd2->is_regex) return FALSE;
+  return (safe_strcmp (pd1->matchstring, pd2->matchstring) == 0);
+}
+
 static char *
 string_to_string (gpointer object, QofParam *getter)
 {
@@ -259,6 +230,132 @@
   return NULL;
 }
 
+/* QOF_QUERY_STRING */
+
+static int
+string_match_predicate (gpointer object,
+                        QofParam *getter,
+                        QofQueryPredData *pd)
+{
+  VERIFY_PREDICATE (query_string_type);
+  return string_match_predicate_common(object, getter, pd);
+}
+
+static int
+string_compare_func (gpointer a, gpointer b, gint options,
+                     QofParam *getter)
+{
+  const char *s1, *s2;
+  g_return_val_if_fail (a && b && getter &&getter->param_getfcn, COMPARE_ERROR);
+
+  s1 = ((query_string_getter)getter->param_getfcn) (a, getter);
+  s2 = ((query_string_getter)getter->param_getfcn) (b, getter);
+
+  if (options == QOF_STRING_MATCH_CASEINSENSITIVE)
+    return safe_strcasecmp (s1, s2);
+
+  return safe_strcmp (s1, s2);
+}
+
+static void
+string_free_pdata (QofQueryPredData *pd)
+{
+  VERIFY_PDATA (query_string_type);
+  return string_free_pdata_common(pd);
+}
+
+static QofQueryPredData *
+string_copy_predicate (QofQueryPredData *pd)
+{
+  query_string_t pdata = (query_string_t) pd;
+
+  VERIFY_PDATA_R (query_string_type);
+
+  return qof_query_string_predicate_common (pd->how, pdata->matchstring,
+					    pdata->options,
+					    pdata->is_regex,
+					    query_string_type);
+}
+
+QofQueryPredData *
+qof_query_string_predicate (QofQueryCompare how,
+                            const char *str, QofStringMatch options,
+                            gboolean is_regex)
+{
+  return qof_query_string_predicate_common(how, str, options, is_regex,
+					   query_string_type);
+}
+
+/* QOF_QUERY_NUMSTRING */
+
+static int
+numstring_match_predicate (gpointer object,
+                        QofParam *getter,
+                        QofQueryPredData *pd)
+{
+  VERIFY_PREDICATE (query_numstring_type);
+  return string_match_predicate_common(object, getter, pd);
+}
+
+static int
+numstring_compare_func (gpointer a, gpointer b, gint options,
+                     QofParam *getter)
+{
+  const char *s1, *s2;
+  char *sr1, *sr2;
+  long i1, i2;
+  g_return_val_if_fail (a && b && getter &&getter->param_getfcn, COMPARE_ERROR);
+
+  s1 = ((query_string_getter)getter->param_getfcn) (a, getter);
+  s2 = ((query_string_getter)getter->param_getfcn) (b, getter);
+
+  // Deal with NULL strings
+  if (s1 == s2)  return 0;
+  if (!s1 && s2) return -1;
+  if (s1 && !s2) return 1;
+
+  // Convert to integers and test
+  i1 = strtol(s1, &sr1, 0);
+  i2 = strtol(s2, &sr2, 0);
+  if (i1 < i2)  return -1;
+  if (i1 > i2)  return 1;
+
+  // If the integers match, then test the REST of the string as text.
+  if (options == QOF_STRING_MATCH_CASEINSENSITIVE)
+    return safe_strcasecmp (sr1, sr2);
+
+  return safe_strcmp (sr1, sr2);
+}
+
+static void
+numstring_free_pdata (QofQueryPredData *pd)
+{
+  VERIFY_PDATA (query_numstring_type);
+  return string_free_pdata_common(pd);
+}
+
+static QofQueryPredData *
+numstring_copy_predicate (QofQueryPredData *pd)
+{
+  query_string_t pdata = (query_string_t) pd;
+
+  VERIFY_PDATA_R (query_numstring_type);
+
+  return qof_query_string_predicate_common (pd->how, pdata->matchstring,
+					    pdata->options,
+					    pdata->is_regex,
+					    query_numstring_type);
+}
+
+QofQueryPredData *
+qof_query_numstring_predicate (QofQueryCompare how,
+                            const char *str, QofStringMatch options,
+                            gboolean is_regex)
+{
+  return qof_query_string_predicate_common(how, str, options, is_regex,
+					   query_numstring_type);
+}
+
 /* QOF_TYPE_DATE =================================================== */
 
 static int
@@ -1661,6 +1758,9 @@
     { QOF_TYPE_STRING, string_match_predicate, string_compare_func,
       string_copy_predicate, string_free_pdata, string_to_string,
       string_predicate_equal },
+    { QOF_TYPE_NUMSTRING, numstring_match_predicate, numstring_compare_func,
+      numstring_copy_predicate, numstring_free_pdata, string_to_string,
+      string_predicate_equal },
     { QOF_TYPE_DATE, date_match_predicate, date_compare_func,
       date_copy_predicate, date_free_pdata, date_to_string,
       date_predicate_equal },

Modified: gnucash/trunk/lib/libqof/qof/qofquerycore.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofquerycore.h	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofquerycore.h	2006-09-26 00:36:30 UTC (rev 14892)
@@ -141,6 +141,11 @@
                                               QofStringMatch options,
                                               gboolean is_regex);
 
+QofQueryPredData *qof_query_numstring_predicate (QofQueryCompare how,
+						 const gchar *str,
+						 QofStringMatch options,
+						 gboolean is_regex);
+
 QofQueryPredData *qof_query_date_predicate (QofQueryCompare how,
                                             QofDateMatch options,
                                             Timespec date);

Modified: gnucash/trunk/lib/libqof/qof/qofsession.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofsession.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofsession.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -426,7 +426,8 @@
 	cm_param = (QofParam*) data;
 	g_return_if_fail(cm_param != NULL);
 	context->param = cm_param;
-	if(safe_strcmp(cm_param->param_type, QOF_TYPE_STRING) == 0)  { 
+	if(safe_strcmp(cm_param->param_type, QOF_TYPE_STRING) == 0 ||
+	   safe_strcmp(cm_param->param_type, QOF_TYPE_NUMSTRING) == 0)  { 
 		cm_string = (gchar*)cm_param->param_getfcn(importEnt, cm_param);
 		if(cm_string) {
 		string_setter = (void(*)(QofEntity*, const char*))cm_param->param_setfcn;

Modified: gnucash/trunk/lib/libqof/qof/qofsql.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofsql.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofsql.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -308,7 +308,8 @@
 		return NULL;
 	}
 
-	if (!strcmp (param_type, QOF_TYPE_STRING))
+	if (!strcmp (param_type, QOF_TYPE_STRING) ||
+	    !strcmp (param_type, QOF_TYPE_NUMSTRING))
 	{
 		pred_data = 
 		    qof_query_string_predicate (qop,        /* comparison to make */
@@ -605,7 +606,8 @@
 
 	ENTER (" param=%s param_type=%s type=%s content=%s", 
 		param->param_name, param->param_type, type, insert_string);
-	if(safe_strcmp(param->param_type, QOF_TYPE_STRING) == 0)  { 
+	if(safe_strcmp(param->param_type, QOF_TYPE_STRING) == 0 ||
+	   safe_strcmp(param->param_type, QOF_TYPE_NUMSTRING) == 0)  { 
 		string_setter = (void(*)(QofEntity*, const char*))param->param_setfcn;
 		if(string_setter != NULL) { string_setter(ent, insert_string); }
 		registered_type = TRUE;

Modified: gnucash/trunk/lib/libqof/qof/qofutil.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofutil.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/lib/libqof/qof/qofutil.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -416,7 +416,8 @@
 	param_string = NULL;
     known_type = FALSE;
 	paramType = param->param_type;
-	if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0)  { 
+	if(safe_strcmp(paramType, QOF_TYPE_STRING) == 0 ||
+	   safe_strcmp(paramType, QOF_TYPE_NUMSTRING) == 0)  { 
 			param_string = g_strdup(param->param_getfcn(ent, param));
 			if(param_string == NULL) { param_string = ""; }
             known_type = TRUE;

Modified: gnucash/trunk/src/backend/postgres/gncquery.c
===================================================================
--- gnucash/trunk/src/backend/postgres/gncquery.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/src/backend/postgres/gncquery.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -958,7 +958,8 @@
                     more_and = 0;
                 }
 
-            } else if (!safe_strcmp(pd->type_name, QOF_TYPE_STRING)) {
+            } else if (!safe_strcmp(pd->type_name, QOF_TYPE_STRING) ||
+		       !safe_strcmp(pd->type_name, QOF_TYPE_NUMSTRING)) {
                 query_string_t pdata = (query_string_t) pd;
 
                 if (!safe_strcmp(path->data, SPLIT_ACTION)) {

Modified: gnucash/trunk/src/engine/Query.c
===================================================================
--- gnucash/trunk/src/engine/Query.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/src/engine/Query.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -320,6 +320,32 @@
 }
 
 void
+xaccQueryAddNumStringMatch (Query* q, const char *matchstring,
+			    int case_sens, int use_regexp, QofQueryOp op,
+			    const char * path, ...)
+{
+  QofQueryPredData *pred_data;
+  GSList *param_list;
+  va_list ap;
+
+  if (!path || !q)
+    return;
+
+  pred_data = qof_query_numstring_predicate (QOF_COMPARE_EQUAL, (char *)matchstring,
+				       (case_sens ? QOF_STRING_MATCH_NORMAL :
+					QOF_STRING_MATCH_CASEINSENSITIVE),
+				       use_regexp);
+  if (!pred_data)
+    return;
+
+  va_start (ap, path);
+  param_list = build_param_list_internal (path, ap);
+  va_end (ap);
+
+  qof_query_add_term (q, param_list, pred_data, op);
+}
+
+void
 xaccQueryAddNumericMatch (Query *q, gnc_numeric amount, QofNumericMatch sign,
 			  QofQueryCompare how, QofQueryOp op,
 			  const char * path, ...)

Modified: gnucash/trunk/src/engine/Query.h
===================================================================
--- gnucash/trunk/src/engine/Query.h	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/src/engine/Query.h	2006-09-26 00:36:30 UTC (rev 14892)
@@ -127,11 +127,15 @@
 			      int case_sens, int use_regexp, QofQueryOp op,
 			      const char * path, ...);
 
+void xaccQueryAddNumStringMatch (Query* q, const char *matchstring,
+			      int case_sens, int use_regexp, QofQueryOp op,
+			      const char * path, ...);
+
 #define xaccQueryAddDescriptionMatch(q,m,c,r,o) \
 	xaccQueryAddStringMatch ((q), (m), (c), (r), (o), SPLIT_TRANS, \
 				TRANS_DESCRIPTION, NULL)
 #define xaccQueryAddNumberMatch(q,m,c,r,o) \
-	xaccQueryAddStringMatch ((q), (m), (c), (r), (o), SPLIT_TRANS, \
+	xaccQueryAddNumStringMatch ((q), (m), (c), (r), (o), SPLIT_TRANS, \
 				TRANS_NUM, NULL)
 #define xaccQueryAddActionMatch(q,m,c,r,o) \
 	xaccQueryAddStringMatch ((q), (m), (c), (r), (o), SPLIT_ACTION, \

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/src/engine/Transaction.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -1966,7 +1966,7 @@
 gboolean xaccTransRegister (void)
 {
   static QofParam params[] = {
-    { TRANS_NUM, QOF_TYPE_STRING, 
+    { TRANS_NUM, QOF_TYPE_NUMSTRING, 
       (QofAccessFunc)xaccTransGetNum, 
       (QofSetterFunc)qofTransSetNum },
     { TRANS_DESCRIPTION, QOF_TYPE_STRING, 

Modified: gnucash/trunk/src/engine/engine-helpers.c
===================================================================
--- gnucash/trunk/src/engine/engine-helpers.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/src/engine/engine-helpers.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -864,7 +864,8 @@
   qt_scm = scm_cons (scm_str2symbol (pd->type_name), qt_scm);
   qt_scm = scm_cons (gnc_query_compare2scm (pd->how), qt_scm);
 
-  if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING)) {
+  if (!safe_strcmp (pd->type_name, QOF_TYPE_STRING) ||
+      !safe_strcmp (pd->type_name, QOF_TYPE_NUMSTRING)) {
     query_string_t pdata = (query_string_t) pd;
 
     qt_scm = scm_cons (gnc_query_string2scm (pdata->options), qt_scm);
@@ -969,7 +970,8 @@
 
     /* Now compute the predicate */
 
-    if (!safe_strcmp (type, QOF_TYPE_STRING)) 
+    if (!safe_strcmp (type, QOF_TYPE_STRING) ||
+	!safe_strcmp (type, QOF_TYPE_NUMSTRING))
     {
       QofStringMatch options;
       gboolean is_regex;
@@ -991,8 +993,12 @@
 
       matchstring = SCM_STRING_CHARS (scm);
 
-      pd = qof_query_string_predicate (compare_how, matchstring,
-                                    options, is_regex);
+      if (!safe_strcmp (type, QOF_TYPE_STRING))
+	pd = qof_query_string_predicate (compare_how, matchstring,
+					 options, is_regex);
+      else
+	pd = qof_query_numstring_predicate (compare_how, matchstring,
+					    options, is_regex);
     } 
     else if (!safe_strcmp (type, QOF_TYPE_DATE)) 
     {

Modified: gnucash/trunk/src/gnome-search/search-core-type.c
===================================================================
--- gnucash/trunk/src/gnome-search/search-core-type.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/src/gnome-search/search-core-type.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -255,6 +255,8 @@
 {
   gnc_search_core_register_type (QUERYCORE_STRING,
 				 (GNCSearchCoreNew) gnc_search_string_new);
+  gnc_search_core_register_type (QOF_TYPE_NUMSTRING,
+				 (GNCSearchCoreNew) gnc_search_string_new_numstring);
   gnc_search_core_register_type (QUERYCORE_DATE,
 				 (GNCSearchCoreNew) gnc_search_date_new);
   gnc_search_core_register_type (QUERYCORE_INT64,

Modified: gnucash/trunk/src/gnome-search/search-string.c
===================================================================
--- gnucash/trunk/src/gnome-search/search-string.c	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/src/gnome-search/search-string.c	2006-09-26 00:36:30 UTC (rev 14892)
@@ -112,6 +112,7 @@
   o->value = NULL;
   o->how = SEARCH_STRING_CONTAINS;
   o->ign_case = TRUE;
+  o->is_numstring = FALSE;
 }
 
 static void
@@ -139,6 +140,21 @@
   return o;
 }
 
+/**
+ * gnc_search_string_new_numstring:
+ *
+ * Create a new GNCSearchString object for a NumString.
+ * 
+ * Return value: A new #GNCSearchString object.
+ **/
+GNCSearchString *
+gnc_search_string_new_numstring (void)
+{
+  GNCSearchString *o = g_object_new(GNC_TYPE_SEARCH_STRING, NULL);
+  o->is_numstring = TRUE;
+  return o;
+}
+
 void
 gnc_search_string_set_value (GNCSearchString *fi, const char *value)
 {
@@ -359,7 +375,10 @@
   if (ss->ign_case)
     options = STRING_MATCH_CASEINSENSITIVE;
 
-  return gncQueryStringPredicate (how, ss->value, options, is_regex);
+  if (ss->is_numstring)
+    return qof_query_numstring_predicate (how, ss->value, options, is_regex);
+  else
+    return gncQueryStringPredicate (how, ss->value, options, is_regex);
 }
 
 static GNCSearchCoreType *gncs_clone(GNCSearchCoreType *fe)
@@ -369,7 +388,10 @@
   g_return_val_if_fail (fse, NULL);
   g_return_val_if_fail (IS_GNCSEARCH_STRING (fse), NULL);
 
-  se = gnc_search_string_new ();
+  if (fse->is_numstring)
+    se = gnc_search_string_new_numstring ();
+  else
+    se = gnc_search_string_new ();
   gnc_search_string_set_value (se, fse->value);
   gnc_search_string_set_how (se, fse->how);
   gnc_search_string_set_case (se, fse->ign_case);

Modified: gnucash/trunk/src/gnome-search/search-string.h
===================================================================
--- gnucash/trunk/src/gnome-search/search-string.h	2006-09-25 11:58:14 UTC (rev 14891)
+++ gnucash/trunk/src/gnome-search/search-string.h	2006-09-26 00:36:30 UTC (rev 14892)
@@ -44,6 +44,9 @@
   GNCSearchString_Type	how;
   gboolean		ign_case;
   char *		value;
+
+  /* Is this is String or a NumString */
+  gboolean		is_numstring;
 };
 
 struct _GNCSearchStringClass {
@@ -56,6 +59,7 @@
 
 guint		gnc_search_string_get_type	(void);
 GNCSearchString	*gnc_search_string_new	(void);
+GNCSearchString	*gnc_search_string_new_numstring(void);
 
 /* methods */
 void	gnc_search_string_set_value(GNCSearchString *fi, const char *value);



More information about the gnucash-changes mailing list