Decouple QofBook creation from QofSession.

So that we don't create two books when loading a session.
Step 1 to not having a dirty book when we think we should have no
book at all.
This commit is contained in:
John Ralls
2018-06-17 16:43:33 -07:00
parent 0a4347bd5e
commit 8ff5af4c19
21 changed files with 146 additions and 145 deletions

View File

@@ -181,7 +181,7 @@ functions. */
%include <policy.h>
%include <gnc-pricedb.h>
QofSession * qof_session_new (void);
QofSession * qof_session_new (QofBook* book);
QofBook * qof_session_get_book (QofSession *session);
// TODO: Unroll/remove
const char *qof_session_get_url (QofSession *session);
@@ -271,6 +271,7 @@ Account * gnc_book_get_template_root(QofBook *book);
%typemap(out) KvpValue * " $result = gnc_kvp_value_ptr_to_scm($1); "
%typemap(in) GSList *key_path " $1 = gnc_scm_to_gslist_string($input);"
QofBook* qof_book_new (void);
void qof_book_options_delete (QofBook *book, GSList *key_path);
void qof_book_set_option (QofBook *book, KvpValue *new_value, GSList *key_path);
KvpValue* qof_book_get_option (QofBook *book, GSList *key_path);

View File

@@ -25,8 +25,7 @@
(define (run-test)
(setenv "GNC_UNINSTALLED" "1")
(let* ((session (qof-session-new))
(book (qof-session-get-book session))
(let* ((book (qof-book-new))
(root (xaccMallocAccount book))
(acct (xaccMallocAccount book)))
(xaccAccountBeginEdit acct)

View File

@@ -224,4 +224,5 @@ char * no_args[1] = { NULL };
gnc_engine_init(0, no_args);
gnc_prefs_init();
%}
//We must explicitly declare this or it gets left out and we can't create books.
QofBook* qof_book_new (void);

View File

@@ -103,7 +103,7 @@ class Session(GnuCashCoreClass):
you don't need to cleanup and call end() and destroy(), that is handled
for you, and the exception is raised.
"""
GnuCashCoreClass.__init__(self, instance=instance)
GnuCashCoreClass.__init__(self, Book())
if book_uri is not None:
try:
self.begin(book_uri, ignore_lock, is_new, force_new)

View File

@@ -24,12 +24,15 @@
int main()
{
const char* testurl = "sqlite3://" TESTFILE;
char * no_args[1] = { NULL };
QofSession* s = NULL;
qof_log_init();
qof_init();
char * no_args[1] = { NULL };
gnc_engine_init(0, no_args);
QofSession * s = qof_session_new();
s = qof_session_new(NULL);
qof_session_begin(s, testurl, 0, 1, 0);
qof_session_load(s, NULL);
qof_session_save(s, NULL);