How to remove all txns from an Account?

Charles Day cedayiv at gmail.com
Tue Apr 15 15:29:54 EDT 2008


On Tue, Apr 15, 2008 at 11:32 AM, Charles Day <cedayiv at gmail.com> wrote:

> On Tue, Apr 15, 2008 at 10:56 AM, Derek Atkins <warlord at mit.edu> wrote:
>
> > Hi,
> >
> > I think the real question is.. What EXACTLY are you trying to do?
> >
>
> I'm trying to fix bug 512208. Right now, if the user cancels a QIF import,
> the imported account tree is not destroyed.  To fix this, upon cancellation
> I want to first remove all transactions from the imported account tree. This
> removes all their splits too and, crucially, avoids the possibility of
> leaving splits in an Imbalance account in the existing GnuCash account tree.
> After that, I'll need to remove the imported accounts themselves and any new
> commodities created by the importer (both easy).
>
>
> > What I would do:
> >
> >  xaccAccountTreeForEachTransaction(acc, get_txn_list_cb, &txn_list);
> >  foreach (txn_list)
> >     delete txn.
> >
>
> I'm wondering why xaccAccountTreeForEachTransaction() doesn't build that
> list of transactions on its own, before calling the provided callback
> function. Instead, it walks through the list of each account's splits and
> assumes that the list element it is it working on doesn't disappear out from
> under it (which it does, if the callback deletes the split, resulting in a
> crash).
>

Crashing is also a possibility if the callback function reassigns the split
to a different account.


> -Charles
>
> But I don't know why you'd ever want to do this.
> >
> > -derek
> >
> > "Charles Day" <cedayiv at gmail.com> writes:
> >
> > > What is the proper way to destroy all transactions that involve a
> > particular
> > > account?
> > >
> > > I tried using xaccAccountTreeForEachTransaction(), but that uses
> > > xaccAccountStagedTransactionTraversal() which has a limitation in that
> > it
> > > assumes that no splits are being removed from the account. Is this
> > > limitation intentional?
> > >
> > > So for example, the following code doesn't work and actually can cause
> > > crashes:
> > >
> > > /* Remove all the transactions in this account and its descendants. */
> > > xaccAccountTreeForEachTransaction(acc, remove_transaction_cb, NULL);
> > >
> > > ---where remove_transaction_cb is defined as the following---
> > >
> > > static gint
> > > remove_transaction_cb(Transaction * trans, void * data)
> > > {
> > >   /* Destroy the transaction. */
> > >   xaccTransDestroy(trans);
> > >
> > >   return 0;
> > > }
> > >
> > > Cheers,
> > > Charles
> > > _______________________________________________
> > > 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