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" 52 #define TABLE_NAME "lots" 53 #define TABLE_VERSION 2 55 static gpointer get_lot_account (gpointer pObject);
56 static void set_lot_account (gpointer pObject, gpointer pValue);
58 static 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")
67 GncSqlLotsBackend::GncSqlLotsBackend() :
69 TABLE_NAME, col_table) {}
73 get_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);
87 set_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",
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);
bool create_table(const std::string &table_name, const EntryVec &col_table) const noexcept
Creates a table in the database.
bool set_table_version(const std::string &table_name, uint_t version) noexcept
Registers the version for a table.
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
void gnc_sql_slots_load_for_sql_subquery(GncSqlBackend *sql_be, const std::string subquery, BookLookupFn lookup_fn)
gnc_sql_slots_load_for_sql_subquery - Loads slots for all objects whose guid is supplied by a subquer...
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
#define PINFO(format, args...)
Print an informational note.
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
load and save accounts data to SQL
void(* QofInstanceForeachCB)(QofInstance *, gpointer user_data)
Callback type for qof_collection_foreach.
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 xaccAccountInsertLot(Account *acc, GNCLot *lot)
The xaccAccountInsertLot() method will register the indicated lot with this account.
void load_all(GncSqlBackend *) override
Load all objects of m_type in the database into memory.
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.
Account handling public routines.
Row of SQL Query results.
void upgrade_table(const std::string &table_name, const EntryVec &col_table) noexcept
Upgrades a table to a new structure.
load and save data to SQL
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
Encapsulates per-class table schema with functions to load, create a table, commit a changed front-en...
bool write(GncSqlBackend *) override
Write all objects of m_type_name to the database.
Data-passing struct for callbacks to qof_object_foreach() used in GncSqlObjectBackend::write().
void create_tables(GncSqlBackend *) override
Conditionally create or update a database table from m_col_table.
void add_to_table(ColVec &vec) const noexcept override
Add a GncSqlColumnInfo structure for the column type to a ColVec.
QofCollection * qof_book_get_collection(const QofBook *book, QofIdType entity_type)
Return The table of entities of the given type.
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.
uint_t get_table_version(const std::string &table_name) const noexcept
Returns the version number for a DB table.
Main SQL backend structure.