[GNC-dev] Troubles with a basic API integration

F. Eugene Aumson feaumson at gmail.com
Sun Nov 15 00:58:03 EST 2020


Hi all,

I'd like to follow the example shown at
https://wiki.gnucash.org/wiki/Using_the_API, which demonstrates creating a
transaction.  And I'd like to do it with a freshly-created Postgres backend.

That tutorial starts from a point at which you've already got an `Account`,
and therefore can easily get a `QofBook` from it, which gets passed to
`xaccMallocTransaction()`.  However, I'm having trouble getting that far.

I've got some code put together, which you can see here:
https://github.com/feuGeneA/a-gnucash-integration/pull/2  This email is
largely a copy/paste of the PR description there.  Feel free to reply here,
and/or comment on code directly there, whatever works for you.  For the
sake of completeness, I've attached my source and my debug logs to this
email, but all of that is visible in the PR (source code in the PR itself,
and logs in the CI runs (GitHub Checks)).

Thank you in advance for any feedback!
Gene

-----

I've got the GnuCash engine connecting to Postgres, but I'm not sure what
to do next, and I've got errors:

* One error is coming from the `qof_session_destroy()` routine, and it
doesn't seem to make any sense at all.
    - You can see this error in the output of the `ci/circleci:build` Check
on the commit `Start and stop the engine`.
    - Note the error message `qof session error message: (-484235720).
func: qof_session_destroy`.
        - This is coming from my own routine `qof_error_check()` at
`a-gnucash-integration.cpp:11`, which in this case is being called from
`a-gnucash-integration.cpp:49`.
    - Note that `qof_session_get_error_message(session)` is returning an
empty string, and `qof_session_get_error(session)` is returning a
ridiculous value.
    - Am I using these routines right?
* Another error is coming from my attempt to get the session's book and
seed an `Account` with it.
    - See what I introduced in the commit `Get QofBook and create a root
Account`.
    - Below are the `ERROR` logs are being emitted.  You can see the full
debug log in the `ci/circleci:build` Check on the commit.
```
* 05:37:54 ERROR <gnc.engine> Account* xaccMallocAccount(QofBook*):
assertion 'book' failed
* 05:37:54 ERROR <GLib-GObject> g_type_instance_get_private: assertion
'instance != NULL && instance->g_class != NULL' failed
* 05:37:54 ERROR <gnc.engine> void xaccAccountBeginEdit(Account*):
assertion 'acc' failed
```

It feels like I'm not using these routines properly.  Where am I going
wrong?

Other questions:

* How do i properly do error checking? Is my `qof_error_check()` routine
the right approach? What about for non-`qof_`-prefixed routines, eg
`xaccMallocTransaction()` or `gnc_account_create_root()`?
* When do i need to call `qof_session_save()` or `qof_session_load()`?
* What else should I be aware of as I continue trying to connect the dots
between what I have here and what's shown in the API tutorial?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a-gnucash-integration.cpp
Type: text/x-c++src
Size: 2481 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20201115/d784db72/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qof_session_destroy.log
Type: text/x-log
Size: 2793 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20201115/d784db72/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gnc_create_account_root.log
Type: text/x-log
Size: 2172 bytes
Desc: not available
URL: <http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20201115/d784db72/attachment-0002.bin>


More information about the gnucash-devel mailing list