37 #include "gncBillTermP.h" 38 #include "gncVendorP.h" 39 #include "gncTaxTableP.h" 41 #include "gnc-sql-connection.hpp" 42 #include "gnc-sql-backend.hpp" 43 #include "gnc-sql-object-backend.hpp" 44 #include "gnc-sql-column-table-entry.hpp" 51 #define _GNC_MOD_NAME GNC_ID_VENDOR 53 G_GNUC_UNUSED
static QofLogModule log_module =
G_LOG_DOMAIN;
55 #define MAX_NAME_LEN 2048 56 #define MAX_ID_LEN 2048 57 #define MAX_NOTES_LEN 2048 58 #define MAX_TAX_INC_LEN 2048 60 #define TABLE_NAME "vendors" 61 #define TABLE_VERSION 1 63 static EntryVec col_table
65 gnc_sql_make_table_entry<CT_GUID>(
"guid", 0, COL_NNUL | COL_PKEY,
"guid"),
66 gnc_sql_make_table_entry<CT_STRING>(
"name", MAX_NAME_LEN, COL_NNUL,
"name"),
67 gnc_sql_make_table_entry<CT_STRING>(
"id", MAX_ID_LEN, COL_NNUL,
"id"),
68 gnc_sql_make_table_entry<CT_STRING>(
"notes", MAX_NOTES_LEN, COL_NNUL,
70 gnc_sql_make_table_entry<CT_COMMODITYREF>(
"currency", 0, COL_NNUL,
72 gnc_sql_make_table_entry<CT_BOOLEAN>(
"active", 0, COL_NNUL,
"active"),
73 gnc_sql_make_table_entry<CT_BOOLEAN>(
"tax_override", 0, COL_NNUL,
74 "tax-table-override"),
75 gnc_sql_make_table_entry<CT_ADDRESS>(
"addr", 0, 0,
"address"),
76 gnc_sql_make_table_entry<CT_BILLTERMREF>(
"terms", 0, 0,
"terms"),
77 gnc_sql_make_table_entry<CT_STRING>(
"tax_inc", MAX_TAX_INC_LEN, 0,
78 "tax-included-string"),
79 gnc_sql_make_table_entry<CT_TAXTABLEREF>(
"tax_table", 0, 0,
"tax-table"),
82 GncSqlVendorBackend::GncSqlVendorBackend() :
84 TABLE_NAME, col_table) {}
92 g_return_val_if_fail (sql_be != NULL, NULL);
94 guid = gnc_sql_load_guid (sql_be, row);
95 pVendor = gncVendorLookup (sql_be->book(), guid);
98 pVendor = gncVendorCreate (sql_be->book());
100 gnc_sql_load_object (sql_be, row, GNC_ID_VENDOR, pVendor, col_table);
101 qof_instance_mark_clean (QOF_INSTANCE (pVendor));
107 static inline GncVendor*
108 gnc_vendor_lookup (
const GncGUID *guid,
const QofBook *book)
116 g_return_if_fail (sql_be != NULL);
118 std::string sql(
"SELECT * FROM " TABLE_NAME);
119 auto stmt = sql_be->create_statement_from_sql(sql);
122 for (
auto row : *result)
123 load_single_vendor (sql_be, row);
125 std::string pkey(col_table[0]->name());
126 sql =
"SELECT DISTINCT ";
127 sql += pkey +
" FROM " TABLE_NAME;
129 (BookLookupFn)gnc_vendor_lookup);
140 gboolean is_ok = TRUE;
142 g_return_val_if_fail (inst != NULL, FALSE);
143 g_return_val_if_fail (GNC_IS_VENDOR (inst), FALSE);
144 g_return_val_if_fail (sql_be != NULL, FALSE);
146 v = GNC_VENDOR (inst);
148 is_infant = qof_instance_get_infant (inst);
153 else if (sql_be->pristine() || is_infant)
161 if (op != OP_DB_DELETE)
191 vendor_should_be_saved (GncVendor* vendor)
195 g_return_val_if_fail (vendor != NULL, FALSE);
198 id = gncVendorGetID (vendor);
199 if (
id == NULL || *
id ==
'\0')
208 write_single_vendor (
QofInstance* term_p, gpointer data_p)
212 g_return_if_fail (term_p != NULL);
213 g_return_if_fail (GNC_IS_VENDOR (term_p));
214 g_return_if_fail (data_p != NULL);
216 if (vendor_should_be_saved (GNC_VENDOR (term_p)))
225 g_return_val_if_fail (sql_be != NULL, FALSE);
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.
load and save vendor data to SQL
GncSqlResultPtr execute_select_statement(const GncSqlStatementPtr &stmt) const noexcept
Executes an SQL SELECT statement and returns the result rows.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
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...
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
load and save data to SQL
load and save accounts data to SQL
gboolean qof_instance_get_destroying(gconstpointer ptr)
Retrieve the flag that indicates whether or not this object is about to be destroyed.
gboolean gnc_sql_slots_save(GncSqlBackend *sql_be, const GncGUID *guid, gboolean is_infant, QofInstance *inst)
gnc_sql_slots_save - Saves slots for an object to the db.
bool write(GncSqlBackend *) override
Write all objects of m_type_name to the database.
#define QOF_BOOK_RETURN_ENTITY(book, guid, e_type, c_type)
Encapsulates all the information about a dataset manipulated by QOF.
load and save accounts data to SQL
bool commit(GncSqlBackend *, QofInstance *) override
UPDATE/INSERT a single instance of m_type_name into the database.
bool save_commodity(gnc_commodity *comm) noexcept
Ensure that a commodity referenced in another object is in fact saved in the database.
Row of SQL Query results.
void qof_object_foreach(QofIdTypeConst type_name, QofBook *book, QofInstanceForeachCB cb, gpointer user_data)
Invoke the callback 'cb' on every instance ov a particular object type.
Encapsulates per-class table schema with functions to load, create a table, commit a changed front-en...
Data-passing struct for callbacks to qof_object_foreach() used in GncSqlObjectBackend::write().
void load_all(GncSqlBackend *) override
Load all objects of m_type in the database into memory.
gboolean gnc_sql_slots_delete(GncSqlBackend *sql_be, const GncGUID *guid)
gnc_sql_slots_delete - Deletes slots for an object from the db.
The type used to store guids in C.
Commodity handling public routines.
Main SQL backend structure.
load and save tax table data to SQL