GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Data Structures | Macros | Typedefs | Enumerations | Enumerator | Variables
Query: Querying for Objects

BASIC QUERY API: With this API you can create arbitrary logical queries to find sets of arbitrary object. More...

Files

file  qofquery.h
 find objects that match a certain expression.
 
file  qofquerycore.h
 API for providing core Query data types.
 

Data Structures

struct  QofQueryPredData
 No extended comparisons for QOF_TYPE_INT32, QOF_TYPE_INT64, QOF_TYPE_DOUBLE, QOF_TYPE_BOOLEAN. More...
 

Macros

#define QOF_MOD_QUERY   "qof.query"
 
#define QOF_QUERY_FIRST_TERM   QOF_QUERY_AND
 First/only term is same as 'and'.
 
#define QUERY_DEFAULT_SORT   "QofQueryDefaultSort"
 Default sort object type.
 
#define QOF_PARAM_BOOK   "book"
 "Known" Object Parameters – all objects must support these
 
#define QOF_PARAM_GUID   "guid"
 
#define QOF_PARAM_KVP   "kvp"
 "Known" Object Parameters – some objects might support these
 
#define QOF_PARAM_ACTIVE   "active"
 
#define QOF_PARAM_VERSION   "version"
 

Typedefs

typedef GSList QofQueryParamList
 A list of parameters (QofIdType) used to describe a parameter to use in a predicate or when sorting.
 

Enumerations

enum  QofQueryOp {
  QOF_QUERY_AND = 1 , QOF_QUERY_OR , QOF_QUERY_NAND , QOF_QUERY_NOR ,
  QOF_QUERY_XOR
}
 Query Term Operators, for combining Query Terms. More...
 
enum  QofQueryCompare {
  QOF_COMPARE_LT = 1 , QOF_COMPARE_LTE , QOF_COMPARE_EQUAL , QOF_COMPARE_GT ,
  QOF_COMPARE_GTE , QOF_COMPARE_NEQ , QOF_COMPARE_CONTAINS , QOF_COMPARE_NCONTAINS
}
 Standard Query comparators, for how to compare objects in a predicate. More...
 
enum  QofStringMatch { QOF_STRING_MATCH_NORMAL = 1 , QOF_STRING_MATCH_CASEINSENSITIVE }
 List of known core query data-types... Each core query type defines it's set of optional "comparator qualifiers". More...
 
enum  QofDateMatch { QOF_DATE_MATCH_NORMAL = 1 , QOF_DATE_MATCH_DAY }
 Comparisons for QOF_TYPE_DATE The QOF_DATE_MATCH_DAY comparison rounds the two time values to mid-day and then compares these rounded values. More...
 
enum  QofNumericMatch { QOF_NUMERIC_MATCH_DEBIT = 1 , QOF_NUMERIC_MATCH_CREDIT , QOF_NUMERIC_MATCH_ANY }
 Comparisons for QOF_TYPE_NUMERIC, QOF_TYPE_DEBCRED. More...
 
enum  QofGuidMatch {
  QOF_GUID_MATCH_ANY = 1 , QOF_GUID_MATCH_NONE , QOF_GUID_MATCH_NULL , QOF_GUID_MATCH_ALL ,
  QOF_GUID_MATCH_LIST_ANY
}
 
enum  QofCharMatch { QOF_CHAR_MATCH_ANY = 1 , QOF_CHAR_MATCH_NONE }
 A CHAR type is for a RECNCell, Comparisons for QOF_TYPE_CHAR 'ANY' will match any character in the string. More...
 

Variables

QofType QofQueryPredData::type_name
 
QofQueryCompare QofQueryPredData::how
 

Query Subsystem Initialization and Shutdown <br>

void qof_query_init (void)
 Subsystem initialization and shutdown.
 
void qof_query_shutdown (void)
 

Low-Level API Functions

QofQueryParamListqof_query_build_param_list (char const *param,...)
 
QofQueryqof_query_create (void)
 Create a new query.
 
QofQueryqof_query_create_for (QofIdTypeConst obj_type)
 
void qof_query_destroy (QofQuery *q)
 Frees the resources associate with a Query object.
 
void qof_query_search_for (QofQuery *query, QofIdTypeConst obj_type)
 Set the object type to be searched for.
 
void qof_query_set_book (QofQuery *q, QofBook *book)
 Set the book to be searched.
 
void qof_query_add_term (QofQuery *query, QofQueryParamList *param_list, QofQueryPredData *pred_data, QofQueryOp op)
 This is the general function that adds a new Query Term to a query.
 
void qof_query_add_guid_match (QofQuery *q, QofQueryParamList *param_list, const GncGUID *guid, QofQueryOp op)
 DOCUMENT ME !!
 
void qof_query_add_guid_list_match (QofQuery *q, QofQueryParamList *param_list, GList *guid_list, QofGuidMatch options, QofQueryOp op)
 DOCUMENT ME !!
 
void qof_query_add_boolean_match (QofQuery *q, QofQueryParamList *param_list, gboolean value, QofQueryOp op)
 Handy-dandy convenience routines, avoids having to create a separate predicate for boolean matches.
 
GList * qof_query_run (QofQuery *query)
 Perform the query, return the results.
 
GList * qof_query_last_run (QofQuery *query)
 Return the results of the last query, without causing the query to be re-run.
 
GList * qof_query_run_subquery (QofQuery *subquery, const QofQuery *primary_query)
 Perform a subquery, return the results.
 
void qof_query_clear (QofQuery *query)
 Remove all query terms from query.
 
void qof_query_purge_terms (QofQuery *q, QofQueryParamList *param_list)
 Remove query terms of a particular type from q.
 
int qof_query_has_terms (QofQuery *q)
 Return boolean FALSE if there are no terms in the query Can be used as a predicate to see if the query has been initialized (return value > 0) or is "blank" (return value == 0).
 
int qof_query_num_terms (QofQuery *q)
 Return the number of terms in the canonical form of the query.
 
gboolean qof_query_has_term_type (QofQuery *q, QofQueryParamList *term_param)
 DOCUMENT ME !!
 
GSList * qof_query_get_term_type (QofQuery *q, QofQueryParamList *term_param)
 
QofQueryqof_query_copy (QofQuery *q)
 Make a copy of the indicated query.
 
QofQueryqof_query_invert (QofQuery *q)
 Make a copy of the indicated query, inverting the sense of the search.
 
QofQueryqof_query_merge (QofQuery *q1, QofQuery *q2, QofQueryOp op)
 Combine two queries together using the Boolean set (logical) operator 'op'.
 
void qof_query_merge_in_place (QofQuery *q1, QofQuery *q2, QofQueryOp op)
 Like qof_query_merge, but this will merge a copy of q2 into q1.
 
void qof_query_set_sort_order (QofQuery *q, QofQueryParamList *primary_sort_params, QofQueryParamList *secondary_sort_params, QofQueryParamList *tertiary_sort_params)
 When a query is run, the results are sorted before being returned.
 
void qof_query_set_sort_options (QofQuery *q, gint prim_op, gint sec_op, gint tert_op)
 
void qof_query_set_sort_increasing (QofQuery *q, gboolean prim_inc, gboolean sec_inc, gboolean tert_inc)
 When a query is run, the results are sorted before being returned.
 
void qof_query_set_max_results (QofQuery *q, int n)
 Set the maximum number of results that should be returned.
 
gboolean qof_query_equal (const QofQuery *q1, const QofQuery *q2)
 Compare two queries for equality.
 
QofIdType qof_query_get_search_for (const QofQuery *q)
 Return the type of data we're querying for.
 
GList * qof_query_get_books (QofQuery *q)
 Return the list of books we're using.
 

Core Data Type Predicates

QofQueryPredData * qof_query_string_predicate (QofQueryCompare how, const gchar *str, QofStringMatch options, gboolean is_regex)
 
QofQueryPredData * qof_query_date_predicate (QofQueryCompare how, QofDateMatch options, time64 date)
 
QofQueryPredData * qof_query_numeric_predicate (QofQueryCompare how, QofNumericMatch options, gnc_numeric value)
 
QofQueryPredData * qof_query_guid_predicate (QofGuidMatch options, GList *guids)
 
QofQueryPredData * qof_query_int32_predicate (QofQueryCompare how, gint32 val)
 
QofQueryPredData * qof_query_int64_predicate (QofQueryCompare how, gint64 val)
 
QofQueryPredData * qof_query_double_predicate (QofQueryCompare how, double val)
 
QofQueryPredData * qof_query_boolean_predicate (QofQueryCompare how, gboolean val)
 
QofQueryPredData * qof_query_char_predicate (QofCharMatch options, const gchar *chars)
 
QofQueryPredData * qof_query_choice_predicate (QofGuidMatch options, GList *guids)
 
QofQueryPredData * qof_query_core_predicate_copy (const QofQueryPredData *pdata)
 Copy a predicate.
 
void qof_query_core_predicate_free (QofQueryPredData *pdata)
 Destroy a predicate.
 
gboolean qof_query_date_predicate_get_date (const QofQueryPredData *pd, time64 *date)
 Retrieve a predicate.
 
gboolean qof_query_char_predicate_get_char (const QofQueryPredData *pd, char **chars)
 
char * qof_query_core_to_string (QofType, gpointer object, QofParam *getter)
 Return a printable string for a core data object.
 
int qof_string_number_compare_func (gpointer a, gpointer b, gint options, QofParam *this_param)
 Compare two parameter(strings) as if they are numbers! the two objects, a and b, are the objects being compared this_param is the QofParam for this parameter in the objects.
 

Detailed Description

BASIC QUERY API: With this API you can create arbitrary logical queries to find sets of arbitrary object.

To make simple queries (1 term, such as a search for a parameter with one value), create the appropriate QueryTerm structure and stick it in a Query object using xaccInitQuery. The QueryTerm should be malloc'd but the Query object will handle freeing it. To make compound queries, make multiple simple queries and combine them using qof_query_merge() and the logical operations of your choice.

SQL QUERY API: As an alternative to building queries one predicate at a time, you can use the SQL query interface. This interface will accept a string containing an SQL query, parse it, convert it into the core representation, and execute it.

STRUCTURE OF A QUERY: A Query is a logical function of any number of QueryTerms. A QueryTerm consists of a C function pointer (the Predicate) and a PredicateData structure containing data passed to the predicate function. The PredicateData structure is a constant associated with the Term and is identical for every object that is tested.

The terms of the Query may represent any logical function and are stored in canonical form, i.e. the function is expressed as a logical sum of logical products. So if you have QueryTerms a, b, c, d, e and you have the logical function a(b+c) + !(c(d+e)), it gets stored as ab + ac + !c + !c!e +!d!c + !d!e. This may not be optimal for evaluation of some functions but it's easy to store, easy to manipulate, and it doesn't require a complete algebra system to deal with.

The representation is of a GList of GLists of QueryTerms. The "backbone" GList q->terms represents the OR-chain, and every item on the backbone is a GList of QueryTerms representing an AND-chain corresponding to a single product-term in the canonical representation. QueryTerms are duplicated when necessary to fill out the canonical form, and the same predicate may be evaluated multiple times per split for complex queries. This is a place where we could probably optimize.

Macro Definition Documentation

◆ QOF_MOD_QUERY

#define QOF_MOD_QUERY   "qof.query"

Definition at line 86 of file qofquery.h.

◆ QOF_PARAM_ACTIVE

#define QOF_PARAM_ACTIVE   "active"

Definition at line 113 of file qofquery.h.

◆ QOF_PARAM_BOOK

#define QOF_PARAM_BOOK   "book"

"Known" Object Parameters – all objects must support these

Definition at line 108 of file qofquery.h.

◆ QOF_PARAM_GUID

#define QOF_PARAM_GUID   "guid"

Definition at line 109 of file qofquery.h.

◆ QOF_PARAM_KVP

#define QOF_PARAM_KVP   "kvp"

"Known" Object Parameters – some objects might support these

Definition at line 112 of file qofquery.h.

◆ QOF_PARAM_VERSION

#define QOF_PARAM_VERSION   "version"

Definition at line 114 of file qofquery.h.

◆ QOF_QUERY_FIRST_TERM

#define QOF_QUERY_FIRST_TERM   QOF_QUERY_AND

First/only term is same as 'and'.

Definition at line 102 of file qofquery.h.

◆ QUERY_DEFAULT_SORT

#define QUERY_DEFAULT_SORT   "QofQueryDefaultSort"

Default sort object type.

Definition at line 105 of file qofquery.h.

Typedef Documentation

◆ QofQueryParamList

typedef GSList QofQueryParamList

A list of parameters (QofIdType) used to describe a parameter to use in a predicate or when sorting.

Definition at line 151 of file qofquerycore.h.

Enumeration Type Documentation

◆ QofCharMatch

A CHAR type is for a RECNCell, Comparisons for QOF_TYPE_CHAR 'ANY' will match any character in the string.

Match 'ANY' is a convenience/performance-enhanced predicate for the compound statement (value==char1) || (value==char2) || etc. Match 'NONE' is equivalent to (value != char1) && (value != char2) && etc.

Definition at line 132 of file qofquerycore.h.

133{
134 QOF_CHAR_MATCH_ANY = 1,
135 QOF_CHAR_MATCH_NONE
QofCharMatch
A CHAR type is for a RECNCell, Comparisons for QOF_TYPE_CHAR 'ANY' will match any character in the st...

◆ QofDateMatch

Comparisons for QOF_TYPE_DATE The QOF_DATE_MATCH_DAY comparison rounds the two time values to mid-day and then compares these rounded values.

The QOF_DATE_MATCH_NORMAL comparison matches the time values, down to the second.

Definition at line 83 of file qofquerycore.h.

84{
85 QOF_DATE_MATCH_NORMAL = 1,
86 QOF_DATE_MATCH_DAY
QofDateMatch
Comparisons for QOF_TYPE_DATE The QOF_DATE_MATCH_DAY comparison rounds the two time values to mid-day...

◆ QofGuidMatch

Enumerator
QOF_GUID_MATCH_ANY 

These expect a single object and expect the QofAccessFunc returns GncGUID*.

QOF_GUID_MATCH_ALL 

These expect a GList* of objects and calls the QofAccessFunc routine on each item in the list to obtain a GncGUID* for each object.

QOF_GUID_MATCH_LIST_ANY 

These expect a single object and expect the QofAccessFunc function to return a GList* of GncGUID* (the list is the property of the caller)

Definition at line 109 of file qofquerycore.h.

110{
114 QOF_GUID_MATCH_NONE,
115 QOF_GUID_MATCH_NULL,
QofGuidMatch
@ QOF_GUID_MATCH_ALL
These expect a GList* of objects and calls the QofAccessFunc routine on each item in the list to obta...
@ QOF_GUID_MATCH_ANY
These expect a single object and expect the QofAccessFunc returns GncGUID*.
@ QOF_GUID_MATCH_LIST_ANY
These expect a single object and expect the QofAccessFunc function to return a GList* of GncGUID* (th...

◆ QofNumericMatch

Comparisons for QOF_TYPE_NUMERIC, QOF_TYPE_DEBCRED.

XXX Should be deprecated, or at least wrapped up as a convenience function, this is based on the old bill gribble code, which assumed the amount was always positive, and then specified a funds-flow direction (credit, debit, or either).

The point being that 'match credit' is equivalent to the compound predicate (amount >= 0) && (amount 'op' value) while the 'match debit' predicate is equivalent to (amount <= 0) && (abs(amount) 'op' value)

Definition at line 101 of file qofquerycore.h.

102{
103 QOF_NUMERIC_MATCH_DEBIT = 1,
104 QOF_NUMERIC_MATCH_CREDIT,
105 QOF_NUMERIC_MATCH_ANY
QofNumericMatch
Comparisons for QOF_TYPE_NUMERIC, QOF_TYPE_DEBCRED.

◆ QofQueryCompare

Standard Query comparators, for how to compare objects in a predicate.

Note that not all core types implement all comparators

Definition at line 54 of file qofquerycore.h.

55{
56 QOF_COMPARE_LT = 1,
57 QOF_COMPARE_LTE,
58 QOF_COMPARE_EQUAL,
59 QOF_COMPARE_GT,
60 QOF_COMPARE_GTE,
61 QOF_COMPARE_NEQ,
62 QOF_COMPARE_CONTAINS,
63 QOF_COMPARE_NCONTAINS
QofQueryCompare
Standard Query comparators, for how to compare objects in a predicate.

◆ QofQueryOp

enum QofQueryOp

Query Term Operators, for combining Query Terms.

Definition at line 92 of file qofquery.h.

93{
94 QOF_QUERY_AND = 1,
95 QOF_QUERY_OR,
96 QOF_QUERY_NAND,
97 QOF_QUERY_NOR,
98 QOF_QUERY_XOR
QofQueryOp
Query Term Operators, for combining Query Terms.
Definition qofquery.h:93

◆ QofStringMatch

List of known core query data-types... Each core query type defines it's set of optional "comparator qualifiers".

Definition at line 70 of file qofquerycore.h.

71{
72 QOF_STRING_MATCH_NORMAL = 1,
73 QOF_STRING_MATCH_CASEINSENSITIVE
QofStringMatch
List of known core query data-types... Each core query type defines it's set of optional "comparator ...

Function Documentation

◆ qof_query_add_boolean_match()

void qof_query_add_boolean_match ( QofQuery q,
QofQueryParamList param_list,
gboolean  value,
QofQueryOp  op 
)

Handy-dandy convenience routines, avoids having to create a separate predicate for boolean matches.

We might want to create handy-dandy sugar routines for the other predicate types as well.

Definition at line 1347 of file qofquery.cpp.

1349{
1350 QofQueryPredData *pdata;
1351 if (!q || !param_list) return;
1352
1353 pdata = qof_query_boolean_predicate (QOF_COMPARE_EQUAL, value);
1354 qof_query_add_term (q, param_list, pdata, op);
1355}
void qof_query_add_term(QofQuery *q, QofQueryParamList *param_list, QofQueryPredData *pred_data, QofQueryOp op)
This is the general function that adds a new Query Term to a query.
Definition qofquery.cpp:681

◆ qof_query_add_guid_list_match()

void qof_query_add_guid_list_match ( QofQuery q,
QofQueryParamList param_list,
GList *  guid_list,
QofGuidMatch  options,
QofQueryOp  op 
)

DOCUMENT ME !!

Definition at line 1295 of file qofquery.cpp.

1298{
1299 QofQueryPredData *pdata;
1300
1301 if (!q || !param_list) return;
1302
1303 if (!guid_list)
1304 g_return_if_fail (options == QOF_GUID_MATCH_NULL);
1305
1306 pdata = qof_query_guid_predicate (options, guid_list);
1307 qof_query_add_term (q, param_list, pdata, op);
1308}

◆ qof_query_add_guid_match()

void qof_query_add_guid_match ( QofQuery q,
QofQueryParamList param_list,
const GncGUID guid,
QofQueryOp  op 
)

DOCUMENT ME !!

Definition at line 1310 of file qofquery.cpp.

1312{
1313 GList *g = nullptr;
1314
1315 if (!q || !param_list) return;
1316
1317 if (guid)
1318 g = g_list_prepend (g, (gpointer)guid);
1319
1320 qof_query_add_guid_list_match (q, param_list, g,
1321 g ? QOF_GUID_MATCH_ANY : QOF_GUID_MATCH_NULL, op);
1322
1323 g_list_free (g);
1324}
void qof_query_add_guid_list_match(QofQuery *q, QofQueryParamList *param_list, GList *guid_list, QofGuidMatch options, QofQueryOp op)
DOCUMENT ME !!

◆ qof_query_add_term()

void qof_query_add_term ( QofQuery query,
QofQueryParamList param_list,
QofQueryPredData *  pred_data,
QofQueryOp  op 
)

This is the general function that adds a new Query Term to a query.

It will find the 'obj_type' object of the search item and compare the 'param_list' parameter to the predicate data via the comparator.

The param_list is a recursive list of parameters. For example, you can say 'split->memo' by creating a list of one element, "SPLIT_MEMO". You can say 'split->account->name' by creating a list of two elements, "SPLIT_ACCOUNT" and "ACCOUNT_NAME". The list becomes the property of the Query.

For example:

acct_name_pred_data = make_string_pred_data(QOF_STRING_MATCH_CASEINSENSITIVE, account_name); param_list = make_list (SPLIT_ACCOUNT, ACCOUNT_NAME, NULL); qof_query_add_term (query, param_list, QOF_COMPARE_EQUAL, acct_name_pred_data, QOF_QUERY_AND);

Please note that QofQuery does not, at this time, support joins. That is, one cannot specify a predicate that is a parameter list. Put another way, one cannot search for objects where obja->thingy == objb->stuff

Definition at line 681 of file qofquery.cpp.

683{
684 QofQueryTerm *qt;
685 QofQuery *qr, *qs;
686
687 if (!q || !param_list || !pred_data) return;
688
689 qt = g_new0 (QofQueryTerm, 1);
690 qt->param_list = param_list;
691 qt->pdata = pred_data;
692 qs = qof_query_create ();
693 query_init (qs, qt);
694
695 if (q->terms != nullptr)
696 qr = qof_query_merge (q, qs, op);
697 else
698 qr = qof_query_merge (q, qs, QOF_QUERY_OR);
699
700 swap_terms (q, qr);
703}
QofQuery * qof_query_merge(QofQuery *q1, QofQuery *q2, QofQueryOp op)
Combine two queries together using the Boolean set (logical) operator 'op'.
void qof_query_destroy(QofQuery *q)
Frees the resources associate with a Query object.
QofQuery * qof_query_create(void)
Create a new query.
Definition qofquery.cpp:918
A Query.
Definition qofquery.cpp:75

◆ qof_query_boolean_predicate()

QofQueryPredData * qof_query_boolean_predicate ( QofQueryCompare  how,
gboolean  val 
)

Definition at line 1108 of file qofquerycore.cpp.

1109{
1110 query_boolean_t pdata;
1111 g_return_val_if_fail (how == QOF_COMPARE_EQUAL || how == QOF_COMPARE_NEQ, nullptr);
1112
1113 pdata = g_new0 (query_boolean_def, 1);
1114 pdata->pd.type_name = query_boolean_type;
1115 pdata->pd.how = how;
1116 pdata->val = val;
1117 return ((QofQueryPredData*)pdata);
1118}

◆ qof_query_build_param_list()

QofQueryParamList * qof_query_build_param_list ( char const *  param,
  ... 
)

Definition at line 662 of file qofquery.cpp.

663{
664 QofQueryParamList *param_list = nullptr;
665 char const *this_param;
666 va_list ap;
667
668 if (!param)
669 return nullptr;
670
671 va_start (ap, param);
672
673 for (this_param = param; this_param; this_param = va_arg (ap, const char *))
674 param_list = g_slist_prepend (param_list, (gpointer)this_param);
675
676 va_end (ap);
677
678 return g_slist_reverse (param_list);
679}
GSList QofQueryParamList
A list of parameters (QofIdType) used to describe a parameter to use in a predicate or when sorting.

◆ qof_query_char_predicate_get_char()

gboolean qof_query_char_predicate_get_char ( const QofQueryPredData *  pd,
char **  chars 
)

Definition at line 1206 of file qofquerycore.cpp.

1207{
1208 const query_char_t pdata = (const query_char_t)pd;
1209
1210 if (pdata->pd.type_name != query_char_type)
1211 return FALSE;
1212
1213 *chars = g_strdup (pdata->char_list);
1214 return TRUE;
1215}

◆ qof_query_choice_predicate()

QofQueryPredData * qof_query_choice_predicate ( QofGuidMatch  options,
GList *  guids 
)

Definition at line 1372 of file qofquerycore.cpp.

1373{
1374 query_choice_t pdata;
1375 GList *node;
1376
1377 if (nullptr == guid_list) return nullptr;
1378
1379 pdata = g_new0 (query_choice_def, 1);
1380 pdata->pd.how = QOF_COMPARE_EQUAL;
1381 pdata->pd.type_name = query_choice_type;
1382 pdata->options = options;
1383
1384 pdata->guids = g_list_copy (guid_list);
1385 for (node = pdata->guids; node; node = node->next)
1386 {
1387 GncGUID *guid = guid_malloc ();
1388 *guid = *((GncGUID *)node->data);
1389 node->data = guid;
1390 }
1391 return ((QofQueryPredData*)pdata);
1392}
GncGUID * guid_malloc(void)
Allocate memory for a GUID.
Definition guid.cpp:139
The type used to store guids in C.
Definition guid.h:75

◆ qof_query_clear()

void qof_query_clear ( QofQuery query)

Remove all query terms from query.

query matches nothing after qof_query_clear().

Definition at line 905 of file qofquery.cpp.

906{
907 QofQuery *q2 = qof_query_create ();
908 swap_terms (query, q2);
910
911 g_list_free (query->books);
912 query->books = nullptr;
913 g_list_free (query->results);
914 query->results = nullptr;
915 query->changed = 1;
916}

◆ qof_query_copy()

QofQuery * qof_query_copy ( QofQuery q)

Make a copy of the indicated query.

Definition at line 1018 of file qofquery.cpp.

1019{
1020 QofQuery *copy;
1021 GHashTable *ht;
1022
1023 if (!q) return nullptr;
1024 copy = qof_query_create ();
1025 ht = copy->be_compiled;
1026 free_members (copy);
1027
1028 *copy = *q;
1029
1030 copy->be_compiled = ht;
1031 copy->terms = copy_or_terms (q->terms);
1032 copy->books = g_list_copy (q->books);
1033 copy->results = g_list_copy (q->results);
1034
1035 copy_sort (&(copy->primary_sort), &(q->primary_sort));
1036 copy_sort (&(copy->secondary_sort), &(q->secondary_sort));
1037 copy_sort (&(copy->tertiary_sort), &(q->tertiary_sort));
1038
1039 copy->changed = 1;
1040
1041 return copy;
1042}

◆ qof_query_core_predicate_copy()

QofQueryPredData * qof_query_core_predicate_copy ( const QofQueryPredData *  pdata)

Copy a predicate.

Definition at line 1603 of file qofquerycore.cpp.

1604{
1605 QueryPredicateCopyFunc copy;
1606
1607 g_return_val_if_fail (pdata, nullptr);
1608 g_return_val_if_fail (pdata->type_name, nullptr);
1609
1610 copy = qof_query_copy_predicate (pdata->type_name);
1611 return (copy (pdata));
1612}

◆ qof_query_core_predicate_free()

void qof_query_core_predicate_free ( QofQueryPredData *  pdata)

Destroy a predicate.

Definition at line 1591 of file qofquerycore.cpp.

1592{
1593 QueryPredDataFree free_fcn;
1594
1595 g_return_if_fail (pdata);
1596 g_return_if_fail (pdata->type_name);
1597
1598 free_fcn = qof_query_predicate_free (pdata->type_name);
1599 free_fcn (pdata);
1600}

◆ qof_query_core_to_string()

char * qof_query_core_to_string ( QofType  type,
gpointer  object,
QofParam *  getter 
)

Return a printable string for a core data object.

Caller needs to g_free() the returned string.

Definition at line 1615 of file qofquerycore.cpp.

1617{
1618 QueryToString toString;
1619
1620 g_return_val_if_fail (type, nullptr);
1621 g_return_val_if_fail (object, nullptr);
1622 g_return_val_if_fail (getter, nullptr);
1623
1624 toString = reinterpret_cast<QueryToString>(g_hash_table_lookup (toStringTable, type));
1625 g_return_val_if_fail (toString, nullptr);
1626
1627 return toString (object, getter);
1628}

◆ qof_query_create()

QofQuery * qof_query_create ( void  )

Create a new query.

Before running the query, a 'search-for' type must be set otherwise nothing will be returned. The results of the query is a list of the indicated search-for type.

Allocates and initializes a Query structure which must be freed by the user with qof_query_destroy(). A newly-allocated QofQuery object matches nothing (qof_query_run() will return NULL).

Definition at line 918 of file qofquery.cpp.

919{
920 QofQuery *qp = g_new0 (QofQuery, 1);
921 qp->be_compiled = g_hash_table_new (g_direct_hash, g_direct_equal);
922 query_init (qp, nullptr);
923 return qp;
924}

◆ qof_query_create_for()

QofQuery * qof_query_create_for ( QofIdTypeConst  obj_type)

Definition at line 108 of file fake-qofquery.cpp.

109{
110 return (QofQuery*)queryPool.request_query(obj_type);
111}

◆ qof_query_date_predicate()

QofQueryPredData * qof_query_date_predicate ( QofQueryCompare  how,
QofDateMatch  options,
time64  date 
)

Definition at line 420 of file qofquerycore.cpp.

422{
423 query_date_t pdata;
424
425 pdata = g_new0 (query_date_def, 1);
426 pdata->pd.type_name = query_date_type;
427 pdata->pd.how = how;
428 pdata->options = options;
429 pdata->date = date;
430 return ((QofQueryPredData*)pdata);
431}

◆ qof_query_date_predicate_get_date()

gboolean qof_query_date_predicate_get_date ( const QofQueryPredData *  pd,
time64 date 
)

Retrieve a predicate.

Definition at line 434 of file qofquerycore.cpp.

435{
436 const query_date_t pdata = (const query_date_t)pd;
437
438 if (pdata->pd.type_name != query_date_type)
439 return FALSE;
440 *date = pdata->date;
441 return TRUE;
442}

◆ qof_query_destroy()

void qof_query_destroy ( QofQuery q)

Frees the resources associate with a Query object.


Definition at line 114 of file fake-qofquery.cpp.

115{
116 queryPool.release_query((QofFakeQuery*)query);
117}
Fake object providing functionality similar to QofQuery.

◆ qof_query_double_predicate()

QofQueryPredData * qof_query_double_predicate ( QofQueryCompare  how,
double  val 
)

Definition at line 1027 of file qofquerycore.cpp.

1028{
1029 query_double_t pdata = g_new0 (query_double_def, 1);
1030 pdata->pd.type_name = query_double_type;
1031 pdata->pd.how = how;
1032 pdata->val = val;
1033 return ((QofQueryPredData*)pdata);
1034}

◆ qof_query_equal()

gboolean qof_query_equal ( const QofQuery q1,
const QofQuery q2 
)

Compare two queries for equality.

Query terms are compared each to each. This is a simplistic implementation – logical equivalences between different and/or trees are ignored.

Definition at line 1472 of file qofquery.cpp.

1473{
1474 GList *or1, *or2;
1475
1476 if (q1 == q2) return TRUE;
1477 if (!q1 || !q2) return FALSE;
1478
1479 if (q1->max_results != q2->max_results) return FALSE;
1480
1481 for (or1 = q1->terms, or2 = q2->terms; or1 || or2;
1482 or1 = or1->next, or2 = or2->next)
1483 {
1484 GList *and1, *and2;
1485
1486 if (!or1 || !or2)
1487 return FALSE;
1488 and1 = static_cast<GList*>(or1->data);
1489 and2 = static_cast<GList*>(or2->data);
1490
1491 for (; and1 || and2; and1 = and1->next, and2 = and2->next)
1492 {
1493 if (!and1 || !and2)
1494 return FALSE;
1495 if (!qof_query_term_equal (static_cast<QofQueryTerm*>(and1->data),
1496 static_cast<QofQueryTerm*>(and2->data)))
1497 return FALSE;
1498 }
1499 }
1500
1501 if (!qof_query_sort_equal (&(q1->primary_sort), &(q2->primary_sort)))
1502 return FALSE;
1503 if (!qof_query_sort_equal (&(q1->secondary_sort), &(q2->secondary_sort)))
1504 return FALSE;
1505 if (!qof_query_sort_equal (&(q1->tertiary_sort), &(q2->tertiary_sort)))
1506 return FALSE;
1507
1508 return TRUE;
1509}

◆ qof_query_get_books()

GList * qof_query_get_books ( QofQuery q)

Return the list of books we're using.

Definition at line 1341 of file qofquery.cpp.

1342{
1343 if (!q) return nullptr;
1344 return q->books;
1345}

◆ qof_query_get_search_for()

QofIdType qof_query_get_search_for ( const QofQuery q)

Return the type of data we're querying for.

Definition at line 1380 of file qofquery.cpp.

1381{
1382 if (!q) return nullptr;
1383 return q->search_for;
1384}

◆ qof_query_get_term_type()

GSList * qof_query_get_term_type ( QofQuery q,
QofQueryParamList term_param 
)

Definition at line 986 of file qofquery.cpp.

987{
988 GList *_or_;
989 GList *_and_;
990 GSList *results = nullptr;
991
992 if (!q || !term_param)
993 return FALSE;
994
995 for (_or_ = q->terms; _or_; _or_ = _or_->next)
996 {
997 for (_and_ = static_cast<GList*>(_or_->data); _and_;
998 _and_ = static_cast<GList*>(_and_->next))
999 {
1000 QofQueryTerm *qt = static_cast<QofQueryTerm*>(_and_->data);
1001 if (!param_list_cmp (term_param, qt->param_list))
1002 results = g_slist_prepend (results, qt->pdata);
1003 }
1004 }
1005
1006 return g_slist_reverse (results);
1007}

◆ qof_query_guid_predicate()

QofQueryPredData * qof_query_guid_predicate ( QofGuidMatch  options,
GList *  guids 
)

Definition at line 744 of file qofquerycore.cpp.

745{
746 query_guid_t pdata;
747 GList *node;
748
749 /* An empty list of guids is only valid when testing for a null GUID value */
750 if (!guid_list)
751 g_return_val_if_fail (options == QOF_GUID_MATCH_NULL, nullptr);
752
753 pdata = g_new0 (query_guid_def, 1);
754 pdata->pd.how = QOF_COMPARE_EQUAL;
755 pdata->pd.type_name = query_guid_type;
756 pdata->options = options;
757
758 pdata->guids = g_list_copy (guid_list);
759 for (node = pdata->guids; node; node = node->next)
760 {
761 GncGUID *guid = guid_malloc ();
762 *guid = *((GncGUID *)node->data);
763 node->data = guid;
764 }
765 return ((QofQueryPredData*)pdata);
766}

◆ qof_query_has_term_type()

gboolean qof_query_has_term_type ( QofQuery q,
QofQueryParamList term_param 
)

DOCUMENT ME !!

Definition at line 964 of file qofquery.cpp.

965{
966 GList *_or_;
967 GList *_and_;
968
969 if (!q || !term_param)
970 return FALSE;
971
972 for (_or_ = q->terms; _or_; _or_ = _or_->next)
973 {
974 for (_and_ = static_cast<GList*>(_or_->data); _and_;
975 _and_ = static_cast<GList*>(_and_->next))
976 {
977 QofQueryTerm* qt = static_cast<QofQueryTerm*>(_and_->data);
978 if (!param_list_cmp (term_param, qt->param_list))
979 return TRUE;
980 }
981 }
982
983 return FALSE;
984}

◆ qof_query_has_terms()

int qof_query_has_terms ( QofQuery q)

Return boolean FALSE if there are no terms in the query Can be used as a predicate to see if the query has been initialized (return value > 0) or is "blank" (return value == 0).

Definition at line 948 of file qofquery.cpp.

949{
950 if (!q) return 0;
951 return g_list_length (q->terms);
952}

◆ qof_query_init()

void qof_query_init ( void  )

Subsystem initialization and shutdown.

Call init() once to initialize the query subsystem; call shutdown() to free up any resources associated with the query subsystem. Typically called during application startup, shutdown.

Definition at line 1360 of file qofquery.cpp.

1361{
1362 ENTER (" ");
1363 qof_query_core_init ();
1364 qof_class_init ();
1365 LEAVE ("Completed initialization of QofQuery");
1366}
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272

◆ qof_query_int32_predicate()

QofQueryPredData * qof_query_int32_predicate ( QofQueryCompare  how,
gint32  val 
)

Definition at line 843 of file qofquerycore.cpp.

844{
845 query_int32_t pdata = g_new0 (query_int32_def, 1);
846 pdata->pd.type_name = query_int32_type;
847 pdata->pd.how = how;
848 pdata->val = val;
849 return ((QofQueryPredData*)pdata);
850}

◆ qof_query_int64_predicate()

QofQueryPredData * qof_query_int64_predicate ( QofQueryCompare  how,
gint64  val 
)

Definition at line 935 of file qofquerycore.cpp.

936{
937 query_int64_t pdata = g_new0 (query_int64_def, 1);
938 pdata->pd.type_name = query_int64_type;
939 pdata->pd.how = how;
940 pdata->val = val;
941 return ((QofQueryPredData*)pdata);
942}

◆ qof_query_invert()

QofQuery * qof_query_invert ( QofQuery q)

Make a copy of the indicated query, inverting the sense of the search.

In other words, if the original query search for all objects with a certain condition, the inverted query will search for all object with NOT that condition. The union of the results returned by the original and inverted queries equals the set of all searched objects. These to sets are disjoint (share no members in common).

This will return a newly allocated QofQuery object, or NULL on error. Free it with qof_query_destroy() when no longer needed.

Definition at line 1050 of file qofquery.cpp.

1051{
1052 QofQuery * retval;
1053 QofQuery * right, * left, * iright, * ileft;
1054 QofQueryTerm * qt;
1055 GList * aterms;
1056 GList * cur;
1057 GList * new_oterm;
1058 int num_or_terms;
1059
1060 if (!q)
1061 return nullptr;
1062
1063 num_or_terms = g_list_length(q->terms);
1064
1065 switch (num_or_terms)
1066 {
1067 case 0:
1068 retval = qof_query_create();
1069 retval->max_results = q->max_results;
1070 break;
1071
1072 /* This is the DeMorgan expansion for a single AND expression. */
1073 /* !(abc) = !a + !b + !c */
1074 case 1:
1075 retval = qof_query_create();
1076 retval->max_results = q->max_results;
1077 retval->books = g_list_copy (q->books);
1078 retval->search_for = q->search_for;
1079 retval->changed = 1;
1080
1081 aterms = static_cast<GList*>(g_list_nth_data(q->terms, 0));
1082 new_oterm = nullptr;
1083 for (cur = aterms; cur; cur = cur->next)
1084 {
1085 qt = copy_query_term(static_cast<QofQueryTerm*>(cur->data));
1086 qt->invert = !(qt->invert);
1087 new_oterm = g_list_append(nullptr, qt);
1088 retval->terms = g_list_prepend(retval->terms, new_oterm);
1089 }
1090 retval->terms = g_list_reverse(retval->terms);
1091 break;
1092
1093 /* If there are multiple OR-terms, we just recurse by
1094 * breaking it down to !(a + b + c) =
1095 * !a * !(b + c) = !a * !b * !c. */
1096 default:
1097 right = qof_query_create();
1098 right->terms = copy_or_terms(g_list_nth(q->terms, 1));
1099
1100 left = qof_query_create();
1101 left->terms = g_list_append(nullptr,
1102 copy_and_terms(static_cast<GList*>(g_list_nth_data(q->terms, 0))));
1103
1104 iright = qof_query_invert(right);
1105 ileft = qof_query_invert(left);
1106
1107 retval = qof_query_merge(iright, ileft, QOF_QUERY_AND);
1108 retval->books = g_list_copy (q->books);
1109 retval->max_results = q->max_results;
1110 retval->search_for = q->search_for;
1111 retval->changed = 1;
1112
1113 qof_query_destroy(iright);
1114 qof_query_destroy(ileft);
1115 qof_query_destroy(right);
1116 qof_query_destroy(left);
1117 break;
1118 }
1119
1120 return retval;
1121}
QofQuery * qof_query_invert(QofQuery *q)
Make a copy of the indicated query, inverting the sense of the search.

◆ qof_query_last_run()

GList * qof_query_last_run ( QofQuery query)

Return the results of the last query, without causing the query to be re-run.

Do NOT free the resulting list. This list is managed internally by QofQuery.

Definition at line 897 of file qofquery.cpp.

898{
899 if (!query)
900 return nullptr;
901
902 return query->results;
903}

◆ qof_query_merge()

QofQuery * qof_query_merge ( QofQuery q1,
QofQuery q2,
QofQueryOp  op 
)

Combine two queries together using the Boolean set (logical) operator 'op'.

For example, if the operator 'op' is set to QUERY_AND, then the set of results returned by the query will will be the Boolean set intersection of the results returned by q1 and q2. Similarly, QUERY_OR maps to set union, etc.

Both queries must have compatible search-types. If both queries are set, they must search for the same object type. If only one is set, the resulting query will search for the set type. If neither query has the search-type set, the result will be unset as well.

This will return a newly allocated QofQuery object, or NULL on error. Free it with qof_query_destroy() when no longer needed. Note that if either input query is NULL then the returned query is NOT newly allocated – it will return the non-NULL query. You only need to call this function when both q1 and q2 are non-NULL.

Definition at line 1129 of file qofquery.cpp.

1130{
1131
1132 QofQuery * retval = nullptr;
1133 QofQuery * i1, * i2;
1134 QofQuery * t1, * t2;
1135 GList * i, * j;
1136 QofIdType search_for;
1137
1138 if (!q1) return q2;
1139 if (!q2) return q1;
1140
1141 if (q1->search_for && q2->search_for)
1142 g_return_val_if_fail (g_strcmp0 (q1->search_for, q2->search_for) == 0,
1143 nullptr);
1144
1145 search_for = (q1->search_for ? q1->search_for : q2->search_for);
1146
1147 /* Avoid merge surprises if op==QOF_QUERY_AND but q1 is empty.
1148 * The goal of this tweak is to allow the user to start with
1149 * an empty q1 and then append to it recursively
1150 * (and q1 (and q2 (and q3 (and q4 ....))))
1151 * without bombing out because the append started with an
1152 * empty list.
1153 * We do essentially the same check in qof_query_add_term()
1154 * so that the first term added to an empty query doesn't screw up.
1155 */
1156 if ((QOF_QUERY_AND == op) &&
1157 (q1->terms == nullptr || q2->terms == nullptr))
1158 {
1159 op = QOF_QUERY_OR;
1160 }
1161
1162 switch (op)
1163 {
1164 case QOF_QUERY_OR:
1165 retval = qof_query_create();
1166 retval->terms =
1167 g_list_concat(copy_or_terms(q1->terms), copy_or_terms(q2->terms));
1168 retval->books = merge_books (q1->books, q2->books);
1169 retval->max_results = q1->max_results;
1170 retval->changed = 1;
1171 break;
1172
1173 case QOF_QUERY_AND:
1174 retval = qof_query_create();
1175 retval->books = merge_books (q1->books, q2->books);
1176 retval->max_results = q1->max_results;
1177 retval->changed = 1;
1178
1179 /* g_list_append() can take forever, so let's build the list in
1180 * reverse and then reverse it at the end, to deal better with
1181 * "large" queries.
1182 */
1183 for (i = q1->terms; i; i = i->next)
1184 {
1185 for (j = q2->terms; j; j = j->next)
1186 {
1187 retval->terms =
1188 g_list_prepend(retval->terms,
1189 g_list_concat
1190 (copy_and_terms(static_cast<GList*>(i->data)),
1191 copy_and_terms(static_cast<GList*>(j->data))));
1192 }
1193 }
1194 retval->terms = g_list_reverse(retval->terms);
1195 break;
1196
1197 case QOF_QUERY_NAND:
1198 /* !(a*b) = (!a + !b) */
1199 i1 = qof_query_invert(q1);
1200 i2 = qof_query_invert(q2);
1201 retval = qof_query_merge(i1, i2, QOF_QUERY_OR);
1204 break;
1205
1206 case QOF_QUERY_NOR:
1207 /* !(a+b) = (!a*!b) */
1208 i1 = qof_query_invert(q1);
1209 i2 = qof_query_invert(q2);
1210 retval = qof_query_merge(i1, i2, QOF_QUERY_AND);
1213 break;
1214
1215 case QOF_QUERY_XOR:
1216 /* a xor b = (a * !b) + (!a * b) */
1217 i1 = qof_query_invert(q1);
1218 i2 = qof_query_invert(q2);
1219 t1 = qof_query_merge(q1, i2, QOF_QUERY_AND);
1220 t2 = qof_query_merge(i1, q2, QOF_QUERY_AND);
1221 retval = qof_query_merge(t1, t2, QOF_QUERY_OR);
1222
1227 break;
1228 }
1229
1230 if (retval)
1231 retval->search_for = search_for;
1232 return retval;
1233}
const gchar * QofIdType
QofIdType declaration.
Definition qofid.h:80

◆ qof_query_merge_in_place()

void qof_query_merge_in_place ( QofQuery q1,
QofQuery q2,
QofQueryOp  op 
)

Like qof_query_merge, but this will merge a copy of q2 into q1.

q2 remains unchanged.

Definition at line 1236 of file qofquery.cpp.

1237{
1238 QofQuery *tmp_q;
1239
1240 if (!q1 || !q2)
1241 return;
1242
1243 tmp_q = qof_query_merge (q1, q2, op);
1244 swap_terms (q1, tmp_q);
1245 qof_query_destroy (tmp_q);
1246}

◆ qof_query_num_terms()

int qof_query_num_terms ( QofQuery q)

Return the number of terms in the canonical form of the query.

Definition at line 954 of file qofquery.cpp.

955{
956 GList *o;
957 int n = 0;
958 if (!q) return 0;
959 for (o = q->terms; o; o = o->next)
960 n += g_list_length(static_cast<GList*>(o->data));
961 return n;
962}

◆ qof_query_numeric_predicate()

QofQueryPredData * qof_query_numeric_predicate ( QofQueryCompare  how,
QofNumericMatch  options,
gnc_numeric  value 
)

Definition at line 556 of file qofquerycore.cpp.

559{
560 query_numeric_t pdata;
561 pdata = g_new0 (query_numeric_def, 1);
562 pdata->pd.type_name = query_numeric_type;
563 pdata->pd.how = how;
564 pdata->options = options;
565 pdata->amount = value;
566 return ((QofQueryPredData*)pdata);
567}

◆ qof_query_purge_terms()

void qof_query_purge_terms ( QofQuery q,
QofQueryParamList param_list 
)

Remove query terms of a particular type from q.

The "type" of a term is determined by the type of data that gets passed to the predicate function. XXX ??? Huh? remove anything of that predicate type, or just the particular predicate ?

Definition at line 705 of file qofquery.cpp.

706{
707 QofQueryTerm *qt;
708 GList *_or_, *_and_;
709
710 if (!q || !param_list) return;
711
712 for (_or_ = q->terms; _or_; _or_ = _or_->next)
713 {
714 for (_and_ = static_cast<GList*>(_or_->data); _and_;
715 _and_ = static_cast<GList*>(_and_->next))
716 {
717 qt = static_cast<QofQueryTerm*>(_and_->data);
718 if (!param_list_cmp (qt->param_list, param_list))
719 {
720 auto or_list = static_cast<GList*> (_or_->data);
721 if (or_list && !or_list->next)
722 {
723 q->terms = g_list_remove_link (static_cast<GList*>(q->terms), _or_);
724 g_list_free_1 (_or_);
725 _or_ = q->terms;
726 break;
727 }
728 else
729 {
730 _or_->data = g_list_remove_link (or_list, _and_);
731 g_list_free_1 (_and_);
732 _and_ = static_cast<GList*>(_or_->data);
733 if (!_and_) break;
734 }
735 q->changed = 1;
736 free_query_term (qt);
737 }
738 }
739 if (!_or_) break;
740 }
741}

◆ qof_query_run()

GList * qof_query_run ( QofQuery query)

Perform the query, return the results.

The returned list is a list of the 'search-for' type that was previously set with the qof_query_search_for() or the qof_query_create_for() routines. The returned list will have been sorted using the indicated sort order, and trimmed to the max_results length.

Do NOT free the resulting list. This list is managed internally by QofQuery.

Definition at line 149 of file fake-qofquery.cpp.

150{
151 GList *matching_objects = NULL;
152 bool query_used = queryPool.query_used(query);
153
154 EXPECT_TRUE(query_used);
155 if (query_used)
156 {
157 auto matchingObjects = ((QofFakeQuery*)query)->run();
158
159 for (auto object : matchingObjects)
160 {
161 matching_objects = g_list_append(matching_objects, static_cast<gpointer>(object));
162 }
163 }
164
165 return matching_objects;
166}

◆ qof_query_run_subquery()

GList * qof_query_run_subquery ( QofQuery subquery,
const QofQuery primary_query 
)

Perform a subquery, return the results.

Instead of running over a book, the subquery runs over the results of the primary query.

Do NOT free the resulting list. This list is managed internally by QofQuery.

Definition at line 880 of file qofquery.cpp.

881{
882 if (!subq) return nullptr;
883 if (!primaryq) return nullptr;
884
885 /* Make sure we're searching for the same thing */
886 g_return_val_if_fail (subq->search_for, nullptr);
887 g_return_val_if_fail (primaryq->search_for, nullptr);
888 g_return_val_if_fail(!g_strcmp0(subq->search_for, primaryq->search_for),
889 nullptr);
890
891 /* Perform the subquery */
892 return qof_query_run_internal(subq, qof_query_run_subq_cb,
893 (gpointer)primaryq);
894}

◆ qof_query_search_for()

void qof_query_search_for ( QofQuery query,
QofIdTypeConst  obj_type 
)

Set the object type to be searched for.

The results of performing the query will be a list of this obj_type.

Definition at line 926 of file qofquery.cpp.

927{
928 if (!q || !obj_type)
929 return;
930
931 if (g_strcmp0 (q->search_for, obj_type))
932 {
933 q->search_for = (QofIdType) obj_type;
934 q->changed = 1;
935 }
936}

◆ qof_query_set_book()

void qof_query_set_book ( QofQuery q,
QofBook book 
)

Set the book to be searched.

Books contain/identify collections of objects; the search will be performed over those books specified with this function. If no books are set, no results will be returned (since there is nothing to search over).

You can search multiple books. To specify multiple books, call this function multiple times with different arguments. XXX needed qof_query_clear_books() to reset the list ...

Definition at line 120 of file fake-qofquery.cpp.

121{
122 ASSERT_TRUE(queryPool.query_used(query));
123 ASSERT_TRUE(QOF_IS_BOOK(book));
124 ((QofFakeQuery*)query)->set_book(book);
125}

◆ qof_query_set_max_results()

void qof_query_set_max_results ( QofQuery q,
int  n 
)

Set the maximum number of results that should be returned.

If 'max-results' is set to -1, then all of the results are returned. If there are more results than 'max-results', then the result list is trimmed. Note that there is an important interplay between 'max-results' and the sort order: only the last bit of results are returned. For example, if the sort order is set to be increasing date order, then only the objects with the most recent dates will be returned.

Definition at line 1289 of file qofquery.cpp.

1290{
1291 if (!q) return;
1292 q->max_results = n;
1293}

◆ qof_query_set_sort_increasing()

void qof_query_set_sort_increasing ( QofQuery q,
gboolean  prim_inc,
gboolean  sec_inc,
gboolean  tert_inc 
)

When a query is run, the results are sorted before being returned.

This routine can be used to control the direction of the ordering. A value of TRUE indicates the sort will be in increasing order, a value of FALSE will order results in decreasing order.

Note that if there are more results than the 'max-results' value, then only the last max-results will be returned. For example, if the sort is set to be increasing date order, then only the objects with the most recent dates will be returned.

Definition at line 1280 of file qofquery.cpp.

1282{
1283 if (!q) return;
1284 q->primary_sort.increasing = prim_inc;
1285 q->secondary_sort.increasing = sec_inc;
1286 q->tertiary_sort.increasing = tert_inc;
1287}

◆ qof_query_set_sort_options()

void qof_query_set_sort_options ( QofQuery q,
gint  prim_op,
gint  sec_op,
gint  tert_op 
)

Definition at line 1271 of file qofquery.cpp.

1273{
1274 if (!q) return;
1275 q->primary_sort.options = prim_op;
1276 q->secondary_sort.options = sec_op;
1277 q->tertiary_sort.options = tert_op;
1278}

◆ qof_query_set_sort_order()

void qof_query_set_sort_order ( QofQuery q,
QofQueryParamList primary_sort_params,
QofQueryParamList secondary_sort_params,
QofQueryParamList tertiary_sort_params 
)

When a query is run, the results are sorted before being returned.

This routine can be used to set the parameters on which the sort will be performed. Two objects in the result list will be compared using the 'primary_sort_params', and sorted based on that order. If the comparison shows that they are equal, then the 'secondary_sort_params' will be used. If still equal, then the tertiary parameters will be compared. Any or all of these parameter lists may be NULL. Any of these parameter lists may be set to QUERY_DEFAULT_SORT.

Note that if there are more results than the 'max-results' value, then only the last max-results will be returned. For example, if the sort is set to be increasing date order, then only the objects with the most recent dates will be returned.

The input lists become the property of QofQuery and are managed by it. They will be freed when the query is destroyed (or when new lists are set).

Definition at line 1249 of file qofquery.cpp.

1251{
1252 if (!q) return;
1253 if (q->primary_sort.param_list)
1254 g_slist_free (q->primary_sort.param_list);
1255 q->primary_sort.param_list = params1;
1256 q->primary_sort.options = 0;
1257
1258 if (q->secondary_sort.param_list)
1259 g_slist_free (q->secondary_sort.param_list);
1260 q->secondary_sort.param_list = params2;
1261 q->secondary_sort.options = 0;
1262
1263 if (q->tertiary_sort.param_list)
1264 g_slist_free (q->tertiary_sort.param_list);
1265 q->tertiary_sort.param_list = params3;
1266 q->tertiary_sort.options = 0;
1267
1268 q->changed = 1;
1269}

◆ qof_query_shutdown()

void qof_query_shutdown ( void  )

Definition at line 1368 of file qofquery.cpp.

1369{
1370 qof_class_shutdown ();
1371 qof_query_core_shutdown ();
1372}

◆ qof_string_number_compare_func()

int qof_string_number_compare_func ( gpointer  a,
gpointer  b,
gint  options,
QofParam *  this_param 
)

Compare two parameter(strings) as if they are numbers! the two objects, a and b, are the objects being compared this_param is the QofParam for this parameter in the objects.

Definition at line 209 of file qofquerycore.cpp.

211{
212 const char *s1, *s2;
213 char *sr1, *sr2;
214 long i1, i2;
215 g_return_val_if_fail (a && b && getter && getter->param_getfcn, COMPARE_ERROR);
216
217 s1 = ((query_string_getter)getter->param_getfcn) (a, getter);
218 s2 = ((query_string_getter)getter->param_getfcn) (b, getter);
219
220 // Deal with nullptr strings
221 if (s1 == s2) return 0;
222 if (!s1 && s2) return -1;
223 if (s1 && !s2) return 1;
224
225 // Convert to integers and test
226 i1 = strtol(s1, &sr1, 10);
227 i2 = strtol(s2, &sr2, 10);
228 if (i1 < i2) return -1;
229 if (i1 > i2) return 1;
230
231 // If the integers match, then test the REST of the string as text.
232 if (options == QOF_STRING_MATCH_CASEINSENSITIVE)
233 return safe_strcasecmp (sr1, sr2);
234
235 return g_strcmp0 (sr1, sr2);
236}
gint safe_strcasecmp(const gchar *da, const gchar *db)
case sensitive comparison of strings da and db - either may be NULL.
Definition qofutil.cpp:100

Variable Documentation

◆ how

QofQueryCompare QofQueryPredData::how

Definition at line 146 of file qofquerycore.h.

◆ type_name

QofType QofQueryPredData::type_name

Definition at line 145 of file qofquerycore.h.