GnuCash de0bfde+
Loading...
Searching...
No Matches
GncSqlSchedXactionBackend Class Reference
Inheritance diagram for GncSqlSchedXactionBackend:
GncSqlObjectBackend

Public Member Functions

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.
Public Member Functions inherited from GncSqlObjectBackend
 GncSqlObjectBackend (int version, const std::string &type, const std::string &table, const EntryVec &vec)
virtual void create_tables (GncSqlBackend *sql_be)
 Conditionally create or update a database table from m_col_table.
virtual bool write (GncSqlBackend *sql_be)
 Write all objects of m_type_name to the database.
const char * type () const noexcept
 Return the m_type_name for the class.
const bool is_version (int version) const noexcept
 Compare a version with the compiled version (m_version).
bool instance_in_db (const GncSqlBackend *sql_be, QofInstance *inst) const noexcept
 Check the presence of an object in the backend's database.

Additional Inherited Members

Protected Attributes inherited from GncSqlObjectBackend
const std::string m_table_name
const int m_version
const std::string m_type_name
const EntryVec & m_col_table
 The front-end QofIdType.

Detailed Description

Definition at line 35 of file gnc-schedxaction-sql.h.

Constructor & Destructor Documentation

◆ GncSqlSchedXactionBackend()

GncSqlSchedXactionBackend::GncSqlSchedXactionBackend ( )

Definition at line 84 of file gnc-schedxaction-sql.cpp.

84 :
85 GncSqlObjectBackend(TABLE_VERSION, GNC_ID_SCHEDXACTION,
86 SCHEDXACTION_TABLE, col_table) {}

Member Function Documentation

◆ commit()

bool GncSqlSchedXactionBackend::commit ( GncSqlBackend * sql_be,
QofInstance * inst )
overridevirtual

UPDATE/INSERT a single instance of m_type_name into the database.

Parameters
sql_beThe GncSqlBackend containing the database.
instThe QofInstance to be written out.

Reimplemented from GncSqlObjectBackend.

Definition at line 149 of file gnc-schedxaction-sql.cpp.

150{
151 SchedXaction* pSx;
152 const GncGUID* guid;
153 E_DB_OPERATION op;
154 gboolean is_infant;
155 gboolean is_ok;
156
157 g_return_val_if_fail (sql_be != NULL, FALSE);
158 g_return_val_if_fail (inst != NULL, FALSE);
159 g_return_val_if_fail (GNC_IS_SX (inst), FALSE);
160
161 pSx = GNC_SX (inst);
162
163 is_infant = qof_instance_get_infant (inst);
165 {
166 op = OP_DB_DELETE;
167 }
168 else if (sql_be->pristine() || is_infant)
169 {
170 op = OP_DB_INSERT;
171 }
172 else
173 {
174 op = OP_DB_UPDATE;
175 }
176 is_ok = sql_be->do_db_operation(op, SCHEDXACTION_TABLE, GNC_SX_ID, pSx,
177 col_table);
178 guid = qof_instance_get_guid (inst);
179 if (op == OP_DB_INSERT || op == OP_DB_UPDATE)
180 {
181 gnc_sql_recurrence_save_list (sql_be, guid, gnc_sx_get_schedule (pSx));
182 }
183 else
184 {
185 gnc_sql_recurrence_delete (sql_be, guid);
186 }
187
188 if (is_ok)
189 {
190 // Now, commit any slots
191 if (op == OP_DB_INSERT || op == OP_DB_UPDATE)
192 {
193 is_ok = gnc_sql_slots_save (sql_be, guid, is_infant, inst);
194 }
195 else
196 {
197 is_ok = gnc_sql_slots_delete (sql_be, guid);
198 }
199 }
200
201 return is_ok;
202}
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.
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.
GList * gnc_sx_get_schedule(const SchedXaction *sx)

◆ load_all()

void GncSqlSchedXactionBackend::load_all ( GncSqlBackend * sql_be)
overridevirtual

Load all objects of m_type in the database into memory.

Parameters
sql_beThe GncSqlBackend containing the database connection.

Implements GncSqlObjectBackend.

Definition at line 120 of file gnc-schedxaction-sql.cpp.

121{
122 g_return_if_fail (sql_be != NULL);
123
124 std::string sql("SELECT * FROM " SCHEDXACTION_TABLE);
125 auto stmt = sql_be->create_statement_from_sql(sql);
126 if (stmt == nullptr) return;
127 auto result = sql_be->execute_select_statement(stmt);
128 SchedXactions* sxes;
129 sxes = gnc_book_get_schedxactions (sql_be->book());
130
131 for (auto row : *result)
132 {
133 SchedXaction* sx;
134
135 sx = load_single_sx (sql_be, row);
136 if (sx != nullptr)
137 gnc_sxes_add_sx (sxes, sx);
138 }
139 std::string pkey(col_table[0]->name());
140 sql = "SELECT DISTINCT ";
141 sql += pkey + " FROM " SCHEDXACTION_TABLE;
142 gnc_sql_slots_load_for_sql_subquery (sql_be, sql,
143 (BookLookupFn)gnc_sx_lookup);
144}
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.

The documentation for this class was generated from the following files: