GnuCash  5.6-150-g038405b370+
Public Member Functions
GncSqlBookBackend Class Reference
Inheritance diagram for GncSqlBookBackend:
GncSqlObjectBackend

Public Member Functions

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

Member Function Documentation

◆ load_all()

void GncSqlBookBackend::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 166 of file gnc-book-sql.cpp.

167 {
168  g_return_if_fail (sql_be != NULL);
169 
170  std::stringstream sql;
171  sql << "SELECT * FROM " << BOOK_TABLE;
172  auto stmt = sql_be->create_statement_from_sql(sql.str());
173  if (stmt != nullptr)
174  {
175  auto result = sql_be->execute_select_statement(stmt);
176  auto row = result->begin();
177 
178  /* If there are no rows, try committing the book; unset
179  * loading so that it will actually get saved.
180  */
181  if (row == result->end())
182  {
183  sql_be->set_loading(false);
184  commit (sql_be, QOF_INSTANCE (sql_be->book()));
185  sql_be->set_loading(true);
186  }
187  else
188  {
189  // Otherwise, load the 1st book.
190  load_single_book (sql_be, *row);
191  }
192  }
193 }
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
virtual bool commit(GncSqlBackend *sql_be, QofInstance *inst)
UPDATE/INSERT a single instance of m_type_name into the database.

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