GnuCash  5.6-150-g038405b370+
Public Member Functions
GncSqlCommodityBackend Class Reference
Inheritance diagram for GncSqlCommodityBackend:
GncSqlObjectBackend

Public Member Functions

void load_all (GncSqlBackend *) override
 Load all objects of m_type in the database into memory. More...
 
bool commit (GncSqlBackend *, QofInstance *) 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 37 of file gnc-commodity-sql.h.

Member Function Documentation

◆ commit()

bool GncSqlCommodityBackend::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 212 of file gnc-commodity-sql.cpp.

213 {
214  g_return_val_if_fail (sql_be != NULL, FALSE);
215  g_return_val_if_fail (inst != NULL, FALSE);
216  g_return_val_if_fail (GNC_IS_COMMODITY (inst), FALSE);
217  auto in_be = instance_in_db(sql_be, inst);
218  return do_commit_commodity (sql_be, inst, !in_be);
219 }
bool instance_in_db(const GncSqlBackend *sql_be, QofInstance *inst) const noexcept
Check the presence of an object in the backend's database.

◆ load_all()

void GncSqlCommodityBackend::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 137 of file gnc-commodity-sql.cpp.

138 {
139  gnc_commodity_table* pTable;
140 
141  pTable = gnc_commodity_table_get_table (sql_be->book());
142  std::string sql("SELECT * FROM " COMMODITIES_TABLE);
143  auto stmt = sql_be->create_statement_from_sql(sql);
144  auto result = sql_be->execute_select_statement(stmt);
145 
146  for (auto row : *result)
147  {
148  auto pCommodity = load_single_commodity (sql_be, row);
149 
150  if (pCommodity != NULL)
151  {
152  GncGUID guid;
153 
154  guid = *qof_instance_get_guid (QOF_INSTANCE (pCommodity));
155  pCommodity = gnc_commodity_table_insert (pTable, pCommodity);
156  if (qof_instance_is_dirty (QOF_INSTANCE (pCommodity)))
157  sql_be->commodity_for_postload_processing(pCommodity);
158  qof_instance_set_guid (QOF_INSTANCE (pCommodity), &guid);
159  }
160 
161  }
162  std::string pkey(col_table[0]->name());
163  sql = "SELECT DISTINCT ";
164  sql += pkey + " FROM " COMMODITIES_TABLE;
166  (BookLookupFn)gnc_commodity_find_commodity_by_guid);
167 }
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
Add a new commodity to the commodity table.
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
#define qof_instance_is_dirty
Return value of is_dirty flag.
Definition: qofinstance.h:166
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...
void commodity_for_postload_processing(gnc_commodity *)
Register a commodity to be committed after loading is complete.
The type used to store guids in C.
Definition: guid.h:75

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