access_method and new, empty, sessions.

Derek Atkins warlord at MIT.EDU
Wed Feb 16 19:40:05 EST 2005

Neil Williams <linux at> writes:

> On Wednesday 16 February 2005 9:30 pm, Derek Atkins wrote:
>> > I'm now trying to see how it can work when qof_session_new() and
>> > qof_session_begin() are called where no content exists, i.e. new, empty,
>> > sessions.
>> You mean what to do when we use File -> Save As?
> Yes, as well as Report->Export data, or any other situation where certain 
> entities from an existing book are to be saved / exported.

Uh, Report->Export exports the HTML results of the report...  I don't think
QSF applies in that case.

> It's tied in with those qof_entity_copy routines - a regular GnuCash book 
> can't save a QofBook that doesn't follow the AccountGroup hierarchy, so if 
> this isn't a complete file, just a selection of entities, the user should 
> expect that a suitable format is used.


> I'd rather that each of the qof_entity_copy functions (and anything else) that 
> create partial books are not forever tied to a specific backend.

Agreed.  They shouldn't need to be tied to a specific backend.

> I'd prefer a general usage function in qof_session.c that allows a different 
> way of selecting amongst the existing file:/ backends - bearing in mind the 
> two systems too, gnc_mod and load_library.

Yea..  Not sure the best way to handle that.

>> Where are the cases when 
>> this is an issue?  AFAICT it's only an "issue" during File -> New File
>> or when you run (effectively) gnucash --nofile.  At that point the
>> user clicking on "save" is effectively calling Save As.
> At present, qof_session_save doesn't do that, it simply calls whatever backend 
> was selected by qof_session_begin which in turn relies on the access_method.

Oh?  So File -> New File does... what?  There's no backend associated
with it.  Simiarly File -> Save As, what does that do?

> How would qof_session_save determine the nature of the contents of the 
> QofBook? (without converting the entire book to each format in turn so that 
> the existing file_type routines could be used!)
> What about if the qof_entity_copy routines put a flag in qof_book_set_data() 
> that can also be set by any other routines that will result in partial books?

That's probably a good idea, so you keep track of full books
v. partial books.  We know that the gnucash file backends (xmlv1,
xmlv2, and sqlite) will all be full books, but qsf is not guaranteed
to be a full book.  So you should treat them as such.  Partial books
cannot be "loaded", only "merged".

"Save" isn't as much of an issue -- you can "save" only into the
gnucash formats, and only from full books.  You can "export" partial
data, and only into qsf.  The only exception to this would be the
(eventual) export gnc-xml, but I suppose that could just be a Save As

> save could then use that to destroy the old backend, create a new one and 
> execute the save?

Hmm.. Maybe..

> If the flag had different values for QSF and SQLite, qof_session_save could 
> know how to find the _new() routines for the required backend.
> Maybe an enum?

No, enums are bad..  Not pluggable.  Use a glist or hash table.

> qof_book_set_data(book, "partial_status", partial_book);


> Maybe the results of partial_book in a switch could call a specific backend 
> using prov->description?
> switch (partial_book) {
>  case QSF : 
>  if(0 == safe_strcmp("QSF Backend Version 0.1", prov->description)) {
>   if (NULL == prov->backend_new) continue;
>  }
>  break;
> (the default would be gnc-backend-v2)

Well, until the default is sqlite ;)

> Only if changing the backend would cause problems for a live book - after data 
> had been added or modified.
> Can you see any problems with changing the backend of a book in use?

"Save As" does it..

> OK, that'll be file:// too, so that would use the same system - if we choose 
> to use a flag in the book data that is set by any routines that require a 
> certain file backend?
> Make it part of the API - if you create a QofBook that cannot or should not be 
> saved by the default GnuCash-xml-v2 file backend, specify the type of backend 
> in the book data . . . 

Could be...  We definitely need to keep track of whether a book is a
Full Book or a Partial Book and act accordingly.

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

More information about the gnucash-devel mailing list