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"
50static QofLogModule log_module = G_LOG_DOMAIN;
52#define TABLE_NAME "lots"
53#define TABLE_VERSION 2
55static gpointer get_lot_account (gpointer pObject);
56static void set_lot_account (gpointer pObject, gpointer pValue);
58static const EntryVec col_table
60 gnc_sql_make_table_entry<CT_GUID>(
"guid", 0, COL_NNUL | COL_PKEY,
"guid"),
61 gnc_sql_make_table_entry<CT_ACCOUNTREF>(
"account_guid", 0, 0,
64 gnc_sql_make_table_entry<CT_BOOLEAN>(
"is_closed", 0, COL_NNUL,
"is-closed")
67GncSqlLotsBackend::GncSqlLotsBackend() :
69 TABLE_NAME, col_table) {}
73get_lot_account (gpointer pObject)
78 g_return_val_if_fail (pObject != NULL, NULL);
79 g_return_val_if_fail (GNC_IS_LOT (pObject), NULL);
81 lot = GNC_LOT (pObject);
87set_lot_account (gpointer pObject, gpointer pValue)
92 g_return_if_fail (pObject != NULL && GNC_IS_LOT (pObject));
93 g_return_if_fail (pValue == NULL || GNC_IS_ACCOUNT (pValue));
95 lot = GNC_LOT (pObject);
96 pAccount = GNC_ACCOUNT (pValue);
108 g_return_val_if_fail (sql_be != NULL, NULL);
110 lot = gnc_lot_new (sql_be->book());
112 gnc_lot_begin_edit (lot);
113 gnc_sql_load_object (sql_be, row, GNC_ID_LOT, lot, col_table);
114 gnc_lot_commit_edit (lot);
122 g_return_if_fail (sql_be != NULL);
124 std::stringstream sql;
125 sql <<
"SELECT * FROM " << TABLE_NAME;
126 auto stmt = sql_be->create_statement_from_sql(sql.str());
130 if (result->begin () ==
nullptr)
132 for (
auto row : *result)
133 load_single_lot (sql_be, row);
135 auto sql = g_strdup_printf (
"SELECT DISTINCT guid FROM %s",
137 gnc_sql_slots_load_for_sql_subquery (sql_be, sql, (BookLookupFn)gnc_lot_lookup);
148 g_return_if_fail (sql_be != NULL);
154 (void)sql_be->
create_table(TABLE_NAME, TABLE_VERSION, col_table);
156 else if (version < m_version)
167 PINFO (
"Lots table upgraded from version 1 to version %d\n", TABLE_VERSION);
185 g_return_val_if_fail (sql_be != NULL, FALSE);
198 gpointer pObject)
const noexcept
200 load_from_guid_ref(row, obj_name, pObject,
202 return gnc_lot_lookup(g, sql_be->book());
209 add_objectref_guid_to_table(vec);
214 const gpointer pObject,
215 PairVec& vec)
const noexcept
217 add_objectref_guid_to_query(obj_name, pObject, vec);
Account handling public routines.
Main SQL backend structure.
uint_t get_table_version(const std::string &table_name) const noexcept
Returns the version number for a DB table.
bool create_table(const std::string &table_name, const EntryVec &col_table) const noexcept
Creates a table in the database.
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
void upgrade_table(const std::string &table_name, const EntryVec &col_table) noexcept
Upgrades a table to a new structure.
bool set_table_version(const std::string &table_name, uint_t version) noexcept
Registers the version for a table.
void add_to_query(QofIdTypeConst obj_name, void *pObject, PairVec &vec) const noexcept override
Add a pair of the table column heading and object's value's string representation to a PairVec; used ...
void add_to_table(ColVec &vec) const noexcept override
Add a GncSqlColumnInfo structure for the column type to a ColVec.
void load(const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, void *pObject) const noexcept override
Load a value into an object from the database row.
void create_tables(GncSqlBackend *) override
Conditionally create or update a database table from m_col_table.
bool write(GncSqlBackend *) override
Write all objects of m_type_name to the database.
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...
Row of SQL Query results.
load and save data to SQL
load and save accounts data to SQL
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
void xaccAccountInsertLot(Account *acc, GNCLot *lot)
The xaccAccountInsertLot() method will register the indicated lot with this account.
void(* QofInstanceForeachCB)(QofInstance *, gpointer user_data)
Callback type for qof_collection_foreach.
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
#define PINFO(format, args...)
Print an informational note.
Account * gnc_lot_get_account(const GNCLot *lot)
Returns the account with which this lot is associated.
The type used to store guids in C.
Data-passing struct for callbacks to qof_object_foreach() used in GncSqlObjectBackend::write().