Encapsulates per-class table schema with functions to load, create a table, commit a changed front-end object (note that database transaction semantics are not yet implemented; edit/commit applies to the front-end object!) and write all front-end objects of the type to the database.
More...
Encapsulates per-class table schema with functions to load, create a table, commit a changed front-end object (note that database transaction semantics are not yet implemented; edit/commit applies to the front-end object!) and write all front-end objects of the type to the database.
Additional functions for creating and running queries existed but were unused and untested. They've been temporarily removed until the front end is ready to use them.
Definition at line 48 of file gnc-sql-object-backend.hpp.
UPDATE/INSERT a single instance of m_type_name into the database.
- Parameters
-
| sql_be | The GncSqlBackend containing the database. |
| inst | The QofInstance to be written out. |
Reimplemented in GncSqlAccountBackend, GncSqlCommodityBackend, GncSqlEmployeeBackend, GncSqlRecurrenceBackend, GncSqlSlotsBackend, GncSqlVendorBackend, GncSqlBudgetBackend, GncSqlInvoiceBackend, GncSqlPriceBackend, GncSqlSchedXactionBackend, GncSqlTaxTableBackend, GncSqlTransBackend, and GncSqlSplitBackend.
Definition at line 33 of file gnc-sql-object-backend.cpp.
34{
36 gboolean is_infant;
37 E_DB_OPERATION op;
38 gboolean is_ok;
39
40 is_infant = qof_instance_get_infant (inst);
42 {
43 op = OP_DB_DELETE;
44 }
45 else if (sql_be->pristine() || is_infant)
46 {
47 op = OP_DB_INSERT;
48 }
49 else
50 {
51 op = OP_DB_UPDATE;
52 }
55
56 if (is_ok)
57 {
58
61 {
62 is_ok = gnc_sql_slots_save (sql_be, guid, is_infant, inst);
63 }
64 else
65 {
66 is_ok = gnc_sql_slots_delete (sql_be, guid);
67 }
68 }
69
70 return is_ok;
71}
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.
The type used to store guids in C.
| void GncSqlObjectBackend::create_tables |
( |
GncSqlBackend * |
sql_be | ) |
|
|
virtual |
Conditionally create or update a database table from m_col_table.
The condition is the version returned by querying the database's version table: If it's 0 then the table wasn't found and will be created; All tables areat least version 1. If the database's version is less than the compiled version then the table schema is upgraded but the data isn't, that's the engine's responsibility when the object is loaded. If the version is greater than the compiled version then nothing is touched.
- Parameters
-
Reimplemented in GncSqlBillTermBackend, GncSqlBudgetBackend, GncSqlCustomerBackend, GncSqlEmployeeBackend, GncSqlEntryBackend, GncSqlInvoiceBackend, GncSqlLotsBackend, GncSqlPriceBackend, GncSqlRecurrenceBackend, GncSqlSlotsBackend, GncSqlTaxTableBackend, GncSqlTransBackend, and GncSqlSplitBackend.
Definition at line 74 of file gnc-sql-object-backend.cpp.
75{
76 g_return_if_fail (sql_be != nullptr);
78 if (version == 0)
79 {
82 }
83 else if (version != m_version)
84 PERR(
"Version mismatch in table %s, expecting %d but backend is %d."
85 "Table creation aborted.", m_table_name.c_str(), m_version, version);
86}
uint_t get_table_version(const std::string &table_name) const noexcept
Returns the version number for a DB table.
bool create_table(const std::string &table_name, const EntryVec &col_table) const noexcept
Creates a table in the database.
bool set_table_version(const std::string &table_name, uint_t version) noexcept
Registers the version for a table.
#define PERR(format, args...)
Log a serious error.