GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions
GncSqlSplitBackend Class Reference
Inheritance diagram for GncSqlSplitBackend:
GncSqlObjectBackend

Public Member Functions

void load_all (GncSqlBackend *) override
 Load all objects of m_type in the database into memory.
 
void create_tables (GncSqlBackend *) override
 Conditionally create or update a database table from m_col_table.
 
bool commit (GncSqlBackend *sql_be, QofInstance *inst) override
 Commits a split to the database.
 
- Public Member Functions inherited from GncSqlObjectBackend
 GncSqlObjectBackend (int version, const std::string &type, const std::string &table, const EntryVec &vec)
 
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 45 of file gnc-transaction-sql.h.

Constructor & Destructor Documentation

◆ GncSqlSplitBackend()

GncSqlSplitBackend::GncSqlSplitBackend ( )

Definition at line 146 of file gnc-transaction-sql.cpp.

146 :
147 GncSqlObjectBackend(SPLIT_TABLE_VERSION, GNC_ID_SPLIT,
148 SPLIT_TABLE, split_col_table) {}
Encapsulates per-class table schema with functions to load, create a table, commit a changed front-en...

Member Function Documentation

◆ commit()

bool GncSqlSplitBackend::commit ( GncSqlBackend sql_be,
QofInstance inst 
)
overridevirtual

Commits a split to the database.

Parameters
sql_beSQL backend
instSplit
Returns
TRUE if successful, FALSE if error

Reimplemented from GncSqlObjectBackend.

Definition at line 542 of file gnc-transaction-sql.cpp.

543{
544 E_DB_OPERATION op;
545 gboolean is_infant;
546 gboolean is_ok;
547 GncGUID* guid = (GncGUID*)qof_instance_get_guid (inst);
548
549 g_return_val_if_fail (inst != NULL, FALSE);
550 g_return_val_if_fail (sql_be != NULL, FALSE);
551
552 is_infant = qof_instance_get_infant (inst);
554 {
555 op = OP_DB_DELETE;
556 }
557 else if (sql_be->pristine() || is_infant)
558 {
559 op = OP_DB_INSERT;
560 }
561 else
562 {
563 op = OP_DB_UPDATE;
564 }
565
566 if (guid_equal (guid, guid_null ()))
567 {
568 *guid = guid_new_return ();
569 qof_instance_set_guid (inst, guid);
570 }
571
572 is_ok = sql_be->do_db_operation(op, SPLIT_TABLE, GNC_ID_SPLIT,
573 inst, split_col_table);
574
575 if (is_ok && !qof_instance_get_destroying (inst))
576 {
577 is_ok = gnc_sql_slots_save (sql_be, guid, is_infant, inst);
578 }
579
580 return is_ok;
581}
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 * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
Definition guid.cpp:165
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Given two GUIDs, return TRUE if they are non-NULL and equal.
Definition guid.cpp:237
GncGUID guid_new_return(void)
Generate a new id.
Definition guid.cpp:193
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

◆ create_tables()

void GncSqlSplitBackend::create_tables ( GncSqlBackend sql_be)
overridevirtual

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
sql_beThe GncSqlBackend containing the database connection.

Reimplemented from GncSqlObjectBackend.

Definition at line 442 of file gnc-transaction-sql.cpp.

443{
444 g_return_if_fail (sql_be != nullptr);
445
446 auto version = sql_be->get_table_version( m_table_name.c_str());
447 if (version == 0)
448 {
449 (void)sql_be->create_table(m_table_name.c_str(),
450 m_version, m_col_table);
451 if (!sql_be->create_index("splits_tx_guid_index",
452 m_table_name.c_str(), tx_guid_col_table))
453 PERR ("Unable to create index\n");
454 if (!sql_be->create_index("splits_account_guid_index",
455 m_table_name.c_str(),
456 account_guid_col_table))
457 PERR ("Unable to create index\n");
458 }
459 else if (version < SPLIT_TABLE_VERSION)
460 {
461
462 /* Upgrade:
463 1->2: 64 bit int handling
464 3->4: Split reconcile date can be NULL
465 4->5: Use DATETIME instead of TIMESTAMP in MySQL
466 */
467 sql_be->upgrade_table(m_table_name.c_str(), split_col_table);
468 if (!sql_be->create_index("splits_tx_guid_index",
469 m_table_name.c_str(),
470 tx_guid_col_table))
471 PERR ("Unable to create index\n");
472 if (!sql_be->create_index("splits_account_guid_index",
473 m_table_name.c_str(),
474 account_guid_col_table))
475 PERR ("Unable to create index\n");
476 sql_be->set_table_version (m_table_name.c_str(), m_version);
477 PINFO ("Splits table upgraded from version %d to version %d\n", version,
478 m_version);
479 }
480}
uint_t get_table_version(const std::string &table_name) const noexcept
Returns the version number for a DB table.
bool create_index(const std::string &index_name, const std::string &table_name, const EntryVec &col_table) const noexcept
Creates an index in the database.
bool create_table(const std::string &table_name, const EntryVec &col_table) const noexcept
Creates a table in the database.
void upgrade_table(const std::string &table_name, const EntryVec &col_table) noexcept
Upgrades a table to a new structure.
bool set_table_version(const std::string &table_name, uint_t version) noexcept
Registers the version for a table.
const EntryVec & m_col_table
The front-end QofIdType.
#define PINFO(format, args...)
Print an informational note.
Definition qoflog.h:256
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244

◆ load_all()

void GncSqlSplitBackend::load_all ( GncSqlBackend sql_be)
inlineoverridevirtual

Load all objects of m_type in the database into memory.

Parameters
sql_beThe GncSqlBackend containing the database connection.

Implements GncSqlObjectBackend.

Definition at line 49 of file gnc-transaction-sql.h.

49{ return; } // loaded by transaction.

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