GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions
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) {}
Encapsulates per-class table schema with functions to load, create a table, commit a changed front-en...

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 152 of file gnc-schedxaction-sql.cpp.

153{
154 SchedXaction* pSx;
155 const GncGUID* guid;
156 E_DB_OPERATION op;
157 gboolean is_infant;
158 gboolean is_ok;
159
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);
163
164 pSx = GNC_SX (inst);
165
166 is_infant = qof_instance_get_infant (inst);
168 {
169 op = OP_DB_DELETE;
170 }
171 else if (sql_be->pristine() || is_infant)
172 {
173 op = OP_DB_INSERT;
174 }
175 else
176 {
177 op = OP_DB_UPDATE;
178 }
179 is_ok = sql_be->do_db_operation(op, SCHEDXACTION_TABLE, GNC_SX_ID, pSx,
180 col_table);
181 guid = qof_instance_get_guid (inst);
182 if (op == OP_DB_INSERT || op == OP_DB_UPDATE)
183 {
184 gnc_sql_recurrence_save_list (sql_be, guid, gnc_sx_get_schedule (pSx));
185 }
186 else
187 {
188 gnc_sql_recurrence_delete (sql_be, guid);
189 }
190
191 if (is_ok)
192 {
193 // Now, commit any slots
194 if (op == OP_DB_INSERT || op == OP_DB_UPDATE)
195 {
196 is_ok = gnc_sql_slots_save (sql_be, guid, is_infant, inst);
197 }
198 else
199 {
200 is_ok = gnc_sql_slots_delete (sql_be, guid);
201 }
202 }
203
204 return is_ok;
205}
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)
The type used to store guids in C.
Definition guid.h:75

◆ 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 123 of file gnc-schedxaction-sql.cpp.

124{
125 g_return_if_fail (sql_be != NULL);
126
127 std::string sql("SELECT * FROM " SCHEDXACTION_TABLE);
128 auto stmt = sql_be->create_statement_from_sql(sql);
129 if (stmt == nullptr) return;
130 auto result = sql_be->execute_select_statement(stmt);
131 SchedXactions* sxes;
132 sxes = gnc_book_get_schedxactions (sql_be->book());
133
134 for (auto row : *result)
135 {
136 SchedXaction* sx;
137
138 sx = load_single_sx (sql_be, row);
139 if (sx != nullptr)
140 gnc_sxes_add_sx (sxes, sx);
141 }
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);
147}
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: