GnuCash  5.6-150-g038405b370+
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. More...
 
void create_tables (GncSqlBackend *) override
 Conditionally create or update a database table from m_col_table. More...
 
bool commit (GncSqlBackend *sql_be, QofInstance *inst) override
 Commits a split to the database. More...
 
- 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. 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 45 of file gnc-transaction-sql.h.

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);
553  if (qof_instance_get_destroying (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 * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
GncGUID guid_new_return(void)
Generate a new id.
Definition: guid.cpp:158
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.
gboolean gnc_sql_slots_save(GncSqlBackend *sql_be, const GncGUID *guid, gboolean is_infant, QofInstance *inst)
gnc_sql_slots_save - Saves slots for an object to the db.
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:204
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
Definition: guid.cpp:130
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 }
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.
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
void upgrade_table(const std::string &table_name, const EntryVec &col_table) noexcept
Upgrades a table to a new structure.
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.
uint_t get_table_version(const std::string &table_name) const noexcept
Returns the version number for a DB table.

◆ 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: