GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Friends
GncSqlColumnTableEntry Class Referenceabstract

Contains all of the information required to copy information between an object and the database for a specific object property. More...

#include <gnc-sql-column-table-entry.hpp>

Inheritance diagram for GncSqlColumnTableEntry:
GncSqlColumnTableEntryImpl< Type >

Public Member Functions

 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)
 
virtual void load (const GncSqlBackend *sql_be, GncSqlRow &row, QofIdTypeConst obj_name, void *pObject) const noexcept=0
 Load a value into an object from the database row.
 
virtual void add_to_table (ColVec &vec) const noexcept=0
 Add a GncSqlColumnInfo structure for the column type to a ColVec.
 
virtual void add_to_query (QofIdTypeConst obj_name, void *pObject, PairVec &vec) const noexcept=0
 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.
 
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
 

Protected Member Functions

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
 

Friends

template<GncSqlObjectType Otype>
class GncSqlColumnTableEntryImpl
 
struct GncSqlColumnInfo
 

Detailed Description

Contains all of the information required to copy information between an object and the database for a specific object property.

If an entry contains a gobj_param_name value, this string is used as the property name for a call to g_object_get() or g_object_set(). If the gobj_param_name value is NULL but qof_param_name is not NULL, this value is used as the parameter name for a call to qof_class_get_parameter_getter(). If both of these values are NULL, getter and setter are the addresses of routines to return or set the parameter value, respectively.

The database description for an object consists of an array of GncSqlColumnTableEntry objects, with a final member having col_name == NULL.

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

Constructor & Destructor Documentation

◆ GncSqlColumnTableEntry()

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 
)
inline

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

134 :
135 m_col_name{name}, m_col_type{type}, m_size{s},
136 m_flags{static_cast<ColumnFlags>(f)},
137 m_gobj_param_name{gobj_name}, m_qof_param_name{qof_name}, m_getter{get},
138 m_setter{set} {}
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_objectref_guid_to_query()

void GncSqlColumnTableEntry::add_objectref_guid_to_query ( QofIdTypeConst  obj_name,
const void *  pObject,
PairVec &  vec 
) const
protectednoexcept

Adds a name/guid std::pair to a PairVec for creating a query.

Parameters
sql_beSQL backend struct
obj_nameQOF object type name
pObjectObject
pListList

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

98{
99 auto inst = get_row_value_from_object<QofInstance*>(obj_name, pObject);
100 if (inst == nullptr) return;
101 auto guid = qof_instance_get_guid (inst);
102 if (guid != nullptr) {
103 gchar *guid_s = guid_to_string(guid);
104 vec.emplace_back (std::make_pair (std::string{m_col_name}, quote_string(guid_s)));
105 g_free(guid_s);
106 }
107}
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
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.

◆ add_objectref_guid_to_table()

void GncSqlColumnTableEntry::add_objectref_guid_to_table ( ColVec &  vec) const
protectednoexcept

Adds a column info structure for an object reference GncGUID to a ColVec.

Parameters
sql_beSQL backend struct
pListList

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

111{
112 GncSqlColumnInfo info{*this, BCT_STRING, GUID_ENCODING_LENGTH, FALSE};
113 vec.emplace_back(std::move(info));
114}
#define GUID_ENCODING_LENGTH
Number of characters needed to encode a guid as a string not including the null terminator.
Definition guid.h:84
information required to create a column in a table.

◆ add_to_query()

virtual void GncSqlColumnTableEntry::add_to_query ( QofIdTypeConst  obj_name,
void *  pObject,
PairVec &  vec 
) const
pure virtualnoexcept

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.

Implemented in GncSqlColumnTableEntryImpl< Type >.

◆ add_to_table()

virtual void GncSqlColumnTableEntry::add_to_table ( ColVec &  vec) const
pure virtualnoexcept

◆ add_value_to_vec() [1/3]

template<typename T >
void GncSqlColumnTableEntry::add_value_to_vec ( QofIdTypeConst  obj_name,
const void *  pObject,
PairVec &  vec 
) const
protected

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

382{
383 add_value_to_vec<T>(obj_name, pObject, vec, std::is_pointer<T>());
384}

◆ add_value_to_vec() [2/3]

template<>
void GncSqlColumnTableEntry::add_value_to_vec ( QofIdTypeConst  obj_name,
const void *  pObject,
PairVec &  vec,
std::false_type   
) const
inlineprotected

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

435{
436 double s = *get_row_value_from_object<double*>(obj_name, pObject);
437
438 std::ostringstream stream;
439 stream << std::setprecision(12) << std::fixed << s;
440 vec.emplace_back(std::make_pair(std::string{m_col_name}, stream.str()));
441 return;
442}

◆ add_value_to_vec() [3/3]

template<>
void GncSqlColumnTableEntry::add_value_to_vec ( QofIdTypeConst  obj_name,
const void *  pObject,
PairVec &  vec,
std::true_type   
) const
inlineprotected

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

406{
407 double* s = get_row_value_from_object<double*>(obj_name, pObject);
408
409 if (s != nullptr)
410 {
411 std::ostringstream stream;
412 stream << std::setprecision(12) << std::fixed << *s;
413 vec.emplace_back(std::make_pair(std::string{m_col_name}, stream.str()));
414 return;
415 }
416}

◆ get_getter()

QofAccessFunc GncSqlColumnTableEntry::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.

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

53{
54 QofAccessFunc getter;
55
56 g_return_val_if_fail (obj_name != NULL, NULL);
57
58 if (m_flags & COL_AUTOINC)
59 {
60 getter = get_autoinc_id;
61 }
62 else if (m_qof_param_name != NULL)
63 {
64 getter = qof_class_get_parameter_getter (obj_name, m_qof_param_name);
65 }
66 else
67 {
68 getter = m_getter;
69 }
70
71 return getter;
72}
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
The QofAccessFunc defines an arbitrary function pointer for access functions.
Definition qofclass.h:123
QofAccessFunc qof_class_get_parameter_getter(QofIdTypeConst obj_name, const char *parameter)
Return the object's parameter getter function.
Definition qofclass.cpp:156

◆ get_row_value_from_object() [1/2]

template<>
gint64 GncSqlColumnTableEntry::get_row_value_from_object ( QofIdTypeConst  obj_name,
const void *  pObject 
) const
protected

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

262{
263 g_return_val_if_fail(obj_name != nullptr && pObject != nullptr,
264 INT64_C(0));
265 int64_t result = INT64_C(0);
266 if (m_gobj_param_name != nullptr)
267 g_object_get(const_cast<void*>(pObject), m_gobj_param_name,
268 &result, nullptr);
269 else
270 {
271 auto getter = (Int64AccessFunc)get_getter(obj_name);
272 if (getter != nullptr)
273 result = (getter)(const_cast<void*>(pObject));
274 }
275 return result;
276}
QofAccessFunc get_getter(QofIdTypeConst obj_name) const noexcept
Retrieve the getter function depending on whether it's an auto-increment field, a QofClass getter,...

◆ get_row_value_from_object() [2/2]

template<typename T >
T GncSqlColumnTableEntry::get_row_value_from_object ( QofIdTypeConst  obj_name,
const void *  pObject 
) const
protected

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

330{
331 return get_row_value_from_object<T>(obj_name, pObject,
332 std::is_pointer<T>());
333}

◆ get_setter()

QofSetterFunc GncSqlColumnTableEntry::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.

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

76{
77 QofSetterFunc setter = nullptr;
78 if (m_flags & COL_AUTOINC)
79 {
80 setter = set_autoinc_id;
81 }
82 else if (m_qof_param_name != nullptr)
83 {
84 g_assert (obj_name != NULL);
85 setter = qof_class_get_parameter_setter (obj_name, m_qof_param_name);
86 }
87 else
88 {
89 setter = m_setter;
90 }
91 return setter;
92}
void(* QofSetterFunc)(gpointer, gpointer)
The QofSetterFunc defines an function pointer for parameter setters.
Definition qofclass.h:130
QofSetterFunc qof_class_get_parameter_setter(QofIdTypeConst obj_name, const char *parameter)
Return the object's parameter setter function.
Definition qofclass.cpp:172

◆ is_autoincr()

bool GncSqlColumnTableEntry::is_autoincr ( ) const
inlinenoexcept

Report if the entry is an auto-increment field.

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

176{ return m_flags & COL_AUTOINC; }

◆ load()

virtual void GncSqlColumnTableEntry::load ( const GncSqlBackend sql_be,
GncSqlRow row,
QofIdTypeConst  obj_name,
void *  pObject 
) const
pure virtualnoexcept

Load a value into an object from the database row.

Implemented in GncSqlColumnTableEntryImpl< Type >.

◆ load_from_guid_ref()

template<typename T >
void GncSqlColumnTableEntry::load_from_guid_ref ( GncSqlRow row,
QofIdTypeConst  obj_name,
void *  pObject,
get_ref 
) const
inlinenoexcept

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

186 {
187 static QofLogModule log_module = G_LOG_DOMAIN;
188 g_return_if_fail (pObject != NULL);
189
190 GncGUID guid;
191 auto val = row.get_string_at_col (m_col_name);
192 if (!val)
193 {
194 DEBUG("set parameter: No string in column %s.", m_col_name);
195 return;
196 }
197
198 if (string_to_guid (val->c_str(), &guid))
199 {
200 auto target = get_ref(&guid);
201 if (target != nullptr)
202 set_parameter (pObject, target, get_setter(obj_name),
203 m_gobj_param_name);
204 else
205 DEBUG("GUID %s returned null %s reference.",
206 val->c_str(), m_gobj_param_name);
207 }
208 else
209 {
210 if (val->empty())
211 DEBUG("Can't load empty guid string for column %s", m_col_name);
212 else
213 DEBUG("Invalid GUID %s for column %s", val->c_str(), m_col_name);
214 }
215 }
QofSetterFunc get_setter(QofIdTypeConst obj_name) const noexcept
Retrieve the setter function depending on whether it's an auto-increment field, a QofClass getter,...
#define DEBUG(format, args...)
Print a debugging message.
Definition qoflog.h:264
The type used to store guids in C.
Definition guid.h:75

◆ name()

const char * GncSqlColumnTableEntry::name ( ) const
inlinenoexcept

Retrieve the field name so that we don't need to make create_single_col_select_statement and friend.

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

172{ return m_col_name; }

Friends And Related Symbol Documentation

◆ GncSqlColumnInfo

friend struct GncSqlColumnInfo
friend

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

◆ GncSqlColumnTableEntryImpl

template<GncSqlObjectType Otype>
friend class GncSqlColumnTableEntryImpl
friend

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


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