38#if defined( S_SPLINT_S )
39#include "splint-defs.h"
42#include "gnc-sql-connection.hpp"
43#include "gnc-sql-backend.hpp"
44#include "gnc-sql-object-backend.hpp"
45#include "gnc-sql-column-table-entry.hpp"
50#define BOOK_TABLE "books"
51#define TABLE_VERSION 1
53G_GNUC_UNUSED
static QofLogModule log_module = G_LOG_DOMAIN;
55static gpointer get_root_account_guid (gpointer pObject);
56static void set_root_account_guid (gpointer pObject, gpointer pValue);
57static gpointer get_root_template_guid (gpointer pObject);
58static void set_root_template_guid (gpointer pObject, gpointer pValue);
60static const EntryVec col_table
62 gnc_sql_make_table_entry<CT_GUID>(
63 "guid", 0, COL_NNUL | COL_PKEY,
"guid"),
64 gnc_sql_make_table_entry<CT_GUID>(
"root_account_guid", 0, COL_NNUL,
66 set_root_account_guid),
67 gnc_sql_make_table_entry<CT_GUID>(
"root_template_guid", 0, COL_NNUL,
69 set_root_template_guid)
72GncSqlBookBackend::GncSqlBookBackend() :
74 BOOK_TABLE, col_table) {}
78get_root_account_guid (gpointer pObject)
80 QofBook* book = QOF_BOOK (pObject);
83 g_return_val_if_fail (pObject != NULL, NULL);
84 g_return_val_if_fail (QOF_IS_BOOK (pObject), NULL);
86 root = gnc_book_get_root_account (book);
91set_root_account_guid (gpointer pObject, gpointer pValue)
93 QofBook* book = QOF_BOOK (pObject);
97 g_return_if_fail (pObject != NULL);
98 g_return_if_fail (QOF_IS_BOOK (pObject));
99 g_return_if_fail (pValue != NULL);
101 root = gnc_book_get_root_account (book);
102 qof_instance_set_guid (QOF_INSTANCE (root), guid);
106get_root_template_guid (gpointer pObject)
108 const QofBook* book = QOF_BOOK (pObject);
111 g_return_val_if_fail (pObject != NULL, NULL);
112 g_return_val_if_fail (QOF_IS_BOOK (pObject), NULL);
119set_root_template_guid (gpointer pObject, gpointer pValue)
121 QofBook* book = QOF_BOOK (pObject);
125 g_return_if_fail (pObject != NULL);
126 g_return_if_fail (QOF_IS_BOOK (pObject));
127 g_return_if_fail (pValue != NULL);
136 gnc_book_set_template_root (book, root);
138 qof_instance_set_guid (QOF_INSTANCE (root), guid);
147 g_return_if_fail (sql_be != NULL);
149 gnc_sql_load_guid (sql_be, row);
151 pBook = sql_be->book();
157 qof_book_begin_edit (pBook);
158 gnc_sql_load_object (sql_be, row, GNC_ID_BOOK, pBook, col_table);
159 gnc_sql_slots_load (sql_be, QOF_INSTANCE (pBook));
160 qof_book_commit_edit (pBook);
162 qof_instance_mark_clean (QOF_INSTANCE (pBook));
168 g_return_if_fail (sql_be != NULL);
170 std::stringstream sql;
171 sql <<
"SELECT * FROM " << BOOK_TABLE;
172 auto stmt = sql_be->create_statement_from_sql(sql.str());
176 auto row = result->begin();
181 if (row == result->end())
183 sql_be->set_loading(
false);
184 commit (sql_be, QOF_INSTANCE (sql_be->book()));
185 sql_be->set_loading(
true);
190 load_single_book (sql_be, *row);
Anchor Scheduled Transaction info in a book.
Main SQL backend structure.
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
void load_all(GncSqlBackend *) override
Load all objects of m_type in the database into memory.
Encapsulates per-class table schema with functions to load, create a table, commit a changed front-en...
virtual bool commit(GncSqlBackend *sql_be, QofInstance *inst)
UPDATE/INSERT a single instance of m_type_name into the database.
Row of SQL Query results.
load and save data to SQL
All type declarations for the whole Gnucash engine.
load and save accounts data to SQL
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
void xaccAccountSetType(Account *acc, GNCAccountType tip)
Set the account's type.
Account * xaccMallocAccount(QofBook *book)
Constructor.
QofBook * qof_book_new(void)
Allocate, initialise and return a new QofBook.
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
Account * gnc_book_get_template_root(const QofBook *book)
Returns the template group from the book.
The type used to store guids in C.