GDA: Question about some engine transaction functions
Phil Longstaff
plongstaff at rogers.com
Mon Mar 31 09:59:33 EDT 2008
Derek Atkins wrote:
> Phil Longstaff <plongstaff at rogers.com> writes:
>
>> src/engine/Transaction.c has the following functions:
>>
>> static void
>> qofTransSetNum (Transaction *trans, const char *xnum)
>> {
>> if (!qof_begin_edit(&trans->inst)) return;
>> xaccTransSetNum(trans, xnum);
>> qof_commit_edit(&trans->inst);
>> }
>>
>> void
>> xaccTransSetNum (Transaction *trans, const char *xnum)
>> {
>> if (!trans || !xnum) return;
>> xaccTransBeginEdit(trans);
>>
>> CACHE_REPLACE(trans->num, xnum);
>> qof_instance_set_dirty(QOF_INSTANCE(trans));
>> mark_trans(trans); /* Dirty balance of every account in trans */
>> xaccTransCommitEdit(trans);
>> }
>>
>>
>> qofTransSetNum() is the function which is registered with qof, and if
>> there is a function registered with qof, the gda backend tries to use
>> it. The problem is that if the editlevel is not 0 (which it is, because
>> the gda backend calls xaccTransBeginEdit() before the tx is loaded from
>> the db and xaccTransCommitEdit() after it is loaded), qof_begin_edit()
>> will return FALSE so that the routine does nothing, but does leave the
>> editlevel incremented.
>>
>> Is this correct behaviour? If so, it is not useful to me. Note that
>> there are a number of these pairs of routine in Transaction.c and there
>> may be more in other files.
>
> I have no idea why qofTransSetNum() exists. That logic certainly
> looks wrong to me. Even worse, the qof version will crash if you
> pass in a NULL trans! Eww.
Actually, I think qof_begin_edit() will return FALSE if passed NULL, so
it won't crash.
Well, for now, I will use xaccTransSetNum(). I guess a project needs to
be launched to look into these functions.
Phil
More information about the gnucash-devel
mailing list