is it possible to "refine" an existing QofQuery multiple times?

Derek Atkins warlord at MIT.EDU
Sun Aug 6 10:20:43 EDT 2006


No, there's no way to take the results of a query and run a subquery on it.
HOWEVER, I think adding that functionality might be pretty easy.  We could
add something like:

GList* qof_query_run_subquery(QofQuery* subq, QofQuery* q);

Note that running qof_query_run() on the same query multiple times will
re-iterate over the full book, but you can use qof_query_last_run()
to just return the last set.

I think adding this new API would be relatively simple.
What you've provided below will still iterate multiple times.  Using
this new API you'd do something like:

...
[ setup query ]
...
(void)qof_query_run(stored_query);
...
loop {
  ...
  [ setup subquery ]
  results = qof_query_run_subquery(subq, stored_q);
  ...
}

-derek

Quoting Christian Stimming <stimming at tuhh.de>:

> Just a question about the qofquery.h interface: Is it possible to refine a
> query multiple times?
>
> In the generic importer, for each imported transaction a query is performed
> where the criteria are 1. to match the known import-account, and 2. to match
> a certain date interval. It turned out that each query will internally
> iterate over all splits in the book, not only all splits in the
> import-account, which takes a long long time. Derek told me it's not very
> likely that this would change in soon. So I would like to split this query
> into two parts: First make one query to get all splits belonging to the known
> import-account and store this query (or its result) for the rest of the
> imported transactions. Then, for each additional imported transaction, run
> the query matching on the certain date interval, but run the query only on
> the result of the first query. If this were possible, then I'd get rid of a
> huge performance bottleneck in the generic importer. Here's how I'd imagine
> this to work (in gnc_import_find_split_matches() in import-backend.c):
>
>    Query *stored_query = ...; // from somewhere
>    Account *importaccount =  ...; // from somewhere
>    time_t download_time = ...; // from somewhere
>    Query *query;
>
>    if (stored_query && stored_query_account &&
> 	stored_query_account == importaccount)
>      {
> 	/* Stored query already exists */
>      }
>    else
>      {
> 	/* First run the query only to restrict the set on the account */
>        stored_query = xaccMallocQuery();
> 	xaccQuerySetBook (stored_query, gnc_get_current_book());
> 	xaccQueryAddSingleAccountMatch (stored query, importaccount,
> 					QOF_QUERY_AND);
> 	stored_query_account = importaccount;
>        qof_query_run(stored_query); // or something else here???
>      }
>
>    /* Now refine the stored query.  */
>    query = qof_query_copy(stored_query);
>    // ^^^^ will this avoid iterating over all splits????
>    xaccQueryAddDateMatchTT (query,
> 			     TRUE, download_time - match_date_hardlimit*86400,
> 			     TRUE, download_time + match_date_hardlimit*86400,
> 			     QOF_QUERY_AND);
>    /* Execute final (second) query. */
>    list_element = xaccQueryGetSplits (query);
>
> Any hints? Thanks a lot.
>
> Christian
> _______________________________________________
> gnucash-devel mailing list
> gnucash-devel at gnucash.org
> https://lists.gnucash.org/mailman/listinfo/gnucash-devel
>



-- 
       Derek Atkins, SB '93 MIT EE, SM '95 MIT Media Laboratory
       Member, MIT Student Information Processing Board  (SIPB)
       URL: http://web.mit.edu/warlord/    PP-ASEL-IA     N1NWH
       warlord at MIT.EDU                        PGP key available



More information about the gnucash-devel mailing list