37 #include "gncOrderP.h" 39 #include "gnc-sql-connection.hpp" 40 #include "gnc-sql-backend.hpp" 41 #include "gnc-sql-object-backend.hpp" 42 #include "gnc-sql-column-table-entry.hpp" 46 #define _GNC_MOD_NAME GNC_ID_ORDER 48 [[maybe_unused]]
static QofLogModule log_module =
G_LOG_DOMAIN;
50 #define TABLE_NAME "orders" 51 #define TABLE_VERSION 1 53 #define MAX_ID_LEN 2048 54 #define MAX_NOTES_LEN 2048 55 #define MAX_REFERENCE_LEN 2048 57 static EntryVec col_table
59 gnc_sql_make_table_entry<CT_GUID>(
"guid", 0, COL_NNUL | COL_PKEY,
"guid"),
60 gnc_sql_make_table_entry<CT_STRING>(
"id", MAX_ID_LEN, COL_NNUL,
"id"),
61 gnc_sql_make_table_entry<CT_STRING>(
"notes", MAX_NOTES_LEN, COL_NNUL,
63 gnc_sql_make_table_entry<CT_STRING>(
64 "reference", MAX_REFERENCE_LEN, COL_NNUL,
"reference"),
65 gnc_sql_make_table_entry<CT_BOOLEAN>(
"active", 0, COL_NNUL,
"order"),
66 gnc_sql_make_table_entry<CT_TIME>(
"date_opened", 0, COL_NNUL,
68 gnc_sql_make_table_entry<CT_TIME>(
"date_closed", 0, COL_NNUL,
70 gnc_sql_make_table_entry<CT_OWNERREF>(
"owner", 0, COL_NNUL,
74 GncSqlOrderBackend::GncSqlOrderBackend() :
76 TABLE_NAME, col_table) {}
84 g_return_val_if_fail (sql_be != NULL, NULL);
86 guid = gnc_sql_load_guid (sql_be, row);
87 pOrder = gncOrderLookup (sql_be->book(), guid);
90 pOrder = gncOrderCreate (sql_be->book());
92 gnc_sql_load_object (sql_be, row, GNC_ID_ORDER, pOrder, col_table);
93 qof_instance_mark_clean (QOF_INSTANCE (pOrder));
99 static inline GncOrder*
100 gnc_order_lookup (
const GncGUID *guid,
const QofBook *book)
108 g_return_if_fail (sql_be != NULL);
110 std::string sql(
"SELECT * FROM " TABLE_NAME);
111 auto stmt = sql_be->create_statement_from_sql(sql);
114 for (
auto row : *result)
115 load_single_order (sql_be, row);
117 std::string pkey(col_table[0]->name());
118 sql =
"SELECT DISTINCT ";
119 sql += pkey +
" FROM " TABLE_NAME;
121 (BookLookupFn)gnc_order_lookup);
126 order_should_be_saved (GncOrder* order)
130 g_return_val_if_fail (order != NULL, FALSE);
133 id = gncOrderGetID (order);
134 if (
id == NULL || *
id ==
'\0')
143 write_single_order (
QofInstance* term_p, gpointer data_p)
147 g_return_if_fail (term_p != NULL);
148 g_return_if_fail (GNC_IS_ORDER (term_p));
149 g_return_if_fail (data_p != NULL);
151 if (s->is_ok && order_should_be_saved (GNC_ORDER (term_p)))
160 g_return_val_if_fail (sql_be != NULL, FALSE);
173 gpointer pObject)
const noexcept
175 load_from_guid_ref(row, obj_name, pObject,
177 return gncOrderLookup(sql_be->book(), g);
184 add_objectref_guid_to_table(vec);
189 const gpointer pObject,
190 PairVec& vec)
const noexcept
192 add_objectref_guid_to_query(obj_name, pObject, vec);
bool write(GncSqlBackend *) override
Write all objects of m_type_name to the database.
void load_all(GncSqlBackend *) override
Load all objects of m_type in the database into memory.
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...
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
load and save accounts data to SQL
void add_to_query(QofIdTypeConst obj_name, void *pObject, PairVec &vec) const noexcept override
Add a pair of the table column heading and object's value's string representation to a PairVec; used ...
#define QOF_BOOK_RETURN_ENTITY(book, guid, e_type, c_type)
Encapsulates all the information about a dataset manipulated by QOF.
void load(const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, void *pObject) const noexcept override
Load a value into an object from the database row.
load and save order data to SQL
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 add_to_table(ColVec &vec) const noexcept override
Add a GncSqlColumnInfo structure for the column type to a ColVec.
The type used to store guids in C.
Main SQL backend structure.