static QofQueryPredData* gncs_get_predicate (GNCSearchCoreType *fe) { GNCSearchString *ss = (GNCSearchString *)fe; QofQueryCompare how; QofStringMatch options = QOF_STRING_MATCH_NORMAL; gboolean is_regex = FALSE; g_return_val_if_fail (ss, NULL); g_return_val_if_fail (IS_GNCSEARCH_STRING (ss), NULL); switch (ss->how) { case SEARCH_STRING_MATCHES_REGEX: is_regex = TRUE; /* FALL THROUGH */ case SEARCH_STRING_CONTAINS: how = QOF_COMPARE_EQUAL; break; case SEARCH_STRING_NOT_MATCHES_REGEX: is_regex = TRUE; /* FALL THROUGH */ case SEARCH_STRING_NOT_CONTAINS: how = QOF_COMPARE_NEQ; break; default: g_warning ("invalid string choice: %d", ss->how); return NULL; } if (ss->ign_case) options = QOF_STRING_MATCH_CASEINSENSITIVE; return qof_query_string_predicate (how, ss->value, options, is_regex); }
void xaccQueryAddStringMatch (QofQuery* q, const char *matchstring, gboolean case_sens, gboolean use_regexp, QofQueryCompare how, QofQueryOp op, const char * path, ...) { QofQueryPredData *pred_data; GSList *param_list; va_list ap; if (!path || !q) return; pred_data = qof_query_string_predicate (how, (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); }
/** Creates a new query that searches for an GncEntry item with * description string equal to the given "desc" argument. The query * will find the single GncEntry with the latest (=newest) * DATE_ENTERED. */ static QofQuery *new_query_for_entry_desc(GncEntryLedger *reg, const char* desc, gboolean use_invoice) { QofQuery *query = NULL; QofQueryPredData *predData = NULL; GSList *param_list = NULL; GSList *primary_sort_params = NULL; const char* should_be_null = (use_invoice ? ENTRY_BILL : ENTRY_INVOICE); g_assert(reg); g_assert(desc); /* The query itself and its book */ query = qof_query_create_for (GNC_ID_ENTRY); qof_query_set_book (query, reg->book); /* Predicate data: We want to compare one string, namely the given * argument */ predData = qof_query_string_predicate (QOF_COMPARE_EQUAL, desc, QOF_STRING_MATCH_CASEINSENSITIVE, FALSE); /* Search Parameter: We want to query on the ENTRY_DESC column */ param_list = qof_query_build_param_list (ENTRY_DESC, NULL); /* Register this in the query */ qof_query_add_term (query, param_list, predData, QOF_QUERY_FIRST_TERM); /* For invoice entries, Entry->Bill must be NULL, and vice versa */ qof_query_add_guid_match (query, qof_query_build_param_list (should_be_null, QOF_PARAM_GUID, NULL), NULL, QOF_QUERY_AND); /* Set the sort order: By DATE_ENTERED, increasing, and returning * only one single resulting item. */ primary_sort_params = qof_query_build_param_list(ENTRY_DATE_ENTERED, NULL); qof_query_set_sort_order (query, primary_sort_params, NULL, NULL); qof_query_set_sort_increasing (query, TRUE, TRUE, TRUE); qof_query_set_max_results(query, 1); return query; }