mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 738462 Part 1 - Add search for strings equal.
Add the ability to search for strings that are equal in queries.
This commit is contained in:
parent
5727413ad2
commit
e12c7f7514
@ -318,7 +318,7 @@ xaccQueryAddSingleAccountMatch(QofQuery *q, Account *acc, QofQueryOp op)
|
||||
void
|
||||
xaccQueryAddStringMatch (QofQuery* q, const char *matchstring,
|
||||
gboolean case_sens, gboolean use_regexp,
|
||||
QofQueryOp op,
|
||||
QofQueryCompare how, QofQueryOp op,
|
||||
const char * path, ...)
|
||||
{
|
||||
QofQueryPredData *pred_data;
|
||||
@ -328,7 +328,7 @@ xaccQueryAddStringMatch (QofQuery* q, const char *matchstring,
|
||||
if (!path || !q)
|
||||
return;
|
||||
|
||||
pred_data = qof_query_string_predicate (QOF_COMPARE_EQUAL, (char *)matchstring,
|
||||
pred_data = qof_query_string_predicate (how, (char *)matchstring,
|
||||
(case_sens ? QOF_STRING_MATCH_NORMAL :
|
||||
QOF_STRING_MATCH_CASEINSENSITIVE),
|
||||
use_regexp);
|
||||
@ -658,32 +658,40 @@ xaccQueryGetLatestDateFound(QofQuery * q)
|
||||
|
||||
void
|
||||
xaccQueryAddDescriptionMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryOp o)
|
||||
QofQueryCompare h, QofQueryOp o)
|
||||
{
|
||||
xaccQueryAddStringMatch ((q), (m), (c), (r), (o), SPLIT_TRANS,
|
||||
xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_TRANS,
|
||||
TRANS_DESCRIPTION, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
xaccQueryAddNumberMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryOp o)
|
||||
xaccQueryAddNotesMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryCompare h, QofQueryOp o)
|
||||
{
|
||||
xaccQueryAddStringMatch ((q), (m), (c), (r), (o), SPLIT_TRANS,
|
||||
xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_TRANS,
|
||||
TRANS_NOTES, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
xaccQueryAddNumberMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryCompare h, QofQueryOp o)
|
||||
{
|
||||
xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_TRANS,
|
||||
TRANS_NUM, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
xaccQueryAddActionMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryOp o)
|
||||
QofQueryCompare h, QofQueryOp o)
|
||||
{
|
||||
xaccQueryAddStringMatch ((q), (m), (c), (r), (o), SPLIT_ACTION, NULL);
|
||||
xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_ACTION, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
xaccQueryAddMemoMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryOp o)
|
||||
QofQueryCompare h, QofQueryOp o)
|
||||
{
|
||||
xaccQueryAddStringMatch ((q), (m), (c), (r), (o), SPLIT_MEMO, NULL);
|
||||
xaccQueryAddStringMatch ((q), (m), (c), (r), (h), (o), SPLIT_MEMO, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -108,20 +108,23 @@ void xaccQueryAddSingleAccountMatch(QofQuery *, Account *, QofQueryOp);
|
||||
|
||||
void xaccQueryAddStringMatch (QofQuery* q, const char *matchstring,
|
||||
gboolean case_sens, gboolean use_regexp,
|
||||
QofQueryOp op,
|
||||
QofQueryCompare how, QofQueryOp op,
|
||||
const char * path, ...);
|
||||
void
|
||||
xaccQueryAddDescriptionMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryOp o);
|
||||
QofQueryCompare how, QofQueryOp o);
|
||||
void
|
||||
xaccQueryAddNotesMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryCompare how, QofQueryOp o);
|
||||
void
|
||||
xaccQueryAddNumberMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryOp o);
|
||||
QofQueryCompare how, QofQueryOp o);
|
||||
void
|
||||
xaccQueryAddActionMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryOp o);
|
||||
QofQueryCompare how, QofQueryOp o);
|
||||
void
|
||||
xaccQueryAddMemoMatch(QofQuery *q, const char *m, gboolean c, gboolean r,
|
||||
QofQueryOp o);
|
||||
QofQueryCompare how, QofQueryOp o);
|
||||
void
|
||||
xaccQueryAddValueMatch(QofQuery *q, gnc_numeric amt, QofNumericMatch sgn,
|
||||
QofQueryCompare how, QofQueryOp op);
|
||||
|
@ -1558,28 +1558,28 @@ gnc_scm2query_term_query_v1 (SCM query_term_scm)
|
||||
if (!g_strcmp0 (pr_type, "pr-action"))
|
||||
{
|
||||
xaccQueryAddActionMatch (q, matchstring, case_sens, use_regexp,
|
||||
QOF_QUERY_OR);
|
||||
QOF_COMPARE_CONTAINS, QOF_QUERY_OR);
|
||||
ok = TRUE;
|
||||
|
||||
}
|
||||
else if (!g_strcmp0 (pr_type, "pr-desc"))
|
||||
{
|
||||
xaccQueryAddDescriptionMatch (q, matchstring, case_sens,
|
||||
use_regexp, QOF_QUERY_OR);
|
||||
use_regexp, QOF_COMPARE_CONTAINS, QOF_QUERY_OR);
|
||||
ok = TRUE;
|
||||
|
||||
}
|
||||
else if (!g_strcmp0 (pr_type, "pr-memo"))
|
||||
{
|
||||
xaccQueryAddMemoMatch (q, matchstring, case_sens, use_regexp,
|
||||
QOF_QUERY_OR);
|
||||
QOF_COMPARE_CONTAINS, QOF_QUERY_OR);
|
||||
ok = TRUE;
|
||||
|
||||
}
|
||||
else if (!g_strcmp0 (pr_type, "pr-num"))
|
||||
{
|
||||
xaccQueryAddNumberMatch (q, matchstring, case_sens, use_regexp,
|
||||
QOF_QUERY_OR);
|
||||
QOF_COMPARE_CONTAINS, QOF_QUERY_OR);
|
||||
ok = TRUE;
|
||||
|
||||
}
|
||||
|
@ -1767,6 +1767,7 @@ get_random_query(void)
|
||||
string,
|
||||
get_random_boolean (),
|
||||
get_random_boolean (),
|
||||
get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
|
||||
get_random_queryop ());
|
||||
g_free (string);
|
||||
break;
|
||||
@ -1809,6 +1810,7 @@ get_random_query(void)
|
||||
string,
|
||||
get_random_boolean (),
|
||||
get_random_boolean (),
|
||||
get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
|
||||
get_random_queryop ());
|
||||
g_free (string);
|
||||
break;
|
||||
@ -1845,6 +1847,7 @@ get_random_query(void)
|
||||
string,
|
||||
get_random_boolean (),
|
||||
get_random_boolean (),
|
||||
get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
|
||||
get_random_queryop ());
|
||||
g_free (string);
|
||||
break;
|
||||
@ -1855,6 +1858,7 @@ get_random_query(void)
|
||||
string,
|
||||
get_random_boolean (),
|
||||
get_random_boolean (),
|
||||
get_random_int_in_range (1, QOF_COMPARE_CONTAINS),
|
||||
get_random_queryop ());
|
||||
g_free (string);
|
||||
break;
|
||||
@ -2070,19 +2074,19 @@ make_trans_query (Transaction *trans, TestQueryTypes query_types)
|
||||
if (xaccTransGetDescription(trans) && *xaccTransGetDescription(trans) != '\0')
|
||||
{
|
||||
xaccQueryAddDescriptionMatch (q, xaccTransGetDescription (trans),
|
||||
TRUE, FALSE, QOF_QUERY_AND);
|
||||
TRUE, FALSE, QOF_COMPARE_CONTAINS, QOF_QUERY_AND);
|
||||
}
|
||||
|
||||
if (xaccTransGetNum(trans) && *xaccTransGetNum(trans) != '\0')
|
||||
{
|
||||
xaccQueryAddNumberMatch (q, xaccTransGetNum (trans),
|
||||
TRUE, FALSE, QOF_QUERY_AND);
|
||||
TRUE, FALSE, QOF_COMPARE_CONTAINS, QOF_QUERY_AND);
|
||||
}
|
||||
|
||||
if (xaccSplitGetAction(s) && *xaccSplitGetAction(s) != '\0')
|
||||
{
|
||||
xaccQueryAddActionMatch (q, xaccSplitGetAction (s),
|
||||
TRUE, FALSE, QOF_QUERY_AND);
|
||||
TRUE, FALSE, QOF_COMPARE_CONTAINS, QOF_QUERY_AND);
|
||||
}
|
||||
|
||||
n = xaccSplitGetValue (s);
|
||||
@ -2107,7 +2111,7 @@ make_trans_query (Transaction *trans, TestQueryTypes query_types)
|
||||
|
||||
if (xaccSplitGetMemo(s) && *xaccSplitGetMemo(s) != '\0')
|
||||
{
|
||||
xaccQueryAddMemoMatch (q, xaccSplitGetMemo (s), TRUE, FALSE, QOF_QUERY_AND);
|
||||
xaccQueryAddMemoMatch (q, xaccSplitGetMemo (s), TRUE, FALSE, QOF_COMPARE_CONTAINS, QOF_QUERY_AND);
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -262,6 +262,7 @@ make_menu (GNCSearchCoreType *fe)
|
||||
combo = GTK_COMBO_BOX(gnc_combo_box_new_search());
|
||||
|
||||
gnc_combo_box_search_add(combo, _("contains"), SEARCH_STRING_CONTAINS);
|
||||
gnc_combo_box_search_add(combo, _("equal"), SEARCH_STRING_EQUAL);
|
||||
gnc_combo_box_search_add(combo, _("matches regex"),
|
||||
SEARCH_STRING_MATCHES_REGEX);
|
||||
gnc_combo_box_search_add(combo, _("does not match regex"),
|
||||
@ -350,12 +351,18 @@ static QofQueryPredData* gncs_get_predicate (GNCSearchCoreType *fe)
|
||||
is_regex = TRUE;
|
||||
/* FALL THROUGH */
|
||||
case SEARCH_STRING_CONTAINS:
|
||||
how = QOF_COMPARE_CONTAINS;
|
||||
break;
|
||||
case SEARCH_STRING_EQUAL:
|
||||
how = QOF_COMPARE_EQUAL;
|
||||
break;
|
||||
case SEARCH_STRING_NOT_MATCHES_REGEX:
|
||||
is_regex = TRUE;
|
||||
/* FALL THROUGH */
|
||||
case SEARCH_STRING_NOT_CONTAINS:
|
||||
how = QOF_COMPARE_NCONTAINS;
|
||||
break;
|
||||
case SEARCH_STRING_NOT_EQUAL:
|
||||
how = QOF_COMPARE_NEQ;
|
||||
break;
|
||||
default:
|
||||
|
@ -37,7 +37,9 @@ typedef enum _search_string_how
|
||||
SEARCH_STRING_CONTAINS,
|
||||
SEARCH_STRING_NOT_CONTAINS,
|
||||
SEARCH_STRING_MATCHES_REGEX,
|
||||
SEARCH_STRING_NOT_MATCHES_REGEX
|
||||
SEARCH_STRING_NOT_MATCHES_REGEX,
|
||||
SEARCH_STRING_EQUAL,
|
||||
SEARCH_STRING_NOT_EQUAL
|
||||
} GNCSearchString_Type;
|
||||
|
||||
struct _GNCSearchString
|
||||
|
@ -1761,6 +1761,10 @@ qof_query_printStringForHow (QofQueryCompare how)
|
||||
return "QOF_COMPARE_GTE";
|
||||
case QOF_COMPARE_NEQ:
|
||||
return "QOF_COMPARE_NEQ";
|
||||
case QOF_COMPARE_CONTAINS:
|
||||
return "QOF_COMPARE_CONTAINS";
|
||||
case QOF_COMPARE_NCONTAINS:
|
||||
return "QOF_COMPARE_NCONTAINS";
|
||||
}
|
||||
|
||||
return "INVALID HOW";
|
||||
|
@ -147,22 +147,43 @@ string_match_predicate (gpointer object,
|
||||
regmatch_t match;
|
||||
if (!regexec (&pdata->compiled, s, 1, &match, 0))
|
||||
ret = 1;
|
||||
|
||||
}
|
||||
else if (pdata->options == QOF_STRING_MATCH_CASEINSENSITIVE)
|
||||
{
|
||||
if (qof_utf8_substr_nocase (s, pdata->matchstring))
|
||||
ret = 1;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (strstr (s, pdata->matchstring))
|
||||
ret = 1;
|
||||
if (pdata->options == QOF_STRING_MATCH_CASEINSENSITIVE)
|
||||
{
|
||||
if (pd->how == QOF_COMPARE_CONTAINS || pd->how == QOF_COMPARE_NCONTAINS)
|
||||
{
|
||||
if (qof_utf8_substr_nocase (s, pdata->matchstring)) //uses strstr
|
||||
ret = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (safe_strcasecmp (s, pdata->matchstring) == 0) //uses collate
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pd->how == QOF_COMPARE_CONTAINS || pd->how == QOF_COMPARE_NCONTAINS)
|
||||
{
|
||||
if (strstr (s, pdata->matchstring))
|
||||
ret = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (g_strcmp0 (s, pdata->matchstring) == 0)
|
||||
ret = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch (pd->how)
|
||||
{
|
||||
case QOF_COMPARE_CONTAINS:
|
||||
return ret;
|
||||
case QOF_COMPARE_NCONTAINS:
|
||||
return !ret;
|
||||
case QOF_COMPARE_EQUAL:
|
||||
return ret;
|
||||
case QOF_COMPARE_NEQ:
|
||||
@ -264,8 +285,9 @@ qof_query_string_predicate (QofQueryCompare how,
|
||||
query_string_t pdata;
|
||||
|
||||
g_return_val_if_fail (str, NULL);
|
||||
g_return_val_if_fail (*str != '\0', NULL);
|
||||
g_return_val_if_fail (how == QOF_COMPARE_EQUAL || how == QOF_COMPARE_NEQ, NULL);
|
||||
// g_return_val_if_fail (*str != '\0', NULL);
|
||||
g_return_val_if_fail (how == QOF_COMPARE_CONTAINS || how == QOF_COMPARE_NCONTAINS ||
|
||||
how == QOF_COMPARE_EQUAL || how == QOF_COMPARE_NEQ, NULL);
|
||||
|
||||
pdata = g_new0 (query_string_def, 1);
|
||||
pdata->pd.type_name = query_string_type;
|
||||
|
@ -59,7 +59,9 @@ typedef enum
|
||||
QOF_COMPARE_EQUAL,
|
||||
QOF_COMPARE_GT,
|
||||
QOF_COMPARE_GTE,
|
||||
QOF_COMPARE_NEQ
|
||||
QOF_COMPARE_NEQ,
|
||||
QOF_COMPARE_CONTAINS,
|
||||
QOF_COMPARE_NCONTAINS
|
||||
} QofQueryCompare;
|
||||
|
||||
/** List of known core query data-types...
|
||||
|
Loading…
Reference in New Issue
Block a user