GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions
GncSqlVendorBackend Class Reference
Inheritance diagram for GncSqlVendorBackend:
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.
 
bool write (GncSqlBackend *) override
 Write all objects of m_type_name to 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.
 
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-vendor-sql.h.

Constructor & Destructor Documentation

◆ GncSqlVendorBackend()

GncSqlVendorBackend::GncSqlVendorBackend ( )

Definition at line 82 of file gnc-vendor-sql.cpp.

82 :
83 GncSqlObjectBackend(TABLE_VERSION, GNC_ID_VENDOR,
84 TABLE_NAME, col_table) {}
Encapsulates per-class table schema with functions to load, create a table, commit a changed front-en...

Member Function Documentation

◆ commit()

bool GncSqlVendorBackend::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 134 of file gnc-vendor-sql.cpp.

135{
136 GncVendor* v;
137 const GncGUID* guid;
138 E_DB_OPERATION op;
139 gboolean is_infant;
140 gboolean is_ok = TRUE;
141
142 g_return_val_if_fail (inst != NULL, FALSE);
143 g_return_val_if_fail (GNC_IS_VENDOR (inst), FALSE);
144 g_return_val_if_fail (sql_be != NULL, FALSE);
145
146 v = GNC_VENDOR (inst);
147
148 is_infant = qof_instance_get_infant (inst);
150 {
151 op = OP_DB_DELETE;
152 }
153 else if (sql_be->pristine() || is_infant)
154 {
155 op = OP_DB_INSERT;
156 }
157 else
158 {
159 op = OP_DB_UPDATE;
160 }
161 if (op != OP_DB_DELETE)
162 {
163 // Ensure the commodity is in the db
164 is_ok = sql_be->save_commodity (gncVendorGetCurrency(v));
165 }
166 if (is_ok)
167 {
168 is_ok = sql_be->do_db_operation(op, TABLE_NAME, GNC_ID_VENDOR, v,
169 col_table);
170 }
171
172 if (is_ok)
173 {
174 // Now, commit or delete any slots
175 guid = qof_instance_get_guid (inst);
176 if (!qof_instance_get_destroying (inst))
177 {
178 is_ok = gnc_sql_slots_save (sql_be, guid, is_infant, inst);
179 }
180 else
181 {
182 is_ok = gnc_sql_slots_delete (sql_be, guid);
183 }
184 }
185
186 return is_ok;
187}
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.
bool save_commodity(gnc_commodity *comm) noexcept
Ensure that a commodity referenced in another object is in fact saved in 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.
The type used to store guids in C.
Definition guid.h:75

◆ load_all()

void GncSqlVendorBackend::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 114 of file gnc-vendor-sql.cpp.

115{
116 g_return_if_fail (sql_be != NULL);
117
118 std::string sql("SELECT * FROM " TABLE_NAME);
119 auto stmt = sql_be->create_statement_from_sql(sql);
120 auto result = sql_be->execute_select_statement(stmt);
121
122 for (auto row : *result)
123 load_single_vendor (sql_be, row);
124
125 std::string pkey(col_table[0]->name());
126 sql = "SELECT DISTINCT ";
127 sql += pkey + " FROM " TABLE_NAME;
128 gnc_sql_slots_load_for_sql_subquery (sql_be, sql,
129 (BookLookupFn)gnc_vendor_lookup);
130}
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.

◆ write()

bool GncSqlVendorBackend::write ( GncSqlBackend sql_be)
overridevirtual

Write all objects of m_type_name to the database.

Parameters
sql_beThe GncSqlBackend containing the database.
Returns
true if the objects were successfully written, false otherwise.

Reimplemented from GncSqlObjectBackend.

Definition at line 223 of file gnc-vendor-sql.cpp.

224{
225 g_return_val_if_fail (sql_be != NULL, FALSE);
226 write_objects_t data{sql_be, true, this};
227
228 qof_object_foreach (GNC_ID_VENDOR, sql_be->book(), write_single_vendor, &data);
229
230 return data.is_ok;
231}
void qof_object_foreach(QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
Invoke the callback 'cb' on every instance ov a particular object type.
Data-passing struct for callbacks to qof_object_foreach() used in GncSqlObjectBackend::write().

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