• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

mocks/H03-May-2022-1,188870

test/H03-May-2022-22,75916,212

test-core/H03-May-2022-2,4861,876

Account.cppH A D17-Dec-2021192.4 KiB6,2544,797

Account.hH A D04-Dec-202166.6 KiB1,662364

AccountP.hH A D26-Sep-20216.3 KiB18170

FreqSpec.hH A D14-Mar-20213.1 KiB7934

Query.cH A D14-Mar-202119.5 KiB669485

Query.hH A D14-Mar-20218.1 KiB19082

READMEH A D14-Mar-2021482 1510

README.query-apiH A D14-Mar-20218.8 KiB205157

Recurrence.cH A D04-Dec-202127.1 KiB899721

Recurrence.hH A D01-Aug-20217 KiB18961

SX-book-p.hH A D14-Mar-20212 KiB508

SX-book.cH A D26-Sep-202110.5 KiB392289

SX-book.hH A D01-Aug-20213.6 KiB9741

SX-ttinfo.cH A D14-Mar-20217.3 KiB359256

SX-ttinfo.hH A D14-Mar-20213.9 KiB9141

SchedXaction.cH A D01-Aug-202137 KiB1,276993

SchedXaction.hH A D01-Aug-202112.1 KiB329118

Scrub.cH A D04-Dec-202145.9 KiB1,5071,086

Scrub.hH A D01-Aug-20217.8 KiB17725

Scrub2.cH A D01-Aug-202112.4 KiB405243

Scrub2.hH A D01-Aug-20215.2 KiB1179

Scrub3.cH A D14-Mar-20216.6 KiB199111

Scrub3.hH A D14-Mar-20213.2 KiB767

ScrubBusiness.cH A D26-Sep-202127.7 KiB754485

ScrubBusiness.hH A D14-Mar-20214.7 KiB11110

Split.cH A D26-Sep-202172.8 KiB2,3761,816

Split.hH A D01-Aug-202122.1 KiB565120

SplitP.hH A D26-Sep-20219.5 KiB24082

TransLog.cH A D01-Aug-202110.2 KiB305172

TransLog.hH A D14-Mar-20213.4 KiB8813

Transaction.cH A D27-Sep-2021102.2 KiB3,2912,367

Transaction.hH A D01-Aug-202132.9 KiB796157

TransactionP.hH A D27-Sep-20218.3 KiB20853

cap-gains.cH A D01-Aug-202134.3 KiB979639

cap-gains.hH A D01-Aug-202110 KiB21318

cashobjects.cH A D04-Dec-20212.5 KiB8851

cashobjects.hH A D14-Mar-20211.2 KiB365

engine-helpers.cH A D11-Sep-20218.7 KiB257164

engine-helpers.hH A D11-Sep-20214.5 KiB9225

gnc-aqbanking-templates.cppH A D14-Mar-20219.9 KiB302249

gnc-aqbanking-templates.hH A D14-Mar-20215.6 KiB21443

gnc-backend-prov.hppH A D14-Mar-20213.9 KiB8419

gnc-budget.cH A D26-Sep-202124.6 KiB839641

gnc-budget.hH A D26-Sep-20216.8 KiB17859

gnc-commodity.cH A D26-Sep-202182.7 KiB2,6961,950

gnc-commodity.hH A D17-Dec-202139.3 KiB1,089208

gnc-date-p.hH A D14-Mar-20212.3 KiB8428

gnc-date.cppH A D15-Sep-202141.5 KiB1,6691,251

gnc-date.hH A D01-Aug-202130.1 KiB826151

gnc-datetime.cppH A D01-Aug-202123.7 KiB753608

gnc-datetime.hppH A D01-Aug-202112.6 KiB31590

gnc-engine.cH A D26-Sep-20214.9 KiB180112

gnc-engine.hH A D26-Sep-202111 KiB27490

gnc-event.cH A D14-Mar-20211.9 KiB5228

gnc-event.hH A D14-Mar-20212.1 KiB5514

gnc-features.cH A D04-Dec-20216.9 KiB182118

gnc-features.hH A D11-Sep-20213.6 KiB8924

gnc-hooks.cH A D01-Aug-20216.4 KiB232174

gnc-hooks.hH A D01-Aug-20212.4 KiB7723

gnc-int128.cppH A D14-Mar-202127 KiB1,072889

gnc-int128.hppH A D01-Aug-202110.2 KiB292123

gnc-lot-p.hH A D14-Mar-20211.9 KiB465

gnc-lot.cH A D26-Sep-202121.9 KiB829639

gnc-lot.hH A D01-Aug-20217.8 KiB19760

gnc-numeric.cppH A D26-Sep-202137.2 KiB1,3611,099

gnc-numeric.hH A D01-Aug-202117 KiB498120

gnc-numeric.hppH A D01-Aug-202116.3 KiB435180

gnc-pricedb-p.hH A D26-Sep-20213.3 KiB10055

gnc-pricedb.cH A D04-Dec-202192.9 KiB3,2302,506

gnc-pricedb.hH A D01-Aug-202130 KiB732202

gnc-rational-rounding.hppH A D14-Mar-20216.3 KiB224173

gnc-rational.cppH A D14-Mar-20218.6 KiB322269

gnc-rational.hppH A D14-Mar-202111.3 KiB286135

gnc-session.cH A D01-Aug-20211.8 KiB7141

gnc-session.hH A D14-Mar-20211.5 KiB285

gnc-timezone.cppH A D01-Aug-202125 KiB776628

gnc-timezone.hppH A D14-Mar-20213 KiB7345

gnc-uri-utils.cH A D01-Aug-202113 KiB452272

gnc-uri-utils.hH A D01-Aug-202111.7 KiB31735

gncAddress.cH A D26-Sep-202118.7 KiB671541

gncAddress.hH A D01-Aug-20216 KiB15854

gncAddressP.hH A D14-Mar-20211.7 KiB365

gncBillTerm.cH A D26-Sep-202124.2 KiB889649

gncBillTerm.hH A D01-Aug-20216.5 KiB17477

gncBillTermP.hH A D14-Mar-20212.1 KiB4711

gncBusiness.cH A D14-Mar-20212.9 KiB10060

gncBusiness.hH A D01-Aug-20213.4 KiB10137

gncCustomer.cH A D26-Sep-202127.2 KiB999778

gncCustomer.hH A D14-Mar-20216.9 KiB17076

gncCustomerP.hH A D14-Mar-20212 KiB429

gncEmployee.cH A D26-Sep-202128.7 KiB976770

gncEmployee.hH A D14-Mar-20216.1 KiB14367

gncEmployeeP.hH A D14-Mar-20212 KiB429

gncEntry.cH A D26-Sep-202152 KiB1,7321,290

gncEntry.hH A D01-Aug-202113.9 KiB341149

gncEntryP.hH A D01-Aug-20212.1 KiB4411

gncIDSearch.cH A D04-Dec-20215.1 KiB163106

gncIDSearch.hH A D14-Mar-20211.6 KiB4716

gncInvoice.cH A D26-Sep-202172 KiB2,3271,731

gncInvoice.hH A D01-Aug-202113.5 KiB322146

gncInvoiceP.hH A D01-Aug-20212.3 KiB5017

gncJob.cH A D26-Sep-202115.9 KiB603456

gncJob.hH A D14-Mar-20214.3 KiB12253

gncJobP.hH A D14-Mar-20211.8 KiB407

gncOrder.cH A D26-Sep-202116.6 KiB593447

gncOrder.hH A D14-Mar-20214.7 KiB12457

gncOrderP.hH A D01-Aug-20211.8 KiB407

gncOwner.cH A D26-Sep-202149.6 KiB1,6551,264

gncOwner.hH A D01-Aug-202113.9 KiB352111

gncOwnerP.hH A D14-Mar-20211.8 KiB397

gncTaxTable.cH A D26-Sep-202128.9 KiB1,064818

gncTaxTable.hH A D14-Mar-20217.8 KiB21291

gncTaxTableP.hH A D14-Mar-20212.2 KiB4812

gncVendor.cH A D26-Sep-202130.3 KiB1,054837

gncVendor.hH A D14-Mar-20215.6 KiB14067

gncVendorP.hH A D14-Mar-20211.9 KiB429

guid.cppH A D14-Mar-202110.1 KiB438329

guid.hH A D01-Aug-20216.8 KiB19141

guid.hppH A D14-Mar-20212.7 KiB6838

iso-4217-currencies.xmlH A D04-Dec-202157.7 KiB3,0842,499

iso-currencies-to-c.xslH A D14-Mar-20213.1 KiB5956

kvp-frame.cppH A D26-Sep-202113.4 KiB454383

kvp-frame.hppH A D01-Aug-202111.5 KiB27987

kvp-value.cppH A D11-Sep-202110.9 KiB405327

kvp-value.hppH A D11-Sep-20216.6 KiB21384

policy-p.hH A D11-Sep-20213.5 KiB8119

policy.cH A D11-Sep-20219.9 KiB327235

policy.hH A D11-Sep-20213.6 KiB9717

qof-backend.cppH A D01-Aug-20215.4 KiB187131

qof-backend.hppH A D01-Aug-202113.2 KiB30058

qof-gobject.hH A D14-Mar-20214.3 KiB9938

qof-string-cache.cppH A D26-Sep-20215 KiB14895

qof-string-cache.hH A D26-Sep-20214.4 KiB11724

qof-win32.cppH A D01-Aug-20213.7 KiB14396

qof.hH A D01-Aug-20212.8 KiB9525

qofbackend.hH A D01-Aug-20217.9 KiB17175

qofbook-p.hH A D14-Mar-20213.5 KiB9222

qofbook.cppH A D26-Sep-202141.9 KiB1,3551,008

qofbook.hH A D11-Sep-202117.8 KiB447123

qofbookslots.hH A D11-Sep-20213.5 KiB9216

qofchoice.cppH A D01-Aug-20213.9 KiB12889

qofchoice.hH A D14-Mar-20216.1 KiB16921

qofclass-p.hH A D14-Mar-20211.9 KiB447

qofclass.cppH A D01-Aug-20218.9 KiB348251

qofclass.hH A D01-Aug-202111.3 KiB28759

qofevent-p.hH A D14-Mar-20211.9 KiB4312

qofevent.cppH A D01-Aug-20216.7 KiB243158

qofevent.hH A D14-Mar-20215.3 KiB14830

qofid-p.hH A D14-Mar-20212.3 KiB6215

qofid.cppH A D01-Aug-20218.6 KiB344266

qofid.hH A D17-Dec-20217.9 KiB22649

qofinstance-p.hH A D14-Mar-20218.4 KiB19269

qofinstance.cppH A D26-Sep-202137 KiB1,3711,095

qofinstance.hH A D14-Mar-20218.3 KiB21264

qoflog.cppH A D26-Sep-202113.9 KiB540426

qoflog.hH A D26-Sep-202110 KiB313126

qofobject-p.hH A D14-Mar-20212.6 KiB7118

qofobject.cppH A D01-Aug-20218.6 KiB359246

qofobject.hH A D01-Aug-20217.1 KiB18147

qofquery-p.hH A D14-Mar-20213.1 KiB7923

qofquery.cppH A D04-Dec-202154.1 KiB1,9531,426

qofquery.hH A D26-Sep-202115.6 KiB39277

qofquerycore-p.hH A D14-Mar-20214.2 KiB15088

qofquerycore.cppH A D04-Dec-202150.8 KiB1,8201,418

qofquerycore.hH A D14-Mar-20217 KiB20786

qofsession.cppH A D01-Aug-202119.5 KiB737554

qofsession.hH A D01-Aug-202113.4 KiB32452

qofsession.hppH A D01-Aug-20214.9 KiB14364

qofutil.cppH A D14-Mar-20217.4 KiB279195

qofutil.hH A D14-Mar-20218.5 KiB272100

README

1
2This directory contains code for the accounting engine.
3Its fairly clean but far from perfect, and it certainly
4lacks advanced features.
5
6There should be no GUI code in this subdirectory, and,
7ideally, it should build cleanly and independently of
8any GUI elements or assumptions.
9
10For design documentation, please see the file "design.txt",
11and also, look at the header files carefully.  The documentation
12for each routine is in the header files for that routine.
13
14September 1998
15

README.query-api

1Gnucash Query API
2
3
4BASIC QUERY API: With this API you can create arbitrary logical
5queries to find sets of splits in an account group.  To make simple
6queries (1 term, such as an account query), create the appropriate
7QueryTerm structure and stick it in a Query object using
8xaccInitQuery. The QueryTerm should be malloced but the Query object
9will handle freeing it.  To make compound queries, make multiple
10simple queries and combine them using xaccMergeQuery and the logical
11operations of your choice.
12
13-----------------------------------------------------------------
14Query * xaccMallocQuery()
15
16Allocates and initializes a Query structure which must be freed by the
17user with xaccFreeQuery.  A newly-allocated Query object matches
18nothing (xaccQueryGetSplits will return NULL).
19
20-----------------------------------------------------------------
21void xaccInitQuery(Query * q, QueryTerm * qt)
22
23Initializes an allocated Query object with initial term qt (possibly
24NULL).  Any previous query terms are freed.
25
26-----------------------------------------------------------------
27void xaccFreeQuery(Query * q)
28
29Frees the resources associate with a Query object.
30
31-----------------------------------------------------------------
32void xaccQuerySetGroup(Query * q, AccountGroup * group)
33
34Set the Gnucash account group that the query applies to.
35xaccQuerySetGroup must be called before a Query object created with
36xaccMallocQuery can be used.  Queries created with xaccQueryInvert and
37xaccQueryMerge inherit the account group of the arguments to those
38functions.
39
40-----------------------------------------------------------------
41Query * xaccQueryInvert(Query * q)
42
43Logically invert the query.  xaccInvertQuery returns a newly allocated
44Query object such that the union of the splits matched by query q and
45query (p = xaccQueryInvert(q)) is the entire account group that q
46applies to.
47
48-----------------------------------------------------------------
49Query * xaccQueryMerge(Query * q1, Query * q2, QueryOp how)
50
51Combine queries q1 and q2 using logical operator 'how'.  'how' must be
52one of QUERY_AND, QUERY_OR, QUERY_NAND, QUERY_NOR, QUERY_XOR.  The
53account groups of q1 and q2 must be the same.  xaccQueryMerge returns
54a newly-allocated Query object or NULL on error.
55
56-----------------------------------------------------------------
57void xaccQueryClear(Query * q)
58
59Remove all query terms from q.  q matches nothing after xaccQueryClear.
60
61-----------------------------------------------------------------
62void xaccQueryPurgeTerms(Query * q, pd_type_t type);
63
64Remove query terms of a particular type from q.  The "type" of a term
65is determined by the type of data that gets passed to the predicate
66function.  The currently-supported values of 'type' are PD_DATE,
67PD_AMOUNT, PD_ACCOUNT, PD_STRING, PD_CLEARED, PD_MISC.  This function
68is really only used in one place: in window-register.c, to modify
69in-place a query to remove any date tests prior to adding new ones.
70This should probably be removed from the API in favor of an extra
71argument to xaccQueryMerge specifying what to do with existing terms
72of that type.
73
74
75-----------------------------------------------------------------
76int xaccQueryHasTerms(Query * q)
77
78Returns the number of terms in the canonical form of the query.  Can
79be used as a predicate to see if the query has been initialized
80(return value > 0) or is "blank" (return value == 0).
81
82
83-----------------------------------------------------------------
84
85CONVENIENCE API: The remainder of the API (in particular, any function
86called xaccQueryAdd***Match) is a set of convenience functions for
87creating and modifying specific types of queries.  All of these
88functions can be duplicated using the Basic API specified above,
89directly manipulating QueryTerm objects and creating and merging
90queries as needed.  One slight advantage of the convenience API is
91that it uses a standard set of predicates that are more-or-less
92opaque.  This may be important later.
93
94It's probably more useful to describe the various types of
95PredicateData than the convenience functions, which are pretty
96self-explanatory once you understand what the underlying process is.
97For example, AddMemoMatch and AddDescriptionMatch are essentially the
98same function because they both use PD_STRING predicate data; they
99just use a different predicate (one compares data.string.matchstring
100with the split's Memo, one compares with the parent transaction's
101Description).
102
103Each function in the convenience API takes a Query *, some arguments
104which fill in the fields of the appropriate PredicateData type, and a
105QueryOp.  The Query object is modified in place, using the logical
106operation specified by the QueryOp to combine a single new QueryTerm
107with the existing Query.  This works by making a new Query of one term
108and combining with the existing Query using xaccQueryMerge and the
109specified QueryOp.  If you have an existing Query (a + b + c) and
110combine using QueryOp QUERY_AND in a convenience function representing
111predicate d, you will get (ad + bd + cd).
112
113
114STRUCTURE OF A QUERY: A Query is a logical function of any number of
115QueryTerms.  A QueryTerm consists of a C function pointer (the
116Predicate) and a PredicateData structure containing data passed to the
117predicate function.  The PredicateData structure is a constant
118associated with the Term and is identical for every Split that is
119tested.
120
121The terms of the Query may represent any logical function and are
122stored in canonical form, i.e. the function is expressed as a logical
123sum of logical products.  So if you have QueryTerms a, b, c, d, e and
124you have the logical function a(b+c) + !(c(d+e)), it gets stored as
125ab + ac + !c + !c!e +!d!c + !d!e.  This may not be optimal for evaluation
126of some functions but it's easy to store, easy to manipulate, and it
127doesn't require a complete algebra system to deal with.
128
129The representation is of a GList of GLists of QueryTerms.  The
130"backbone" GList q->terms represents the OR-chain, and every item on
131the backbone is a GList of QueryTerms representing an AND-chain
132corresponding to a single product-term in the canonical
133representation.  QueryTerms are duplicated when necessary to fill out
134the canonical form, and the same predicate may be evaluated multiple
135times per split for complex queries.  This is a place where we could
136probably optimize.
137
138Evaluation of a Query (see xaccQueryGetSplits) is optimized as much as
139possible by short-circuited evaluation.  The predicates in each
140AND-chain are sorted by predicate type, with Account queries sorted
141first to allow the evaluator to completely eliminate accounts from the
142search if there's no chance of them having splits that match.
143
144
145PREDICATE DATA TYPES: All the predicate data types are rolled up into
146the union type PredicateData.  The "type" field specifies which type
147the union is.  The values of type are:
148
149-----------------------------------------------------------------
150PD_DATE : match a date range.  Specify a start date and an end date.
151
152Used in: xaccQueryAddDateMatch
153         xaccQueryAddDateMatchTT
154
155-----------------------------------------------------------------
156PD_AMOUNT : match a numeric amount.  Specify an amount (always
157positive), a funds-flow direction (credit, debit, or either), and
158"how", specifying the type of amount comparison to be used :
159
160  AMT_MATCH_AT LEAST : split >= pd amount
161  AMT_MATCH_ATMOST  : split >= pd amount
162  AMT_MATCH_EXACTLY : split == pd amount
163
164Used in: xaccQueryAddAmountMatch
165         xaccQueryAddSharePriceMatch
166         xaccQueryAddSharesMatch
167
168-----------------------------------------------------------------
169PD_ACCOUNT : match an account or set of accounts. Specify a set
170of accounts and "how":
171
172  ACCT_MATCH_ALL : a transaction must have at least one split
173                   affecting each account in pd.acct.accounts.
174  ACCT_MATCH_ANY : a transaction must have at least one split
175                   affecting any account in the set
176  ACCT_MATCH_NONE : a transaction may not affect any account in
177                   the set.
178
179Used in: xaccQueryAddAccountMatch
180         xaccQueryAddSingleAccountMatch
181
182-----------------------------------------------------------------
183PD_STRING : match a string.  Specify a string, bool signifying
184case sensitivity, bool signifying regexp or simple string.
185
186Used in: xaccQueryAddDescriptionMatch
187         xaccQueryAddNumberMatch
188         xaccQueryAddActionMatch
189         xaccQueryAddMemoMatch
190
191-----------------------------------------------------------------
192PD_CLEARED : match the Cleared state of the transaction.  Specify
193a bit-mask that is an OR combination of one or more of the
194following:
195  CLEARED_NO         (state == 'n')
196  CLEARED_CLEARED    (state == 'c')
197  CLEARED_RECONCILED (state == 'y')
198
199Used in: xaccQueryAddClearedMatch
200
201-----------------------------------------------------------------
202PD_MISC : match some "other" user predicate. Not used at the moment.
203
204-----------------------------------------------------------------
205