34 #include "gncCustomerP.h" 36 #include "gncEmployeeP.h" 37 #include "gncVendorP.h" 41 #include "gnc-sql-backend.hpp" 42 #include "gnc-sql-column-table-entry.hpp" 46 typedef void (*OwnerSetterFunc) (gpointer,
GncOwner*);
47 typedef GncOwner* (*OwnerGetterFunc) (
const gpointer);
53 gpointer pObject)
const noexcept
60 g_return_if_fail (sql_be !=
nullptr);
61 g_return_if_fail (pObject !=
nullptr);
63 auto book = sql_be->book();
64 auto buf = std::string{m_col_name} +
"_type";
67 type =
static_cast<decltype(type)
>(row.get_int_at_col(buf.c_str()).value_or(0));
68 buf = std::string{m_col_name} +
"_guid";
69 auto val = row.get_string_at_col (buf.c_str());
73 catch (std::invalid_argument&)
77 if (type == GNC_OWNER_NONE || pGuid ==
nullptr)
82 case GNC_OWNER_CUSTOMER:
88 cust = gncCustomerLookup (book, pGuid);
91 cust = gncCustomerCreate (book);
92 gncCustomerSetGUID (cust, &guid);
95 gncOwnerInitCustomer (&owner, cust);
105 job = gncJobLookup (book, pGuid);
108 job = gncJobCreate (book);
109 gncJobSetGUID (job, &guid);
112 gncOwnerInitJob (&owner, job);
116 case GNC_OWNER_VENDOR:
118 GncVendor* vendor = NULL;
122 vendor = gncVendorLookup (book, pGuid);
125 vendor = gncVendorCreate (book);
126 gncVendorSetGUID (vendor, &guid);
129 gncOwnerInitVendor (&owner, vendor);
133 case GNC_OWNER_EMPLOYEE:
135 GncEmployee* employee = NULL;
139 employee = gncEmployeeLookup (book, pGuid);
140 if (employee == NULL)
142 employee = gncEmployeeCreate (book);
143 gncEmployeeSetGUID (employee, &guid);
146 gncOwnerInitEmployee (&owner, employee);
151 PWARN (
"Invalid owner type: %d\n", type);
153 set_parameter (pObject, &owner, get_setter(obj_name), m_gobj_param_name);
159 auto buf = g_strdup_printf (
"%s_type", m_col_name);
161 m_flags & COL_PKEY, m_flags & COL_NNUL);
162 vec.emplace_back(std::move(info));
164 buf = g_strdup_printf (
"%s_guid", m_col_name);
166 m_flags & COL_PKEY, m_flags & COL_NNUL);
167 vec.emplace_back(std::move(info2));
172 const gpointer pObject,
173 PairVec& vec)
const noexcept
175 g_return_if_fail (obj_name != NULL);
176 g_return_if_fail (pObject != NULL);
178 auto getter = (OwnerGetterFunc)get_getter (obj_name);
179 auto owner = (*getter) (pObject);
182 GncOwnerType type = GNC_OWNER_NONE;
184 auto type_hdr = std::string{m_col_name} +
"_type";
185 auto guid_hdr = std::string{m_col_name} +
"_guid";
187 if (owner !=
nullptr)
192 case GNC_OWNER_CUSTOMER:
200 case GNC_OWNER_VENDOR:
204 case GNC_OWNER_EMPLOYEE:
209 PWARN (
"Invalid owner type: %d\n", type);
216 vec.emplace_back (std::make_pair (type_hdr, std::string{
"NULL"}));
217 vec.emplace_back (std::make_pair (guid_hdr, std::string{
"NULL"}));
221 std::ostringstream buf;
224 vec.emplace_back(std::make_pair(type_hdr, quote_string(buf.str())));
235 vec.emplace_back(std::make_pair(guid_hdr, quote_string(buf.str())));
information required to create a column in a table.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
const gchar * QofIdTypeConst
QofIdTypeConst declaration.
gboolean string_to_guid(const gchar *string, GncGUID *guid)
Given a string, replace the given guid with the parsed one unless the given value is null...
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 ...
gchar * guid_to_string_buff(const GncGUID *guid, gchar *str)
The guid_to_string_buff() routine puts a null-terminated string encoding of the id into the memory po...
#define PWARN(format, args...)
Log a warning.
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.
Row of SQL Query results.
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
credit, discount and shipaddr are unique to GncCustomer id, name, notes, terms, addr, currency, taxtable, taxtable_override taxincluded, active and jobs are identical to ::GncVendor.
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
GncJob * gncOwnerGetJob(const GncOwner *owner)
If the given owner is of type GNC_OWNER_JOB, returns the pointer to the job object.
void add_to_table(ColVec &vec) const noexcept override
Add a GncSqlColumnInfo structure for the column type to a ColVec.
GncVendor * gncOwnerGetVendor(const GncOwner *owner)
If the given owner is of type GNC_OWNER_VENDOR, returns the pointer to the vendor object...
GncCustomer * gncOwnerGetCustomer(const GncOwner *owner)
If the given owner is of type GNC_OWNER_CUSTOMER, returns the pointer to the customer object...
GncEmployee * gncOwnerGetEmployee(const GncOwner *owner)
If the given owner is of type GNC_OWNER_EMPLOYEE, returns the pointer to the employee object...
The type used to store guids in C.
Main SQL backend structure.