GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions
GncSqlColumnTableEntryImpl< Type > Class Template Referencefinal
Inheritance diagram for GncSqlColumnTableEntryImpl< Type >:
GncSqlColumnTableEntry

Public Member Functions

 GncSqlColumnTableEntryImpl (const char *name, const GncSqlObjectType type, unsigned int s, int f, const char *gobj_name=nullptr, const char *qof_name=nullptr, QofAccessFunc get=nullptr, QofSetterFunc set=nullptr)
 
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.
 
void add_to_table (ColVec &vec) const noexcept override
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
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 for constructing WHERE clauses and UPDATE statements.
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, gpointer pObject) const noexcept
 
void add_to_table (ColVec &vec) const noexcept
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
void add_to_query (QofIdTypeConst obj_name, const gpointer pObject, PairVec &vec) const noexcept
 
- Public Member Functions inherited from GncSqlColumnTableEntry
 GncSqlColumnTableEntry (const char *name, const GncSqlObjectType type, unsigned int s, int f, const char *gobj_name=nullptr, const char *qof_name=nullptr, QofAccessFunc get=nullptr, QofSetterFunc set=nullptr)
 
QofAccessFunc get_getter (QofIdTypeConst obj_name) const noexcept
 Retrieve the getter function depending on whether it's an auto-increment field, a QofClass getter, or a function passed to the constructor.
 
QofSetterFunc get_setter (QofIdTypeConst obj_name) const noexcept
 Retrieve the setter function depending on whether it's an auto-increment field, a QofClass getter, or a function passed to the constructor.
 
const char * name () const noexcept
 Retrieve the field name so that we don't need to make create_single_col_select_statement and friend.
 
bool is_autoincr () const noexcept
 Report if the entry is an auto-increment field.
 
template<typename T >
void load_from_guid_ref (GncSqlRow &row, QofIdTypeConst obj_name, void *pObject, T get_ref) const noexcept
 

Additional Inherited Members

- Protected Member Functions inherited from GncSqlColumnTableEntry
template<typename T >
get_row_value_from_object (QofIdTypeConst obj_name, const void *pObject) const
 
template<typename T >
void add_value_to_vec (QofIdTypeConst obj_name, const void *pObject, PairVec &vec) const
 
void add_objectref_guid_to_query (QofIdTypeConst obj_name, const void *pObject, PairVec &vec) const noexcept
 Adds a name/guid std::pair to a PairVec for creating a query.
 
void add_objectref_guid_to_table (ColVec &vec) const noexcept
 Adds a column info structure for an object reference GncGUID to a ColVec.
 
template<>
gint64 get_row_value_from_object (QofIdTypeConst obj_name, const void *pObject) const
 
template<>
void add_value_to_vec (QofIdTypeConst obj_name, const void *pObject, PairVec &vec, std::true_type) const
 
template<>
void add_value_to_vec (QofIdTypeConst obj_name, const void *pObject, PairVec &vec, std::false_type) const
 

Detailed Description

template<GncSqlObjectType Type>
class GncSqlColumnTableEntryImpl< Type >

Definition at line 267 of file gnc-sql-column-table-entry.hpp.

Constructor & Destructor Documentation

◆ GncSqlColumnTableEntryImpl()

template<GncSqlObjectType Type>
GncSqlColumnTableEntryImpl< Type >::GncSqlColumnTableEntryImpl ( const char *  name,
const GncSqlObjectType  type,
unsigned int  s,
int  f,
const char *  gobj_name = nullptr,
const char *  qof_name = nullptr,
QofAccessFunc  get = nullptr,
QofSetterFunc  set = nullptr 
)
inline

Definition at line 270 of file gnc-sql-column-table-entry.hpp.

275 :
276 GncSqlColumnTableEntry (name, type, s, f, gobj_name,qof_name, get, set)
277 {}
Contains all of the information required to copy information between an object and the database for a...
const char * name() const noexcept
Retrieve the field name so that we don't need to make create_single_col_select_statement and friend.

Member Function Documentation

◆ add_to_query() [1/21]

void GncSqlColumnTableEntryImpl< CT_ACCOUNTREF >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 367 of file gnc-account-sql.cpp.

371{
372 add_objectref_guid_to_query(obj_name, pObject, vec);
373}
void add_objectref_guid_to_query(QofIdTypeConst obj_name, const void *pObject, PairVec &vec) const noexcept
Adds a name/guid std::pair to a PairVec for creating a query.

◆ add_to_query() [2/21]

void GncSqlColumnTableEntryImpl< CT_ADDRESS >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 116 of file gnc-address-sql.cpp.

119{
120 auto addr(get_row_value_from_object<char*>(obj_name, pObject));
121 if (addr == nullptr) return;
122
123 for (auto const& subtable_row : col_table)
124 {
125 auto s = subtable_row->get_row_value_from_object<char*>(GNC_ID_ADDRESS,
126 addr);
127 if (s == nullptr)
128 continue;
129 auto buf = std::string{m_col_name} + "_" + subtable_row->m_col_name;
130 vec.emplace_back(make_pair(buf, quote_string(s)));
131 }
132}

◆ add_to_query() [3/21]

void GncSqlColumnTableEntryImpl< CT_BILLTERMREF >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 351 of file gnc-bill-term-sql.cpp.

354{
355 add_objectref_guid_to_query(obj_name, pObject, vec);
356}

◆ add_to_query() [4/21]

void GncSqlColumnTableEntryImpl< CT_BUDGETREF >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 475 of file gnc-budget-sql.cpp.

478{
479 add_objectref_guid_to_query(obj_name, pObject, vec);
480}

◆ add_to_query() [5/21]

void GncSqlColumnTableEntryImpl< CT_COMMODITYREF >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 241 of file gnc-commodity-sql.cpp.

244{
245 add_objectref_guid_to_query(obj_name, pObject, vec);
246}

◆ add_to_query() [6/21]

void GncSqlColumnTableEntryImpl< CT_INVOICEREF >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 300 of file gnc-invoice-sql.cpp.

303{
304 add_objectref_guid_to_query(obj_name, pObject, vec);
305}

◆ add_to_query() [7/21]

void GncSqlColumnTableEntryImpl< CT_LOTREF >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 213 of file gnc-lots-sql.cpp.

216{
217 add_objectref_guid_to_query(obj_name, pObject, vec);
218}

◆ add_to_query() [8/21]

void GncSqlColumnTableEntryImpl< CT_ORDERREF >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 188 of file gnc-order-sql.cpp.

191{
192 add_objectref_guid_to_query(obj_name, pObject, vec);
193}

◆ add_to_query() [9/21]

void GncSqlColumnTableEntryImpl< CT_OWNERREF >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 171 of file gnc-owner-sql.cpp.

174{
175 g_return_if_fail (obj_name != NULL);
176 g_return_if_fail (pObject != NULL);
177
178 auto getter = (OwnerGetterFunc)get_getter (obj_name);
179 auto owner = (*getter) (pObject);
180
181 QofInstance* inst = nullptr;
182 GncOwnerType type = GNC_OWNER_NONE;
183
184 auto type_hdr = std::string{m_col_name} + "_type";
185 auto guid_hdr = std::string{m_col_name} + "_guid";
186
187 if (owner != nullptr)
188 {
189 type = gncOwnerGetType (owner);
190 switch (type)
191 {
192 case GNC_OWNER_CUSTOMER:
193 inst = QOF_INSTANCE (gncOwnerGetCustomer (owner));
194 break;
195
196 case GNC_OWNER_JOB:
197 inst = QOF_INSTANCE (gncOwnerGetJob (owner));
198 break;
199
200 case GNC_OWNER_VENDOR:
201 inst = QOF_INSTANCE (gncOwnerGetVendor (owner));
202 break;
203
204 case GNC_OWNER_EMPLOYEE:
205 inst = QOF_INSTANCE (gncOwnerGetEmployee (owner));
206 break;
207
208 default:
209 PWARN ("Invalid owner type: %d\n", type);
210 }
211 }
212
213 if (inst == nullptr)
214 {
215 /* Twice, once for type, once for guid. */
216 vec.emplace_back (std::make_pair (type_hdr, std::string{"NULL"}));
217 vec.emplace_back (std::make_pair (guid_hdr, std::string{"NULL"}));
218
219 return;
220 }
221 std::ostringstream buf;
222
223 buf << type;
224 vec.emplace_back(std::make_pair(type_hdr, quote_string(buf.str())));
225 buf.str("");
226 auto guid = qof_instance_get_guid(inst);
227 if (guid != nullptr)
228 {
229 char strbuff[GUID_ENCODING_LENGTH+1];
230 guid_to_string_buff (guid, strbuff);
231 buf << strbuff;
232 }
233 else
234 buf << "NULL";
235 vec.emplace_back(std::make_pair(guid_hdr, quote_string(buf.str())));
236}
QofAccessFunc get_getter(QofIdTypeConst obj_name) const noexcept
Retrieve the getter function depending on whether it's an auto-increment field, a QofClass getter,...
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
Definition guid.h:84
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...
Definition guid.cpp:208
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250
GncCustomer * gncOwnerGetCustomer(const GncOwner *owner)
If the given owner is of type GNC_OWNER_CUSTOMER, returns the pointer to the customer object.
Definition gncOwner.c:369
GncEmployee * gncOwnerGetEmployee(const GncOwner *owner)
If the given owner is of type GNC_OWNER_EMPLOYEE, returns the pointer to the employee object.
Definition gncOwner.c:390
GncJob * gncOwnerGetJob(const GncOwner *owner)
If the given owner is of type GNC_OWNER_JOB, returns the pointer to the job object.
Definition gncOwner.c:376
GncVendor * gncOwnerGetVendor(const GncOwner *owner)
If the given owner is of type GNC_OWNER_VENDOR, returns the pointer to the vendor object.
Definition gncOwner.c:383
GncOwnerType gncOwnerGetType(const GncOwner *owner)
Returns the GncOwnerType of this owner.
Definition gncOwner.c:200

◆ add_to_query() [10/21]

void GncSqlColumnTableEntryImpl< CT_STRING >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 143 of file gnc-sql-column-table-entry.cpp.

146{
147 auto s = get_row_value_from_object<char*>(obj_name, pObject);
148
149 if (s != nullptr)
150 {
151 std::ostringstream stream;
152 stream << s;
153 vec.emplace_back (std::make_pair (std::string{m_col_name},
154 quote_string(stream.str())));
155 return;
156 }
157}

◆ add_to_query() [11/21]

void GncSqlColumnTableEntryImpl< CT_INT >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 188 of file gnc-sql-column-table-entry.cpp.

191{
192 add_value_to_vec<int>(obj_name, pObject, vec);
193}

◆ add_to_query() [12/21]

void GncSqlColumnTableEntryImpl< CT_BOOLEAN >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 224 of file gnc-sql-column-table-entry.cpp.

227{
228 add_value_to_vec<int>(obj_name, pObject, vec);
229}

◆ add_to_query() [13/21]

void GncSqlColumnTableEntryImpl< CT_INT64 >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 279 of file gnc-sql-column-table-entry.cpp.

282{
283 add_value_to_vec<int64_t>(obj_name, pObject, vec);
284}

◆ add_to_query() [14/21]

void GncSqlColumnTableEntryImpl< CT_DOUBLE >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 316 of file gnc-sql-column-table-entry.cpp.

319{
320 add_value_to_vec<double*>(obj_name, pObject, vec);
321}

◆ add_to_query() [15/21]

void GncSqlColumnTableEntryImpl< CT_GUID >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 351 of file gnc-sql-column-table-entry.cpp.

354{
355 auto s = get_row_value_from_object<GncGUID*>(obj_name, pObject);
356
357 if (s != nullptr)
358 {
359 gchar *guid_s = guid_to_string(s);
360 vec.emplace_back (std::make_pair (std::string{m_col_name}, quote_string(guid_s)));
361 g_free(guid_s);
362 return;
363 }
364}
gchar * guid_to_string(const GncGUID *guid)
The guid_to_string() routine returns a null-terminated string encoding of the id.
Definition guid.cpp:199

◆ add_to_query() [16/21]

void GncSqlColumnTableEntryImpl< CT_TIME >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 423 of file gnc-sql-column-table-entry.cpp.

426{
427 /* We still can't use get_row_value_from_object because while g_value could
428 * contentedly store a time64 in an int64, KVP wouldn't be able to tell them
429 * apart, so we have the struct Time64 hack, see engine/gnc-date.c.
430 */
431 time64 t64;
432 if (m_gobj_param_name != nullptr)
433 {
434 Time64* t;
435 g_object_get (pObject, m_gobj_param_name, &t, nullptr);
436 t64 = t->t;
437 }
438 else
439 {
440 auto getter = (Time64AccessFunc)get_getter (obj_name);
441 g_return_if_fail(getter != nullptr);
442 t64 = (*getter)(pObject);
443 }
444 if (t64 > MINTIME && t64 < MAXTIME)
445 {
446 GncDateTime time(t64);
447 std::string timestr("'");
448 timestr += time.format_iso8601() + "'";
449 vec.emplace_back (std::make_pair (std::string{m_col_name}, timestr));
450 }
451 else
452 {
453 vec.emplace_back (std::make_pair (std::string{m_col_name},
454 "NULL"));
455 }
456}
GnuCash DateTime class.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87

◆ add_to_query() [17/21]

void GncSqlColumnTableEntryImpl< CT_GDATE >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 513 of file gnc-sql-column-table-entry.cpp.

516{
517 GDate *date = get_row_value_from_object<GDate*>(obj_name, pObject);
518
519 if (date && g_date_valid (date))
520 {
521 std::ostringstream buf;
522 buf << std::setfill ('0') << std::setw (4) << g_date_get_year (date) <<
523 std::setw (2) << g_date_get_month (date) <<
524 std::setw (2) << static_cast<int>(g_date_get_day (date));
525 vec.emplace_back (std::make_pair (std::string{m_col_name},
526 quote_string(buf.str())));
527 return;
528 }
529}

◆ add_to_query() [18/21]

void GncSqlColumnTableEntryImpl< CT_NUMERIC >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 594 of file gnc-sql-column-table-entry.cpp.

597{
598/* We can't use get_row_value_from_object for the same reason as time64. */
599 NumericGetterFunc getter;
600 gnc_numeric n;
601
602 g_return_if_fail (obj_name != NULL);
603 g_return_if_fail (pObject != NULL);
604
605 if (m_gobj_param_name != nullptr)
606 {
607 gnc_numeric* s;
608 g_object_get (pObject, m_gobj_param_name, &s, NULL);
609 n = *s;
610 }
611 else
612 {
613 getter = reinterpret_cast<NumericGetterFunc>(get_getter (obj_name));
614 if (getter != NULL)
615 {
616 n = (*getter) (pObject);
617 }
618 else
619 {
620 n = gnc_numeric_zero ();
621 }
622 }
623
624 std::ostringstream buf;
625 std::string num_col{m_col_name};
626 std::string denom_col{m_col_name};
627 num_col += "_num";
628 denom_col += "_denom";
629 buf << gnc_numeric_num (n);
630 vec.emplace_back (std::make_pair (num_col, buf.str ()));
631 buf.str ("");
632 buf << gnc_numeric_denom (n);
633 vec.emplace_back (denom_col, buf.str ());
634}

◆ add_to_query() [19/21]

void GncSqlColumnTableEntryImpl< CT_TAXTABLEREF >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 507 of file gnc-tax-table-sql.cpp.

510{
511 add_objectref_guid_to_query(obj_name, pObject, vec);
512}

◆ add_to_query() [20/21]

void GncSqlColumnTableEntryImpl< CT_TXREF >::add_to_query ( QofIdTypeConst  obj_name,
const gpointer  pObject,
PairVec &  vec 
) const
noexcept

Definition at line 828 of file gnc-transaction-sql.cpp.

831{
832 add_objectref_guid_to_query(obj_name, pObject, vec);
833}

◆ add_to_query() [21/21]

template<GncSqlObjectType Type>
void GncSqlColumnTableEntryImpl< Type >::add_to_query ( QofIdTypeConst  obj_name,
void *  pObject,
PairVec &  vec 
) const
overridevirtualnoexcept

Add a pair of the table column heading and object's value's string representation to a PairVec; used for constructing WHERE clauses and UPDATE statements.

Implements GncSqlColumnTableEntry.

◆ add_to_table() [1/21]

void GncSqlColumnTableEntryImpl< CT_ACCOUNTREF >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 361 of file gnc-account-sql.cpp.

362{
364}
void add_objectref_guid_to_table(ColVec &vec) const noexcept
Adds a column info structure for an object reference GncGUID to a ColVec.

◆ add_to_table() [2/21]

void GncSqlColumnTableEntryImpl< CT_ADDRESS >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 101 of file gnc-address-sql.cpp.

102{
103 for (auto const& subtable_row : col_table)
104 {
105 auto buf = std::string{m_col_name} + "_" + subtable_row->m_col_name;
106 GncSqlColumnInfo info(buf.c_str(), BCT_STRING, subtable_row->m_size,
107 true, false, m_flags & COL_PKEY, m_flags & COL_NNUL);
108 vec.emplace_back(std::move(info));
109 }
110}
information required to create a column in a table.

◆ add_to_table() [3/21]

void GncSqlColumnTableEntryImpl< CT_BILLTERMREF >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 345 of file gnc-bill-term-sql.cpp.

346{
348}

◆ add_to_table() [4/21]

void GncSqlColumnTableEntryImpl< CT_BUDGETREF >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 469 of file gnc-budget-sql.cpp.

470{
472}

◆ add_to_table() [5/21]

void GncSqlColumnTableEntryImpl< CT_COMMODITYREF >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 235 of file gnc-commodity-sql.cpp.

236{
238}

◆ add_to_table() [6/21]

void GncSqlColumnTableEntryImpl< CT_INVOICEREF >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 294 of file gnc-invoice-sql.cpp.

295{
297}

◆ add_to_table() [7/21]

void GncSqlColumnTableEntryImpl< CT_LOTREF >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 207 of file gnc-lots-sql.cpp.

208{
210}

◆ add_to_table() [8/21]

void GncSqlColumnTableEntryImpl< CT_ORDERREF >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 182 of file gnc-order-sql.cpp.

183{
185}

◆ add_to_table() [9/21]

void GncSqlColumnTableEntryImpl< CT_OWNERREF >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 157 of file gnc-owner-sql.cpp.

158{
159 auto buf = g_strdup_printf ("%s_type", m_col_name);
160 GncSqlColumnInfo info(buf, BCT_INT, 0, false, false,
161 m_flags & COL_PKEY, m_flags & COL_NNUL);
162 vec.emplace_back(std::move(info));
163/* Buf isn't leaking, it belongs to ColVec now. */
164 buf = g_strdup_printf ("%s_guid", m_col_name);
165 GncSqlColumnInfo info2(buf, BCT_STRING, GUID_ENCODING_LENGTH, false, false,
166 m_flags & COL_PKEY, m_flags & COL_NNUL);
167 vec.emplace_back(std::move(info2));
168}

◆ add_to_table() [10/21]

void GncSqlColumnTableEntryImpl< CT_STRING >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 133 of file gnc-sql-column-table-entry.cpp.

134{
135 GncSqlColumnInfo info{*this, BCT_STRING, m_size, TRUE};
136 vec.emplace_back(std::move(info));
137}

◆ add_to_table() [11/21]

void GncSqlColumnTableEntryImpl< CT_INT >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 181 of file gnc-sql-column-table-entry.cpp.

182{
183 GncSqlColumnInfo info{*this, BCT_INT, 0, FALSE};
184 vec.emplace_back(std::move(info));
185}

◆ add_to_table() [12/21]

void GncSqlColumnTableEntryImpl< CT_BOOLEAN >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 217 of file gnc-sql-column-table-entry.cpp.

218{
219 GncSqlColumnInfo info{*this, BCT_INT, 0, FALSE};
220 vec.emplace_back(std::move(info));
221}

◆ add_to_table() [13/21]

void GncSqlColumnTableEntryImpl< CT_INT64 >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 252 of file gnc-sql-column-table-entry.cpp.

253{
254
255 GncSqlColumnInfo info{*this, BCT_INT64, 0, FALSE};
256 vec.emplace_back(std::move(info));
257}

◆ add_to_table() [14/21]

void GncSqlColumnTableEntryImpl< CT_DOUBLE >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 309 of file gnc-sql-column-table-entry.cpp.

310{
311 GncSqlColumnInfo info{*this, BCT_DOUBLE, 0, FALSE};
312 vec.emplace_back(std::move(info));
313}

◆ add_to_table() [15/21]

void GncSqlColumnTableEntryImpl< CT_GUID >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 344 of file gnc-sql-column-table-entry.cpp.

345{
346 GncSqlColumnInfo info{*this, BCT_STRING, GUID_ENCODING_LENGTH, FALSE};
347 vec.emplace_back(std::move(info));
348}

◆ add_to_table() [16/21]

void GncSqlColumnTableEntryImpl< CT_TIME >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 415 of file gnc-sql-column-table-entry.cpp.

416{
417
418 GncSqlColumnInfo info{*this, BCT_DATETIME, TIME_COL_SIZE, FALSE};
419 vec.emplace_back(std::move(info));
420}

◆ add_to_table() [17/21]

void GncSqlColumnTableEntryImpl< CT_GDATE >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 506 of file gnc-sql-column-table-entry.cpp.

507{
508 GncSqlColumnInfo info{*this, BCT_DATE, DATE_COL_SIZE, FALSE};
509 vec.emplace_back(std::move(info));
510}

◆ add_to_table() [18/21]

void GncSqlColumnTableEntryImpl< CT_NUMERIC >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 579 of file gnc-sql-column-table-entry.cpp.

580{
581
582 for (auto const& subtable_row : numeric_col_table)
583 {
584 gchar* buf = g_strdup_printf("%s_%s", m_col_name,
585 subtable_row->m_col_name);
586 GncSqlColumnInfo info(buf, BCT_INT64, 0, false, false,
587 m_flags & COL_PKEY, m_flags & COL_NNUL);
588 g_free (buf);
589 vec.emplace_back(std::move(info));
590 }
591}

◆ add_to_table() [19/21]

void GncSqlColumnTableEntryImpl< CT_TAXTABLEREF >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 501 of file gnc-tax-table-sql.cpp.

502{
504}

◆ add_to_table() [20/21]

void GncSqlColumnTableEntryImpl< CT_TXREF >::add_to_table ( ColVec &  vec) const
virtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

Definition at line 822 of file gnc-transaction-sql.cpp.

823{
825}

◆ add_to_table() [21/21]

template<GncSqlObjectType Type>
void GncSqlColumnTableEntryImpl< Type >::add_to_table ( ColVec &  vec) const
overridevirtualnoexcept

Add a GncSqlColumnInfo structure for the column type to a ColVec.

Implements GncSqlColumnTableEntry.

◆ load() [1/21]

void GncSqlColumnTableEntryImpl< CT_ACCOUNTREF >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 349 of file gnc-account-sql.cpp.

353{
354 load_from_guid_ref(row, obj_name, pObject,
355 [sql_be](GncGUID* g){
356 return xaccAccountLookup(g, sql_be->book());
357 });
358}
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
The xaccAccountLookup() subroutine will return the account associated with the given id,...
Definition Account.cpp:2050
The type used to store guids in C.
Definition guid.h:75

◆ load() [2/21]

void GncSqlColumnTableEntryImpl< CT_ADDRESS >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 75 of file gnc-address-sql.cpp.

79{
80 g_return_if_fail (sql_be != NULL);
81 g_return_if_fail (pObject != NULL);
82
83 auto addr = gncAddressCreate (sql_be->book(), QOF_INSTANCE(pObject));
84
85 for (auto const& subtable_row : col_table)
86 {
87 auto buf = std::string{m_col_name} + "_" + subtable_row->m_col_name;
88 auto val = row.get_string_at_col (buf.c_str());
89 auto sub_setter = subtable_row->get_setter(GNC_ID_ADDRESS);
90 if (val)
91 set_parameter (addr, val->c_str(), sub_setter,
92 subtable_row->m_gobj_param_name);
93 }
94
95 set_parameter (pObject, addr,
96 reinterpret_cast<AddressSetterFunc>(get_setter(obj_name)),
97 m_gobj_param_name);
98}
QofSetterFunc get_setter(QofIdTypeConst obj_name) const noexcept
Retrieve the setter function depending on whether it's an auto-increment field, a QofClass getter,...

◆ load() [3/21]

void GncSqlColumnTableEntryImpl< CT_BILLTERMREF >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 333 of file gnc-bill-term-sql.cpp.

337{
338 load_from_guid_ref(row, obj_name, pObject,
339 [sql_be](GncGUID* g){
340 return gncBillTermLookup(sql_be->book(), g);
341 });
342}

◆ load() [4/21]

void GncSqlColumnTableEntryImpl< CT_BUDGETREF >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 457 of file gnc-budget-sql.cpp.

461{
462 load_from_guid_ref(row, obj_name, pObject,
463 [sql_be](GncGUID* g){
464 return gnc_budget_lookup (g, sql_be->book());
465 });
466}

◆ load() [5/21]

void GncSqlColumnTableEntryImpl< CT_COMMODITYREF >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 223 of file gnc-commodity-sql.cpp.

227{
228 load_from_guid_ref(row, obj_name, pObject,
229 [sql_be](GncGUID* g){
230 return gnc_commodity_find_commodity_by_guid(g, sql_be->book());
231 });
232}

◆ load() [6/21]

void GncSqlColumnTableEntryImpl< CT_INVOICEREF >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 282 of file gnc-invoice-sql.cpp.

286{
287 load_from_guid_ref(row, obj_name, pObject,
288 [sql_be](GncGUID* g){
289 return gncInvoiceLookup (sql_be->book(), g);
290 });
291}

◆ load() [7/21]

void GncSqlColumnTableEntryImpl< CT_LOTREF >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 195 of file gnc-lots-sql.cpp.

199{
200 load_from_guid_ref(row, obj_name, pObject,
201 [sql_be](GncGUID* g){
202 return gnc_lot_lookup(g, sql_be->book());
203 });
204}

◆ load() [8/21]

void GncSqlColumnTableEntryImpl< CT_ORDERREF >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 170 of file gnc-order-sql.cpp.

174{
175 load_from_guid_ref(row, obj_name, pObject,
176 [sql_be](GncGUID* g){
177 return gncOrderLookup(sql_be->book(), g);
178 });
179}

◆ load() [9/21]

void GncSqlColumnTableEntryImpl< CT_OWNERREF >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 50 of file gnc-owner-sql.cpp.

54{
55 GncOwnerType type;
56 GncGUID guid;
57 GncOwner owner;
58 GncGUID* pGuid = nullptr;
59
60 g_return_if_fail (sql_be != nullptr);
61 g_return_if_fail (pObject != nullptr);
62
63 auto book = sql_be->book();
64 auto buf = std::string{m_col_name} + "_type";
65 try
66 {
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());
70 if (val && string_to_guid (val->c_str(), &guid))
71 pGuid = &guid;
72 }
73 catch (std::invalid_argument&)
74 {
75 return;
76 }
77 if (type == GNC_OWNER_NONE || pGuid == nullptr)
78 return;
79
80 switch (type)
81 {
82 case GNC_OWNER_CUSTOMER:
83 {
84 GncCustomer* cust = NULL;
85
86 if (pGuid != NULL)
87 {
88 cust = gncCustomerLookup (book, pGuid);
89 if (cust == NULL)
90 {
91 cust = gncCustomerCreate (book);
92 gncCustomerSetGUID (cust, &guid);
93 }
94 }
95 gncOwnerInitCustomer (&owner, cust);
96 break;
97 }
98
99 case GNC_OWNER_JOB:
100 {
101 GncJob* job = NULL;
102
103 if (pGuid != NULL)
104 {
105 job = gncJobLookup (book, pGuid);
106 if (job == NULL)
107 {
108 job = gncJobCreate (book);
109 gncJobSetGUID (job, &guid);
110 }
111 }
112 gncOwnerInitJob (&owner, job);
113 break;
114 }
115
116 case GNC_OWNER_VENDOR:
117 {
118 GncVendor* vendor = NULL;
119
120 if (pGuid != NULL)
121 {
122 vendor = gncVendorLookup (book, pGuid);
123 if (vendor == NULL)
124 {
125 vendor = gncVendorCreate (book);
126 gncVendorSetGUID (vendor, &guid);
127 }
128 }
129 gncOwnerInitVendor (&owner, vendor);
130 break;
131 }
132
133 case GNC_OWNER_EMPLOYEE:
134 {
135 GncEmployee* employee = NULL;
136
137 if (pGuid != NULL)
138 {
139 employee = gncEmployeeLookup (book, pGuid);
140 if (employee == NULL)
141 {
142 employee = gncEmployeeCreate (book);
143 gncEmployeeSetGUID (employee, &guid);
144 }
145 }
146 gncOwnerInitEmployee (&owner, employee);
147 break;
148 }
149
150 default:
151 PWARN ("Invalid owner type: %d\n", type);
152 }
153 set_parameter (pObject, &owner, get_setter(obj_name), m_gobj_param_name);
154}
credit, discount and shipaddr are unique to GncCustomer id, name, notes, terms, addr,...

◆ load() [10/21]

void GncSqlColumnTableEntryImpl< CT_STRING >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 119 of file gnc-sql-column-table-entry.cpp.

123{
124 g_return_if_fail (pObject != NULL);
125 g_return_if_fail (m_gobj_param_name != NULL || get_setter(obj_name) != NULL);
126
127 auto s = row.get_string_at_col (m_col_name);
128 if (s)
129 set_parameter(pObject, s->c_str(), get_setter(obj_name), m_gobj_param_name);
130}

◆ load() [11/21]

void GncSqlColumnTableEntryImpl< CT_INT >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 164 of file gnc-sql-column-table-entry.cpp.

168{
169
170 g_return_if_fail (pObject != NULL);
171 g_return_if_fail (m_gobj_param_name != NULL || get_setter(obj_name) != NULL);
172
173 auto val = row.get_int_at_col(m_col_name);
174 if (val)
175 set_parameter(pObject, *val,
176 reinterpret_cast<IntSetterFunc>(get_setter(obj_name)),
177 m_gobj_param_name);
178}

◆ load() [12/21]

void GncSqlColumnTableEntryImpl< CT_BOOLEAN >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 200 of file gnc-sql-column-table-entry.cpp.

205{
206 g_return_if_fail (pObject != NULL);
207 g_return_if_fail (m_gobj_param_name != NULL || get_setter(obj_name) != NULL);
208
209 auto val = row.get_int_at_col (m_col_name);
210 if (val)
211 set_parameter(pObject, static_cast<int>(*val),
212 reinterpret_cast<BooleanSetterFunc>(get_setter(obj_name)),
213 m_gobj_param_name);
214}

◆ load() [13/21]

void GncSqlColumnTableEntryImpl< CT_INT64 >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 236 of file gnc-sql-column-table-entry.cpp.

241{
242 g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
243
244 auto val = row.get_int_at_col (m_col_name);
245 if (val)
246 set_parameter(pObject, *val,
247 reinterpret_cast<Int64SetterFunc>(get_setter(obj_name)),
248 m_gobj_param_name);
249}

◆ load() [14/21]

void GncSqlColumnTableEntryImpl< CT_DOUBLE >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 288 of file gnc-sql-column-table-entry.cpp.

293{
294 g_return_if_fail (pObject != NULL);
295 g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
296 double val{0.0};
297
298 if (auto int_val{row.get_int_at_col(m_col_name)})
299 val = static_cast<decltype(val)>(*int_val);
300 else if (auto float_val{row.get_float_at_col(m_col_name)})
301 val = static_cast<decltype(val)>(*float_val);
302 else if (auto double_val{row.get_double_at_col(m_col_name)})
303 val = *double_val;
304
305 set_parameter(pObject, val, get_setter(obj_name), m_gobj_param_name);
306}

◆ load() [15/21]

void GncSqlColumnTableEntryImpl< CT_GUID >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 326 of file gnc-sql-column-table-entry.cpp.

331{
332
333 GncGUID guid;
334
335 g_return_if_fail (pObject != NULL);
336 g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
337
338 auto strval{row.get_string_at_col(m_col_name)};
339 if (strval && string_to_guid (strval->c_str(), &guid))
340 set_parameter(pObject, &guid, get_setter(obj_name), m_gobj_param_name);
341}

◆ load() [16/21]

void GncSqlColumnTableEntryImpl< CT_TIME >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 371 of file gnc-sql-column-table-entry.cpp.

376{
377 time64 t{0};
378 g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
379 auto strval = row.get_string_at_col(m_col_name);
380 if (strval)
381 {
382 if (!strval->empty())
383 try
384 {
385 GncDateTime time(*strval);
386 t = static_cast<time64>(time);
387 }
388 catch (const std::invalid_argument& err)
389 {
390 PWARN("An invalid date %s was found in your database."
391 "It has been set to 1 January 1970.",
392 strval->c_str());
393 }
394 }
395 else
396 {
397 if (auto time64val = row.get_time64_at_col (m_col_name))
398 t = *time64val;
399 }
400
401 if (m_gobj_param_name != nullptr)
402 {
403 Time64 t64{t};
404 set_parameter(pObject, &t64, m_gobj_param_name);
405 }
406 else
407 {
408 set_parameter(pObject, t,
409 reinterpret_cast<Time64SetterFunc>(get_setter(obj_name)),
410 nullptr);
411 }
412}

◆ load() [17/21]

void GncSqlColumnTableEntryImpl< CT_GDATE >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 462 of file gnc-sql-column-table-entry.cpp.

466{
467 g_return_if_fail (pObject != NULL);
468 g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
469 if (row.is_col_null(m_col_name))
470 return;
471 GDate date;
472 g_date_clear (&date, 1);
473
474 auto strval{row.get_string_at_col(m_col_name)};
475 if (strval)
476 {
477 if (strval->empty())
478 return;
479 auto year = static_cast<GDateYear>(stoi (strval->substr (0,4)));
480 auto month = static_cast<GDateMonth>(stoi (strval->substr (4,2)));
481 auto day = static_cast<GDateDay>(stoi (strval->substr (6,2)));
482
483 if (year != 0 || month != 0 || day != (GDateDay)0)
484 g_date_set_dmy(&date, day, month, year);
485 }
486 else
487 {
488 auto timeval = row.get_time64_at_col(m_col_name);
489 if (!timeval)
490 return;
491 /* time64_to_gdate applies the tz, and gdates are saved
492 * as ymd, so we don't want that.
493 */
494 auto time = *timeval;
495 auto tm = gnc_gmtime(&time);
496 g_date_set_dmy(&date, tm->tm_mday,
497 static_cast<GDateMonth>(tm->tm_mon + 1),
498 tm->tm_year + 1900);
499 free(tm);
500 }
501
502 set_parameter(pObject, &date, get_setter(obj_name), m_gobj_param_name);
503}
struct tm * gnc_gmtime(const time64 *secs)
fill out a time struct from a 64-bit time value
Definition gnc-date.cpp:178

◆ load() [18/21]

void GncSqlColumnTableEntryImpl< CT_NUMERIC >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 552 of file gnc-sql-column-table-entry.cpp.

556{
557
558
559 g_return_if_fail (pObject != NULL);
560 g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
561
562 auto buf = g_strdup_printf ("%s_num", m_col_name);
563 auto num = row.get_int_at_col (buf);
564 g_free (buf);
565 buf = g_strdup_printf ("%s_denom", m_col_name);
566 auto denom = row.get_int_at_col (buf);
567 g_free (buf);
568
569 if (num && denom)
570 {
571 auto n = gnc_numeric_create (*num, *denom);
572 set_parameter(pObject, n,
573 reinterpret_cast<NumericSetterFunc>(get_setter(obj_name)),
574 m_gobj_param_name);
575 }
576}

◆ load() [19/21]

void GncSqlColumnTableEntryImpl< CT_TAXTABLEREF >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 489 of file gnc-tax-table-sql.cpp.

493{
494 load_from_guid_ref(row, obj_name, pObject,
495 [sql_be](GncGUID* g){
496 return gncTaxTableLookup(sql_be->book(), g);
497 });
498}

◆ load() [20/21]

void GncSqlColumnTableEntryImpl< CT_TXREF >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
gpointer  pObject 
) const
noexcept

Definition at line 790 of file gnc-transaction-sql.cpp.

794{
795 g_return_if_fail (sql_be != NULL);
796 g_return_if_fail (pObject != NULL);
797
798 auto val = row.get_string_at_col (m_col_name);
799 if (!val)
800 return;
801
802 GncGUID guid;
803 Transaction *tx = nullptr;
804 if (string_to_guid (val->c_str(), &guid))
805 tx = xaccTransLookup (&guid, sql_be->book());
806
807 // If the transaction is not found, try loading it
808 std::string tpkey(tx_col_table[0]->name());
809 if (tx == nullptr)
810 {
811 std::string sql = tpkey + " = '" + *val + "'";
812 query_transactions ((GncSqlBackend*)sql_be, sql);
813 tx = xaccTransLookup (&guid, sql_be->book());
814 }
815
816 if (tx != nullptr)
817 set_parameter (pObject, tx, get_setter(obj_name), m_gobj_param_name);
818
819}
Main SQL backend structure.
Transaction * xaccTransLookup(const GncGUID *guid, QofBook *book)
The xaccTransLookup() subroutine will return the transaction associated with the given id,...

◆ load() [21/21]

template<GncSqlObjectType Type>
void GncSqlColumnTableEntryImpl< Type >::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
void *  pObject 
) const
overridevirtualnoexcept

Load a value into an object from the database row.

Implements GncSqlColumnTableEntry.


The documentation for this class was generated from the following file: