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 539 of file gnc-transaction-sql.cpp.

540 {
541  E_DB_OPERATION op;
542  gboolean is_infant;
543  gboolean is_ok;
544  GncGUID* guid = (GncGUID*)qof_instance_get_guid (inst);
545 
546  g_return_val_if_fail (inst != NULL, FALSE);
547  g_return_val_if_fail (sql_be != NULL, FALSE);
548 
549  is_infant = qof_instance_get_infant (inst);
550  if (qof_instance_get_destroying (inst))
551  {
552  op = OP_DB_DELETE;
553  }
554  else if (sql_be->pristine() || is_infant)
555  {
556  op = OP_DB_INSERT;
557  }
558  else
559  {
560  op = OP_DB_UPDATE;
561  }
562 
563  if (guid_equal (guid, guid_null ()))
564  {
565  *guid = guid_new_return ();
566  qof_instance_set_guid (inst, guid);
567  }
568 
569  is_ok = sql_be->do_db_operation(op, SPLIT_TABLE, GNC_ID_SPLIT,
570  inst, split_col_table);
571 
572  if (is_ok && !qof_instance_get_destroying (inst))
573  {
574  is_ok = gnc_sql_slots_save (sql_be, guid, is_infant, inst);
575  }
576 
577  return is_ok;
578 }
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 439 of file gnc-transaction-sql.cpp.

440 {
441  g_return_if_fail (sql_be != nullptr);
442 
443  auto version = sql_be->get_table_version( m_table_name.c_str());
444  if (version == 0)
445  {
446  (void)sql_be->create_table(m_table_name.c_str(),
447  m_version, m_col_table);
448  if (!sql_be->create_index("splits_tx_guid_index",
449  m_table_name.c_str(), tx_guid_col_table))
450  PERR ("Unable to create index\n");
451  if (!sql_be->create_index("splits_account_guid_index",
452  m_table_name.c_str(),
453  account_guid_col_table))
454  PERR ("Unable to create index\n");
455  }
456  else if (version < SPLIT_TABLE_VERSION)
457  {
458 
459  /* Upgrade:
460  1->2: 64 bit int handling
461  3->4: Split reconcile date can be NULL
462  4->5: Use DATETIME instead of TIMESTAMP in MySQL
463  */
464  sql_be->upgrade_table(m_table_name.c_str(), split_col_table);
465  if (!sql_be->create_index("splits_tx_guid_index",
466  m_table_name.c_str(),
467  tx_guid_col_table))
468  PERR ("Unable to create index\n");
469  if (!sql_be->create_index("splits_account_guid_index",
470  m_table_name.c_str(),
471  account_guid_col_table))
472  PERR ("Unable to create index\n");
473  sql_be->set_table_version (m_table_name.c_str(), m_version);
474  PINFO ("Splits table upgraded from version %d to version %d\n", version,
475  m_version);
476  }
477 }
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: