GnuCash c935c2f+
Loading...
Searching...
No Matches
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.
 
bool commit (GncSqlBackend *, QofInstance *) 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 37 of file gnc-commodity-sql.h.

Constructor & Destructor Documentation

◆ GncSqlCommodityBackend()

GncSqlCommodityBackend::GncSqlCommodityBackend ( )

Definition at line 87 of file gnc-commodity-sql.cpp.

87 :
88 GncSqlObjectBackend(TABLE_VERSION, GNC_ID_COMMODITY,
89 COMMODITIES_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 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;
165 gnc_sql_slots_load_for_sql_subquery (sql_be, sql,
166 (BookLookupFn)gnc_commodity_find_commodity_by_guid);
167}
void commodity_for_postload_processing(gnc_commodity *)
Register a commodity to be committed after loading is complete.
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
gnc_commodity * gnc_commodity_table_insert(gnc_commodity_table *table, gnc_commodity *comm)
Add a new commodity to the commodity table.
#define qof_instance_is_dirty
Return value of is_dirty flag.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
The type used to store guids in C.
Definition guid.h:75

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