GnuCash  5.6-150-g038405b370+
Public Member Functions
GncSqlCustomerBackend Class Reference
Inheritance diagram for GncSqlCustomerBackend:
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 write (GncSqlBackend *) override
 Write all objects of m_type_name 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 commit (GncSqlBackend *sql_be, QofInstance *inst)
 UPDATE/INSERT a single instance of m_type_name into 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 35 of file gnc-customer-sql.h.

Member Function Documentation

◆ create_tables()

void GncSqlCustomerBackend::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 146 of file gnc-customer-sql.cpp.

147 {
148  gint version;
149 
150  g_return_if_fail (sql_be != NULL);
151 
152  version = sql_be->get_table_version( TABLE_NAME);
153  if (version == 0)
154  {
155  sql_be->create_table(TABLE_NAME, TABLE_VERSION, col_table);
156  }
157  else if (version < m_version)
158  {
159  /* Upgrade 64 bit int handling */
160  sql_be->upgrade_table(TABLE_NAME, col_table);
161  sql_be->set_table_version (TABLE_NAME, TABLE_VERSION);
162 
163  PINFO ("Customers table upgraded from version 1 to version %d\n",
164  TABLE_VERSION);
165  }
166 }
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 PINFO(format, args...)
Print an informational note.
Definition: qoflog.h:256
void upgrade_table(const std::string &table_name, const EntryVec &col_table) noexcept
Upgrades a table to a new structure.
uint_t get_table_version(const std::string &table_name) const noexcept
Returns the version number for a DB table.

◆ load_all()

void GncSqlCustomerBackend::load_all ( GncSqlBackend sql_be)
overridevirtual

Load all objects of m_type in the database into memory.

Parameters
sql_beThe GncSqlBackend containing the database connection.

Implements GncSqlObjectBackend.

Definition at line 126 of file gnc-customer-sql.cpp.

127 {
128  g_return_if_fail (sql_be != NULL);
129 
130  std::string sql("SELECT * FROM " TABLE_NAME);
131  auto stmt = sql_be->create_statement_from_sql(sql);
132  auto result = sql_be->execute_select_statement(stmt);
133 
134  for (auto row : *result)
135  load_single_customer (sql_be, row);
136 
137  std::string pkey(col_table[0]->name());
138  sql = "SELECT DISTINCT ";
139  sql += pkey + " FROM " TABLE_NAME;
141  (BookLookupFn)gnc_customer_lookup);
142 }
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
void gnc_sql_slots_load_for_sql_subquery(GncSqlBackend *sql_be, const std::string subquery, BookLookupFn lookup_fn)
gnc_sql_slots_load_for_sql_subquery - Loads slots for all objects whose guid is supplied by a subquer...

◆ write()

bool GncSqlCustomerBackend::write ( GncSqlBackend sql_be)
overridevirtual

Write all objects of m_type_name to the database.

Parameters
sql_beThe GncSqlBackend containing the database.
Returns
true if the objects were successfully written, false otherwise.

Reimplemented from GncSqlObjectBackend.

Definition at line 202 of file gnc-customer-sql.cpp.

203 {
204  write_objects_t data;
205 
206  g_return_val_if_fail (sql_be != NULL, FALSE);
207 
208  data.be = sql_be;
209  data.is_ok = TRUE;
210  data.obe = this;
211  qof_object_foreach (GNC_ID_CUSTOMER, sql_be->book(), write_single_customer,
212  (gpointer)&data);
213  return data.is_ok;
214 }
void qof_object_foreach(QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
Invoke the callback &#39;cb&#39; on every instance ov a particular object type.
Definition: qofobject.cpp:185
Data-passing struct for callbacks to qof_object_foreach() used in GncSqlObjectBackend::write().

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