GnuCash  5.6-150-g038405b370+
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. More...
 
bool commit (GncSqlBackend *sql_be, QofInstance *inst) override
 UPDATE/INSERT a single instance of m_type_name into the database. More...
 
- 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. More...
 
virtual bool write (GncSqlBackend *sql_be)
 Write all objects of m_type_name to the database. More...
 
const char * type () const noexcept
 Return the m_type_name for the class. More...
 
const bool is_version (int version) const noexcept
 Compare a version with the compiled version (m_version). More...
 
bool instance_in_db (const GncSqlBackend *sql_be, QofInstance *inst) const noexcept
 Check the presence of an object in the backend's database. More...
 

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.

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);
167  if (qof_instance_get_destroying (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.
GList * gnc_sx_get_schedule(const SchedXaction *sx)
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.
gboolean gnc_sql_slots_save(GncSqlBackend *sql_be, const GncGUID *guid, gboolean is_infant, QofInstance *inst)
gnc_sql_slots_save - Saves slots for an object to the db.
gboolean gnc_sql_slots_delete(GncSqlBackend *sql_be, const GncGUID *guid)
gnc_sql_slots_delete - Deletes slots for an object from the db.
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;
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.
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...

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