24 #ifndef __GNC_SQL_BACKEND_HPP__ 25 #define __GNC_SQL_BACKEND_HPP__ 34 #include <qof-backend.hpp> 37 using GncSqlColumnTableEntryPtr = std::shared_ptr<GncSqlColumnTableEntry>;
38 using EntryVec = std::vector<GncSqlColumnTableEntryPtr>;
40 using GncSqlObjectBackendPtr = std::shared_ptr<GncSqlObjectBackend>;
41 using OBEEntry = std::tuple<std::string, GncSqlObjectBackendPtr>;
42 using OBEVec = std::vector<OBEEntry>;
45 using GncSqlStatementPtr = std::unique_ptr<GncSqlStatement>;
48 using VersionPair = std::pair<const std::string, unsigned int>;
49 using VersionVec = std::vector<VersionPair>;
50 using uint_t =
unsigned int;
73 void load(QofBook*, QofBackendLoadType)
override;
79 void sync(QofBook*)
override;
113 GncSqlStatementPtr create_statement_from_sql(
const std::string& str)
const noexcept;
122 int execute_nonselect_statement(
const GncSqlStatementPtr& stmt)
const noexcept;
123 std::string quote_string(
const std::string&)
const noexcept;
131 bool create_table(
const std::string& table_name,
const EntryVec& col_table)
const noexcept;
140 bool create_table(
const std::string& table_name,
int table_version,
141 const EntryVec& col_table) noexcept;
156 const std::string& table_name,
157 const EntryVec& col_table)
const noexcept;
166 const EntryVec& col_table)
const noexcept;
179 const EntryVec& col_table) noexcept;
213 const gpointer pObject,
const EntryVec&
table )
const noexcept;
226 const EntryVec&
table)
const noexcept;
235 QofBook* book()
const noexcept {
return m_book; }
236 void set_loading(
bool loading) noexcept {
m_loading = loading; }
238 void update_progress(
double pct)
const noexcept;
239 void finish_progress()
const noexcept;
250 bool write_account_tree(
Account*);
251 bool write_accounts();
252 bool write_transactions();
253 bool write_template_transactions();
254 bool write_schedXactions();
255 GncSqlStatementPtr build_insert_statement (
const char* table_name,
258 const EntryVec&
table)
const noexcept;
259 GncSqlStatementPtr build_update_statement (
const gchar* table_name,
262 const EntryVec&
table)
const noexcept;
263 GncSqlStatementPtr build_delete_statement (
const char* table_name,
266 const EntryVec&
table)
const noexcept;
268 class ObjectBackendRegistry
271 ObjectBackendRegistry();
272 ObjectBackendRegistry(
const ObjectBackendRegistry&) =
delete;
273 ObjectBackendRegistry(
const ObjectBackendRegistry&&) =
delete;
274 ObjectBackendRegistry operator=(
const ObjectBackendRegistry&) =
delete;
275 ObjectBackendRegistry operator=(
const ObjectBackendRegistry&&) =
delete;
276 ~ObjectBackendRegistry() =
default;
281 OBEVec::iterator
begin() {
return m_registry.begin(); }
282 OBEVec::iterator end() {
return m_registry.end(); }
283 OBEVec::size_type size() {
return m_registry.size(); }
287 ObjectBackendRegistry m_backend_registry;
288 std::vector<gnc_commodity*> m_postload_commodities;
291 #endif //__GNC_SQL_BACKEND_HPP__ 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.
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.
bool set_table_version(const std::string &table_name, uint_t version) noexcept
Registers the version for a table.
const char * m_time_format
Server-specific date-time string format.
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
VersionVec m_versions
Version number for each table.
void rollback(QofInstance *) override
Object editing has been cancelled.
void commit(QofInstance *) override
Object editing is complete and the object should be saved.
void create_tables() noexcept
Create/update all tables in the database.
bool m_loading
We are performing an initial load.
void commodity_for_postload_processing(gnc_commodity *)
Register a commodity to be committed after loading is complete.
GncSqlConnection * m_conn
SQL connection.
void load(QofBook *, QofBackendLoadType) override
Load the contents of an SQL database into a book.
void sync(QofBook *) override
Save the contents of a book to an SQL database.
bool object_in_db(const char *table_name, QofIdTypeConst obj_name, const gpointer pObject, const EntryVec &table) const noexcept
Checks whether an object is in the database or not.
Account handling public routines.
bool m_in_query
We are processing a query.
bool save_commodity(gnc_commodity *comm) noexcept
Ensure that a commodity referenced in another object is in fact saved in the database.
static bool register_backend(const char *, const char *)
Class methods for dynamically loading the several backends and for freeing them at shutdown...
void upgrade_table(const std::string &table_name, const EntryVec &col_table) noexcept
Upgrades a table to a new structure.
QofBook * m_book
The primary, main open book.
GncSqlObjectBackendPtr get_object_backend(const std::string &type) const noexcept
Get the GncSqlObjectBackend for the indicated type.
void init_version_info() noexcept
Initializes DB table version information.
Encapsulates per-class table schema with functions to load, create a table, commit a changed front-en...
void begin(QofInstance *) override
An object is about to be edited.
Encapsulate the connection to the database.
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.
void connect(GncSqlConnection *conn) noexcept
Connect the backend to a GncSqlConnection.
bool m_is_pristine_db
Are we saving to a new pristine db?
Pure virtual class to iterate over a query result set.
Contains all of the information required to copy information between an object and the database for a...
bool reset_version_info() noexcept
Resets the version table information by removing all version table info.
uint_t get_table_version(const std::string &table_name) const noexcept
Returns the version number for a DB table.
Main SQL backend structure.
void finalize_version_info() noexcept
Finalizes DB table version information.