GnuCash de0bfde+
Loading...
Searching...
No Matches
GncSqlSlotsBackend Class Reference

Slots are neither loadable nor committable. More...

#include <gnc-slots-sql.h>

Inheritance diagram for GncSqlSlotsBackend:
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 *, QofInstance *) override
 UPDATE/INSERT a single instance of m_type_name into 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

Slots are neither loadable nor committable.

Note that the default write() implementation is also a no-op.

Definition at line 41 of file gnc-slots-sql.h.

Constructor & Destructor Documentation

◆ GncSqlSlotsBackend()

GncSqlSlotsBackend::GncSqlSlotsBackend ( )

Definition at line 181 of file gnc-slots-sql.cpp.

181 :
182 GncSqlObjectBackend(TABLE_VERSION, GNC_ID_ACCOUNT,
183 TABLE_NAME, col_table) {}

Member Function Documentation

◆ commit()

bool GncSqlSlotsBackend::commit ( GncSqlBackend * sql_be,
QofInstance * inst )
inlineoverridevirtual

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 47 of file gnc-slots-sql.h.

47{ return false; }

◆ create_tables()

void GncSqlSlotsBackend::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 834 of file gnc-slots-sql.cpp.

835{
836 gint version;
837 gboolean ok;
838
839 g_return_if_fail (sql_be != NULL);
840
841 version = sql_be->get_table_version( TABLE_NAME);
842 if (version == 0)
843 {
844 (void)sql_be->create_table(TABLE_NAME, TABLE_VERSION, col_table);
845
846 ok = sql_be->create_index ("slots_guid_index", TABLE_NAME,
847 obj_guid_col_table);
848 if (!ok)
849 {
850 PERR ("Unable to create index\n");
851 }
852 }
853 else if (version < m_version)
854 {
855 /* Upgrade:
856 1->2: 64-bit int values to proper definition, add index
857 2->3: Add gdate field
858 3->4: Use DATETIME instead of TIMESTAMP in MySQL
859 */
860 if (version == 1)
861 {
862 sql_be->upgrade_table(TABLE_NAME, col_table);
863 ok = sql_be->create_index ("slots_guid_index", TABLE_NAME,
864 obj_guid_col_table);
865 if (!ok)
866 {
867 PERR ("Unable to create index\n");
868 }
869 }
870 else if (version == 2)
871 {
872 ok = sql_be->add_columns_to_table(TABLE_NAME, gdate_col_table);
873 if (!ok)
874 {
875 PERR ("Unable to add gdate column\n");
876 }
877 }
878 else
879 {
880 sql_be->upgrade_table(TABLE_NAME, col_table);
881 }
882 sql_be->set_table_version (TABLE_NAME, TABLE_VERSION);
883 PINFO ("Slots table upgraded from version %d to version %d\n", version,
884 TABLE_VERSION);
885 }
886}
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 add_columns_to_table(const std::string &table_name, const EntryVec &col_table) const noexcept
Adds one or more columns to an existing table.
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.
#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 GncSqlSlotsBackend::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 45 of file gnc-slots-sql.h.

45{ return; }

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