Add code to extract the date terms from a query.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/gnucash-gnome2-dev@9438 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton
2003-10-01 02:26:47 +00:00
parent c39422f275
commit c8ec96cdf2
6 changed files with 82 additions and 0 deletions

View File

@@ -395,6 +395,32 @@ xaccQueryAddDateMatchTS (Query * q,
qof_query_destroy (tmp_q);
}
void
xaccQueryGetDateMatchTS (Query * q,
Timespec * sts,
Timespec * ets)
{
QofQueryPredData *term_data;
GSList *param_list;
GSList *terms, *tmp;
sts->tv_sec = sts->tv_nsec = 0;
ets->tv_sec = ets->tv_nsec = 0;
param_list = qof_query_build_param_list (SPLIT_TRANS, TRANS_DATE_POSTED, NULL);
terms = qof_query_get_term_type (q, param_list);
g_slist_free(param_list);
for (tmp = terms; tmp; tmp = g_slist_next(tmp)) {
term_data = tmp->data;
if (term_data->how == QOF_COMPARE_GTE)
qof_query_date_predicate_get_date(term_data, sts);
if (term_data->how == QOF_COMPARE_LTE)
qof_query_date_predicate_get_date(term_data, ets);
}
g_slist_free(terms);
}
/********************************************************************
* xaccQueryAddDateMatch
* Add a date filter to an existing query.
@@ -442,6 +468,20 @@ xaccQueryAddDateMatchTT(Query * q,
}
void
xaccQueryGetDateMatchTT (Query * q,
time_t * stt,
time_t * ett)
{
Timespec sts;
Timespec ets;
xaccQueryGetDateMatchTS (q, &sts, &ets);
*stt = sts.tv_sec;
*ett = ets.tv_sec;
}
void
xaccQueryAddClearedMatch(Query * q, cleared_match_t how, QofQueryOp op)
{

View File

@@ -188,6 +188,13 @@ void xaccQueryAddDateMatchTT(Query * q,
int use_start, time_t stt,
int use_end, time_t ett,
QofQueryOp op);
void xaccQueryGetDateMatchTS (Query * q,
Timespec * sts,
Timespec * ets);
void xaccQueryGetDateMatchTT (Query * q,
time_t * stt,
time_t * ett);
typedef enum {
CLEARED_NONE = 0x0000,
CLEARED_NO = 0x0001,

View File

@@ -893,6 +893,26 @@ gboolean qof_query_has_term_type (QofQuery *q, GSList *term_param)
return FALSE;
}
GSList * qof_query_get_term_type (QofQuery *q, GSList *term_param)
{
GList *or;
GList *and;
GSList *results = NULL;
if (!q || !term_param)
return FALSE;
for(or = q->terms; or; or = or->next) {
for(and = or->data; and; and = and->next) {
QofQueryTerm *qt = and->data;
if (!param_list_cmp (term_param, qt->param_list))
results = g_slist_append(results, qt->pdata);
}
}
return results;
}
void qof_query_destroy (QofQuery *q)
{
if (!q) return;

View File

@@ -152,6 +152,7 @@ int qof_query_has_terms (QofQuery *q);
int qof_query_num_terms (QofQuery *q);
gboolean qof_query_has_term_type (QofQuery *q, GSList *term_param);
GSList * qof_query_get_term_type (QofQuery *q, GSList *term_param);
QofQuery * qof_query_copy (QofQuery *q);
QofQuery * qof_query_invert(QofQuery *q);

View File

@@ -372,6 +372,17 @@ qof_query_date_predicate (QofQueryCompare how,
return ((QofQueryPredData*)pdata);
}
gboolean
qof_query_date_predicate_get_date (QofQueryPredData *pd, Timespec *date)
{
query_date_t pdata = (query_date_t)pd;
if (pdata->pd.type_name != query_date_type)
return FALSE;
*date = pdata->date;
return TRUE;
}
static char * date_to_string (gpointer object, QofAccessFunc get)
{
Timespec ts = ((query_date_getter)get)(object);

View File

@@ -144,6 +144,9 @@ QofQueryPredData *qof_query_core_predicate_copy (QofQueryPredData *pdata);
/** Destroy a predicate. */
void qof_query_core_predicate_free (QofQueryPredData *pdata);
/** Retrieve a predicate. */
gboolean qof_query_date_predicate_get_date (QofQueryPredData *data, Timespec *date);
/** Return a printable string for a core data object. Caller needs
* to g_free() the returned string.
*/