GnuCash
5.6-150-g038405b370+
|
Main SQL backend structure. More...
#include <gnc-sql-backend.hpp>
Public Member Functions | |
GncSqlBackend (GncSqlConnection *conn, QofBook *book) | |
void | load (QofBook *, QofBackendLoadType) override |
Load the contents of an SQL database into a book. More... | |
void | sync (QofBook *) override |
Save the contents of a book to an SQL database. More... | |
void | begin (QofInstance *) override |
An object is about to be edited. More... | |
void | commit (QofInstance *) override |
Object editing is complete and the object should be saved. More... | |
void | rollback (QofInstance *) override |
Object editing has been cancelled. More... | |
void | connect (GncSqlConnection *conn) noexcept |
Connect the backend to a GncSqlConnection. More... | |
void | init_version_info () noexcept |
Initializes DB table version information. More... | |
bool | reset_version_info () noexcept |
Resets the version table information by removing all version table info. More... | |
void | finalize_version_info () noexcept |
Finalizes DB table version information. More... | |
GncSqlStatementPtr | create_statement_from_sql (const std::string &str) const noexcept |
GncSqlResultPtr | execute_select_statement (const GncSqlStatementPtr &stmt) const noexcept |
Executes an SQL SELECT statement and returns the result rows. More... | |
int | execute_nonselect_statement (const GncSqlStatementPtr &stmt) const noexcept |
std::string | quote_string (const std::string &) const noexcept |
bool | create_table (const std::string &table_name, const EntryVec &col_table) const noexcept |
Creates a table in the database. More... | |
bool | create_table (const std::string &table_name, int table_version, const EntryVec &col_table) noexcept |
Creates a table in the database and sets its version. More... | |
void | create_tables () noexcept |
Create/update all tables in 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. More... | |
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. More... | |
void | upgrade_table (const std::string &table_name, const EntryVec &col_table) noexcept |
Upgrades a table to a new structure. More... | |
uint_t | get_table_version (const std::string &table_name) const noexcept |
Returns the version number for a DB table. More... | |
bool | set_table_version (const std::string &table_name, uint_t version) noexcept |
Registers the version for a table. More... | |
void | commodity_for_postload_processing (gnc_commodity *) |
Register a commodity to be committed after loading is complete. More... | |
GncSqlObjectBackendPtr | get_object_backend (const std::string &type) const noexcept |
Get the GncSqlObjectBackend for the indicated type. More... | |
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. More... | |
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. More... | |
bool | save_commodity (gnc_commodity *comm) noexcept |
Ensure that a commodity referenced in another object is in fact saved in the database. More... | |
QofBook * | book () const noexcept |
void | set_loading (bool loading) noexcept |
bool | pristine () const noexcept |
void | update_progress (double pct) const noexcept |
void | finish_progress () const noexcept |
Public Member Functions inherited from QofBackend | |
QofBackend (const QofBackend &)=delete | |
QofBackend (const QofBackend &&)=delete | |
virtual void | session_begin (QofSession *session, const char *new_uri, SessionOpenMode mode)=0 |
Open the file or connect to the server. More... | |
virtual void | session_end ()=0 |
virtual void | safe_sync (QofBook *)=0 |
Perform a sync in a way that prevents data loss on a DBI backend. | |
virtual void | export_coa (QofBook *) |
Extract the chart of accounts from the current database and create a new database with it. More... | |
void | set_error (QofBackendError err) |
Set the error value only if there isn't already an error already. | |
QofBackendError | get_error () |
Retrieve the currently-stored error and clear it. | |
bool | check_error () |
Report if there is an error. | |
void | set_message (std::string &&) |
Set a descriptive message that can be displayed to the user when there's an error. | |
const std::string && | get_message () |
Retrieve and clear the stored error message. | |
void | set_percentage (QofBePercentageFunc pctfn) |
Store and retrieve a backend-specific function for determining the progress in completing a long operation, for use with a progress meter. | |
QofBePercentageFunc | get_percentage () |
const std::string & | get_uri () |
Retrieve the backend's storage URI. | |
Protected Attributes | |
GncSqlConnection * | m_conn = nullptr |
SQL connection. | |
QofBook * | m_book = nullptr |
The primary, main open book. | |
bool | m_loading |
We are performing an initial load. | |
bool | m_in_query |
We are processing a query. | |
bool | m_is_pristine_db |
Are we saving to a new pristine db? | |
const char * | m_time_format = nullptr |
Server-specific date-time string format. | |
VersionVec | m_versions |
Version number for each table. | |
Protected Attributes inherited from QofBackend | |
QofBePercentageFunc | m_percentage |
std::string | m_fullpath |
Each backend resolves a fully-qualified file path. More... | |
Additional Inherited Members | |
Static Public Member Functions inherited from QofBackend | |
static bool | register_backend (const char *, const char *) |
Class methods for dynamically loading the several backends and for freeing them at shutdown. | |
static void | release_backends () |
Main SQL backend structure.
Definition at line 63 of file gnc-sql-backend.hpp.
|
noexcept |
Adds one or more columns to an existing table.
table_name | SQL table name |
new_col_table | Column table for new columns |
Definition at line 182 of file gnc-sql-backend.cpp.
|
overridevirtual |
An object is about to be edited.
inst | Object being edited |
Reimplemented from QofBackend.
Definition at line 543 of file gnc-sql-backend.cpp.
|
overridevirtual |
Object editing is complete and the object should be saved.
inst | Object being edited |
Reimplemented from QofBackend.
Definition at line 577 of file gnc-sql-backend.cpp.
void GncSqlBackend::commodity_for_postload_processing | ( | gnc_commodity * | commodity | ) |
Register a commodity to be committed after loading is complete.
Necessary to save corrections made while loading.
comm | The commodity item to be committed. |
Definition at line 561 of file gnc-sql-backend.cpp.
|
noexcept |
Connect the backend to a GncSqlConnection.
Sets up version info. Calling with nullptr clears the connection and destroys the version info.
Definition at line 94 of file gnc-sql-backend.cpp.
|
noexcept |
Creates an index in the database.
index_name | Index name |
table_name | Table name |
col_table | Columns that the index should index |
Definition at line 173 of file gnc-sql-backend.cpp.
|
noexcept |
Creates a table in the database.
table_name | Table name |
col_table | DB table description |
Definition at line 148 of file gnc-sql-backend.cpp.
|
noexcept |
Creates a table in the database and sets its version.
table_name | Table name |
table_version | Table version |
col_table | DB table description |
Definition at line 164 of file gnc-sql-backend.cpp.
|
noexcept |
Performs an operation on the database.
op | Operation type |
table_name | SQL table name |
obj_name | QOF object type name |
pObject | Gnucash object |
table | DB table description |
Definition at line 854 of file gnc-sql-backend.cpp.
|
noexcept |
Executes an SQL SELECT statement and returns the result rows.
If an error occurs, an entry is added to the log, an error status is returned to qof and nullptr is returned.
statement | Statement |
Definition at line 115 of file gnc-sql-backend.cpp.
|
noexcept |
Finalizes DB table version information.
Finalizes the version table info by destroying the hash table.
be | Backend struct |
Definition at line 721 of file gnc-sql-backend.cpp.
|
noexcept |
Get the GncSqlObjectBackend for the indicated type.
Required because we need to pass a pointer to this to a callback via a C function.
type | The QofInstance type constant to select the object backend. |
Definition at line 567 of file gnc-sql-backend.cpp.
|
noexcept |
Returns the version number for a DB table.
table_name | Table name |
Definition at line 727 of file gnc-sql-backend.cpp.
|
noexcept |
Initializes DB table version information.
Sees if the version table exists, and if it does, loads the info into the version hash table.
Otherwise, it creates an empty version table.
be | Backend struct |
Definition at line 673 of file gnc-sql-backend.cpp.
|
overridevirtual |
Load the contents of an SQL database into a book.
book | Book to be loaded |
Implements QofBackend.
Definition at line 283 of file gnc-sql-backend.cpp.
|
noexcept |
Checks whether an object is in the database or not.
table_name | DB table name |
obj_name | QOF object type name |
pObject | Object to be checked |
table | DB table description |
Definition at line 832 of file gnc-sql-backend.cpp.
|
noexcept |
Resets the version table information by removing all version table info.
It also recreates the version table in the db.
be | Backend struct |
Definition at line 706 of file gnc-sql-backend.cpp.
|
overridevirtual |
Object editing has been cancelled.
inst | Object being edited |
Reimplemented from QofBackend.
Definition at line 552 of file gnc-sql-backend.cpp.
|
noexcept |
Ensure that a commodity referenced in another object is in fact saved in the database.
comm | The commodity in question |
Definition at line 882 of file gnc-sql-backend.cpp.
|
noexcept |
Registers the version for a table.
Registering involves updating the db version table and also the hash table.
be | Backend struct |
table_name | Table name |
version | Version number |
Definition at line 751 of file gnc-sql-backend.cpp.
|
overridevirtual |
Save the contents of a book to an SQL database.
book | Book to be saved |
Implements QofBackend.
Definition at line 472 of file gnc-sql-backend.cpp.
|
noexcept |
Upgrades a table to a new structure.
The upgrade is done by creating a new table with the new structure, SELECTing the old data into the new table, deleting the old table, then renaming the new table. Therefore, this will only work if the new table structure is similar enough to the old table that the SELECT will work.
table_name | SQL table name |
col_table | Column table |
Definition at line 792 of file gnc-sql-backend.cpp.