mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Add explicit types to GUID queries.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5862 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
@@ -803,10 +803,18 @@ sqlQuery_build (sqlQuery *sq, Query *q, GNCSession *session)
|
||||
break;
|
||||
|
||||
case PR_GUID:
|
||||
if (!guid_equal (&pd->guid.guid, xaccGUIDNULL ()))
|
||||
switch (pd->guid.id_type)
|
||||
{
|
||||
need_account = TRUE;
|
||||
need_entry = TRUE;
|
||||
case GNC_ID_ACCOUNT:
|
||||
need_account = TRUE;
|
||||
break;
|
||||
|
||||
case GNC_ID_SPLIT:
|
||||
need_entry = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1046,25 +1054,31 @@ sqlQuery_build (sqlQuery *sq, Query *q, GNCSession *session)
|
||||
|
||||
sq->pq = stpcpy (sq->pq, " (");
|
||||
|
||||
if (guid_equal (&pd->guid.guid, xaccGUIDNULL ()))
|
||||
switch (pd->guid.id_type)
|
||||
{
|
||||
sq->pq = stpcpy(sq->pq, "FALSE ");
|
||||
}
|
||||
else
|
||||
{
|
||||
sq->pq = stpcpy(sq->pq, "gncAccount.accountGuid = '");
|
||||
sq->pq = guid_to_string_buff (&pd->guid.guid, sq->pq);
|
||||
sq->pq = stpcpy(sq->pq, "' ");
|
||||
sq->pq = stpcpy(sq->pq, " OR ");
|
||||
default:
|
||||
case GNC_ID_NULL:
|
||||
case GNC_ID_NONE:
|
||||
sq->pq = stpcpy(sq->pq, "FALSE ");
|
||||
break;
|
||||
|
||||
sq->pq = stpcpy(sq->pq, "gncTransaction.transGuid = '");
|
||||
sq->pq = guid_to_string_buff (&pd->guid.guid, sq->pq);
|
||||
sq->pq = stpcpy(sq->pq, "' ");
|
||||
sq->pq = stpcpy(sq->pq, " OR ");
|
||||
case GNC_ID_ACCOUNT:
|
||||
sq->pq = stpcpy(sq->pq, "gncAccount.accountGuid = '");
|
||||
sq->pq = guid_to_string_buff (&pd->guid.guid, sq->pq);
|
||||
sq->pq = stpcpy(sq->pq, "' ");
|
||||
break;
|
||||
|
||||
sq->pq = stpcpy(sq->pq, "gncEntry.entryGuid = '");
|
||||
sq->pq = guid_to_string_buff (&pd->guid.guid, sq->pq);
|
||||
sq->pq = stpcpy(sq->pq, "' ");
|
||||
case GNC_ID_TRANS:
|
||||
sq->pq = stpcpy(sq->pq, "gncTransaction.transGuid = '");
|
||||
sq->pq = guid_to_string_buff (&pd->guid.guid, sq->pq);
|
||||
sq->pq = stpcpy(sq->pq, "' ");
|
||||
break;
|
||||
|
||||
case GNC_ID_SPLIT:
|
||||
sq->pq = stpcpy(sq->pq, "gncEntry.entryGuid = '");
|
||||
sq->pq = guid_to_string_buff (&pd->guid.guid, sq->pq);
|
||||
sq->pq = stpcpy(sq->pq, "' ");
|
||||
break;
|
||||
}
|
||||
|
||||
sq->pq = stpcpy (sq->pq, ") ");
|
||||
|
||||
@@ -196,7 +196,8 @@ xaccQueryPrint(Query * q)
|
||||
char buff[40];
|
||||
printf ("guid sense=%d\n", qt->data.guid.sense);
|
||||
guid_to_string_buff (&qt->data.guid.guid, buff);
|
||||
printf ("\tguid %s\n", buff);
|
||||
printf ("\tguid=%s\n", buff);
|
||||
printf ("\tid type=%d\n", qt->data.guid.id_type);
|
||||
break;
|
||||
}
|
||||
case PR_KVP: {
|
||||
@@ -1425,6 +1426,8 @@ xaccQueryTermEqual (QueryTerm *qt1, QueryTerm *qt2)
|
||||
case PD_GUID:
|
||||
if (!guid_equal (&qt1->data.guid.guid, &qt2->data.guid.guid))
|
||||
return FALSE;
|
||||
if (qt1->data.guid.id_type != qt2->data.guid.id_type)
|
||||
return FALSE;
|
||||
break;
|
||||
|
||||
case PD_KVP: {
|
||||
@@ -2206,7 +2209,8 @@ xaccQueryAddBalanceMatch(Query * q, balance_match_t how, QueryOp op)
|
||||
********************************************************************/
|
||||
|
||||
void
|
||||
xaccQueryAddGUIDMatch(Query * q, const GUID *guid, QueryOp op)
|
||||
xaccQueryAddGUIDMatch(Query * q, const GUID *guid,
|
||||
GNCIdType id_type, QueryOp op)
|
||||
{
|
||||
Query * qs = xaccMallocQuery();
|
||||
QueryTerm * qt = g_new0(QueryTerm, 1);
|
||||
@@ -2217,6 +2221,7 @@ xaccQueryAddGUIDMatch(Query * q, const GUID *guid, QueryOp op)
|
||||
qt->data.base.term_type = PR_GUID;
|
||||
qt->data.base.sense = 1;
|
||||
qt->data.guid.guid = guid ? *guid : *xaccGUIDNULL ();
|
||||
qt->data.guid.id_type = id_type;
|
||||
|
||||
xaccInitQuery(qs, qt);
|
||||
xaccQuerySetGroup(qs, q->acct_group);
|
||||
@@ -2473,7 +2478,7 @@ xaccGUIDMatchPredicate(Split * s, PredicateData * pd)
|
||||
|
||||
guid = &pd->guid.guid;
|
||||
|
||||
switch (xaccGUIDTypeEntityTable (guid, s->entity_table))
|
||||
switch (pd->guid.id_type)
|
||||
{
|
||||
case GNC_ID_NONE:
|
||||
case GNC_ID_NULL:
|
||||
|
||||
@@ -213,6 +213,7 @@ typedef struct {
|
||||
pr_type_t term_type;
|
||||
int sense;
|
||||
GUID guid;
|
||||
GNCIdType id_type;
|
||||
} GUIDPredicateData;
|
||||
|
||||
typedef struct {
|
||||
@@ -333,7 +334,8 @@ void xaccQueryAddMemoMatch(Query * q, const char * matchstring,
|
||||
int case_sens, int use_regexp, QueryOp op);
|
||||
void xaccQueryAddClearedMatch(Query * q, cleared_match_t how, QueryOp op);
|
||||
void xaccQueryAddBalanceMatch(Query * q, balance_match_t how, QueryOp op);
|
||||
void xaccQueryAddGUIDMatch(Query * q, const GUID *guid, QueryOp op);
|
||||
void xaccQueryAddGUIDMatch(Query * q, const GUID *guid,
|
||||
GNCIdType id_type, QueryOp op);
|
||||
/* given kvp value is on right side of comparison */
|
||||
void xaccQueryAddKVPMatch(Query *q, GSList *path, const kvp_value *value,
|
||||
kvp_match_t how, kvp_match_where_t where,
|
||||
|
||||
@@ -23,20 +23,20 @@
|
||||
\********************************************************************/
|
||||
|
||||
#include "config.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-numeric.h"
|
||||
#include "gnc-book.h"
|
||||
|
||||
#include <g-wrap-runtime-guile.h>
|
||||
#include <libguile.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "Backend.h"
|
||||
#include "Query.h"
|
||||
#include "date.h"
|
||||
#include "engine-helpers.h"
|
||||
#include "glib-helpers.h"
|
||||
|
||||
#include <libguile.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <g-wrap-runtime-guile.h>
|
||||
#include "gnc-book.h"
|
||||
#include "gnc-engine-util.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-numeric.h"
|
||||
|
||||
gnc_commodity_table *
|
||||
gnc_engine_commodity_table_new (void)
|
||||
@@ -327,6 +327,18 @@ gnc_scm2sort_type (SCM sort_type_scm)
|
||||
return gnc_gw_enum_scm2val ("<gnc:sort-type>", sort_type_scm);
|
||||
}
|
||||
|
||||
static SCM
|
||||
gnc_id_type2scm (GNCIdType id_type)
|
||||
{
|
||||
return gnc_gw_enum_val2scm ("<gnc:id-type>", id_type);
|
||||
}
|
||||
|
||||
static GNCIdType
|
||||
gnc_scm2id_type (SCM id_type_scm)
|
||||
{
|
||||
return gnc_gw_enum_scm2val ("<gnc:id-type>", id_type_scm);
|
||||
}
|
||||
|
||||
static SCM
|
||||
gnc_bitfield2scm (const char *typestr, int value)
|
||||
{
|
||||
@@ -833,6 +845,7 @@ gnc_queryterm2scm (QueryTerm *qt)
|
||||
|
||||
case PD_GUID:
|
||||
qt_scm = gh_cons (gnc_guid2scm (qt->data.guid.guid), qt_scm);
|
||||
qt_scm = gh_cons (gnc_id_type2scm (qt->data.guid.id_type), qt_scm);
|
||||
break;
|
||||
|
||||
case PD_KVP:
|
||||
@@ -1138,6 +1151,7 @@ gnc_scm2query_term_query (SCM query_term_scm)
|
||||
case PD_GUID:
|
||||
{
|
||||
GUID guid;
|
||||
GNCIdType id_type;
|
||||
|
||||
/* guid */
|
||||
if (gh_null_p (query_term_scm))
|
||||
@@ -1148,7 +1162,14 @@ gnc_scm2query_term_query (SCM query_term_scm)
|
||||
|
||||
guid = gnc_scm2guid (scm);
|
||||
|
||||
xaccQueryAddGUIDMatch (q, &guid, QUERY_OR);
|
||||
/* id type */
|
||||
|
||||
scm = gh_car (query_term_scm);
|
||||
query_term_scm = gh_cdr (query_term_scm);
|
||||
|
||||
id_type = gnc_scm2id_type (scm);
|
||||
|
||||
xaccQueryAddGUIDMatch (q, &guid, id_type, QUERY_OR);
|
||||
}
|
||||
|
||||
ok = TRUE;
|
||||
|
||||
@@ -352,6 +352,17 @@
|
||||
(gw:wrap-non-native-type mod '<gnc:QueryTerm*>
|
||||
"QueryTerm *" "const QueryTerm *")
|
||||
|
||||
(let ((wt (gw:wrap-enumeration mod '<gnc:id-type>
|
||||
"GNCIdType" "const GNCIdType")))
|
||||
(gw:enum-add-value! wt "GNC_ID_NONE" 'gnc-id-none)
|
||||
(gw:enum-add-value! wt "GNC_ID_NULL" 'gnc-id-null)
|
||||
(gw:enum-add-value! wt "GNC_ID_ACCOUNT" 'gnc-id-account)
|
||||
(gw:enum-add-value! wt "GNC_ID_TRANS" 'gnc-id-trans)
|
||||
(gw:enum-add-value! wt "GNC_ID_SPLIT" 'gnc-id-split)
|
||||
(gw:enum-add-value! wt "GNC_ID_PRICE" 'gnc-id-price)
|
||||
(gw:enum-add-value! wt "GNC_ID_SCHEDXACTION" 'gnc-id-sched-xaction)
|
||||
(gw:enum-add-value! wt "GNC_ID_FREQSPEC" 'gnc-id-freq-spec))
|
||||
|
||||
(let ((wt (gw:wrap-enumeration mod '<gnc:query-op>
|
||||
"QueryOp" "const QueryOp")))
|
||||
(gw:enum-add-value! wt "QUERY_AND" 'query-and)
|
||||
|
||||
@@ -1219,6 +1219,12 @@ free_random_kvp_path (GSList *path)
|
||||
g_slist_free (path);
|
||||
}
|
||||
|
||||
static GNCIdType
|
||||
get_random_id_type (void)
|
||||
{
|
||||
return get_random_int_in_range (0, LAST_GNC_ID);
|
||||
}
|
||||
|
||||
Query *
|
||||
get_random_query(void)
|
||||
{
|
||||
@@ -1318,7 +1324,10 @@ get_random_query(void)
|
||||
|
||||
case PR_GUID:
|
||||
guid = get_random_guid ();
|
||||
xaccQueryAddGUIDMatch (q, guid, get_random_queryop ());
|
||||
xaccQueryAddGUIDMatch (q,
|
||||
guid,
|
||||
get_random_id_type (),
|
||||
get_random_queryop ());
|
||||
g_free (guid);
|
||||
break;
|
||||
|
||||
@@ -1645,9 +1654,14 @@ make_trans_query (Transaction *trans, TestQueryTypes query_types)
|
||||
|
||||
if (query_types & GUID_QT)
|
||||
{
|
||||
xaccQueryAddGUIDMatch (q, xaccSplitGetGUID (s), QUERY_AND);
|
||||
xaccQueryAddGUIDMatch (q, xaccTransGetGUID (trans), QUERY_AND);
|
||||
xaccQueryAddGUIDMatch (q, xaccAccountGetGUID (a), QUERY_AND);
|
||||
xaccQueryAddGUIDMatch (q, xaccSplitGetGUID (s),
|
||||
GNC_ID_SPLIT, QUERY_AND);
|
||||
|
||||
xaccQueryAddGUIDMatch (q, xaccTransGetGUID (trans),
|
||||
GNC_ID_TRANS, QUERY_AND);
|
||||
|
||||
xaccQueryAddGUIDMatch (q, xaccAccountGetGUID (a),
|
||||
GNC_ID_ACCOUNT, QUERY_AND);
|
||||
}
|
||||
|
||||
if (query_types & SPLIT_KVP_QT)
|
||||
|
||||
@@ -26,10 +26,9 @@ TESTS = \
|
||||
test-query \
|
||||
test-resolve-file-path \
|
||||
test-split-vs-account \
|
||||
test-transaction-voiding
|
||||
|
||||
# test-freq-spec
|
||||
# test-scm-query
|
||||
test-transaction-voiding \
|
||||
test-freq-spec \
|
||||
test-scm-query
|
||||
|
||||
TESTS_ENVIRONMENT = \
|
||||
GNC_MODULE_PATH="${top_srcdir}/src/engine" \
|
||||
|
||||
@@ -886,6 +886,7 @@ process_auto_create_list( GList *autoCreateList, sxSinceLastData *sxsld )
|
||||
(thisGUID = thisGUID->next) ) {
|
||||
xaccQueryAddGUIDMatch( sxsld->autoCreateQuery,
|
||||
(GUID*)thisGUID->data,
|
||||
GNC_ID_TRANS,
|
||||
QUERY_OR );
|
||||
}
|
||||
g_list_free( createdGUIDs );
|
||||
@@ -897,9 +898,9 @@ process_auto_create_list( GList *autoCreateList, sxSinceLastData *sxsld )
|
||||
}
|
||||
gnc_resume_gui_refresh();
|
||||
|
||||
gnc_ledger_display_set_query( sxsld->ac_ledger, sxsld->autoCreateQuery );
|
||||
gnc_ledger_display_set_query( sxsld->ac_ledger,
|
||||
sxsld->autoCreateQuery );
|
||||
gnc_ledger_display_refresh( sxsld->ac_ledger );
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
@@ -3339,7 +3339,8 @@ invoiceTransCB (GtkWidget *widget, gpointer data)
|
||||
|
||||
xaccQuerySetGroup (query, gnc_get_current_group ());
|
||||
|
||||
xaccQueryAddGUIDMatch (query, xaccSplitGetGUID (split), QUERY_AND);
|
||||
xaccQueryAddGUIDMatch (query, xaccSplitGetGUID (split),
|
||||
GNC_ID_SPLIT, QUERY_AND);
|
||||
|
||||
report_helper (regData, func, query);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user