35#include "Recurrence.h"
38#include "splint-defs.h"
41#include "gnc-sql-connection.hpp"
42#include "gnc-sql-backend.hpp"
43#include "gnc-sql-object-backend.hpp"
44#include "gnc-sql-column-table-entry.hpp"
45#include "gnc-schedxaction-sql.h"
51#define SCHEDXACTION_TABLE "schedxactions"
52#define TABLE_VERSION 1
54G_GNUC_UNUSED
static QofLogModule log_module = G_LOG_DOMAIN;
56#define SX_MAX_NAME_LEN 2048
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_STRING>(
"name", SX_MAX_NAME_LEN, 0,
"name"),
62 gnc_sql_make_table_entry<CT_BOOLEAN>(
"enabled", 0, COL_NNUL,
"enabled"),
63 gnc_sql_make_table_entry<CT_GDATE>(
"start_date", 0, 0,
"start-date"),
64 gnc_sql_make_table_entry<CT_GDATE>(
"end_date", 0, 0,
"end-date"),
65 gnc_sql_make_table_entry<CT_GDATE>(
66 "last_occur", 0, 0,
"last-occurance-date"),
67 gnc_sql_make_table_entry<CT_INT>(
68 "num_occur", 0, COL_NNUL,
"num-occurance"),
69 gnc_sql_make_table_entry<CT_INT>(
"rem_occur", 0, COL_NNUL,
"rem-occurance"),
70 gnc_sql_make_table_entry<CT_BOOLEAN>(
71 "auto_create", 0, COL_NNUL,
"auto-create"),
72 gnc_sql_make_table_entry<CT_BOOLEAN>(
73 "auto_notify", 0, COL_NNUL,
"auto-create-notify"),
74 gnc_sql_make_table_entry<CT_INT>(
75 "adv_creation", 0, COL_NNUL,
"advance-creation-days"),
76 gnc_sql_make_table_entry<CT_INT>(
77 "adv_notify", 0, COL_NNUL,
"advance-reminder-days"),
78 gnc_sql_make_table_entry<CT_INT>(
79 "instance_count", 0, COL_NNUL,
"instance-count"),
80 gnc_sql_make_table_entry<CT_ACCOUNTREF>(
81 "template_act_guid", 0, COL_NNUL,
"template-account"),
84GncSqlSchedXactionBackend::GncSqlSchedXactionBackend() :
86 SCHEDXACTION_TABLE, col_table) {}
97 g_return_val_if_fail (sql_be != NULL, NULL);
99 guid = gnc_sql_load_guid (sql_be, row);
100 g_assert (guid != NULL);
103 gnc_sx_begin_edit (pSx);
104 gnc_sql_load_object (sql_be, row, GNC_SX_ID, pSx, col_table);
105 schedule = gnc_sql_recurrence_load_list (sql_be, guid);
107 gnc_sx_commit_edit (pSx);
108 gnc_sql_transaction_load_tx_for_account (sql_be, pSx->template_acct);
110 g_object_get (pSx,
"start-date", &start_date, NULL);
116static inline SchedXaction*
125 g_return_if_fail (sql_be != NULL);
127 std::string sql(
"SELECT * FROM " SCHEDXACTION_TABLE);
128 auto stmt = sql_be->create_statement_from_sql(sql);
129 if (stmt ==
nullptr)
return;
132 sxes = gnc_book_get_schedxactions (sql_be->book());
134 for (
auto row : *result)
138 sx = load_single_sx (sql_be, row);
140 gnc_sxes_add_sx (sxes, sx);
142 std::string pkey(col_table[0]->name());
143 sql =
"SELECT DISTINCT ";
144 sql += pkey +
" FROM " SCHEDXACTION_TABLE;
145 gnc_sql_slots_load_for_sql_subquery (sql_be, sql,
146 (BookLookupFn)gnc_sx_lookup);
160 g_return_val_if_fail (sql_be != NULL, FALSE);
161 g_return_val_if_fail (inst != NULL, FALSE);
162 g_return_val_if_fail (GNC_IS_SX (inst), FALSE);
166 is_infant = qof_instance_get_infant (inst);
171 else if (sql_be->pristine() || is_infant)
179 is_ok = sql_be->
do_db_operation(op, SCHEDXACTION_TABLE, GNC_SX_ID, pSx,
182 if (op == OP_DB_INSERT || op == OP_DB_UPDATE)
188 gnc_sql_recurrence_delete (sql_be, guid);
194 if (op == OP_DB_INSERT || op == OP_DB_UPDATE)
196 is_ok = gnc_sql_slots_save (sql_be, guid, is_infant, inst);
200 is_ok = gnc_sql_slots_delete (sql_be, guid);
Anchor Scheduled Transaction info in a book.
Scheduled Transactions public handling routines.
Main SQL backend structure.
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
bool do_db_operation(E_DB_OPERATION op, const char *table_name, QofIdTypeConst obj_name, gpointer pObject, const EntryVec &table) const noexcept
Performs an operation on the database.
Encapsulates per-class table schema with functions to load, create a table, commit a changed front-en...
Row of SQL Query results.
void load_all(GncSqlBackend *) override
Load all objects of m_type in the database into memory.
bool commit(GncSqlBackend *sql_be, QofInstance *inst) override
UPDATE/INSERT a single instance of m_type_name into the database.
load and save accounts data to SQL
load and save accounts data to SQL
load and save data to SQL
#define QOF_BOOK_RETURN_ENTITY(book, guid, e_type, c_type)
Encapsulates all the information about a dataset manipulated by QOF.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.
void gnc_sx_set_schedule(SchedXaction *sx, GList *schedule)
SchedXaction * xaccSchedXactionMalloc(QofBook *book)
Creates and initializes a scheduled transaction.
GList * gnc_sx_get_schedule(const SchedXaction *sx)
The type used to store guids in C.