Combine add_colname_to_list and add_gvalue_to_slist into single function add_value_to_vec.

The two lists were always used together so replace them with a single
vector of std::pair<std::string, std::string>; this also gets rid of the
intermediate GValue which was used to convert the returned value to a string.
operator<<() can do that for us more transparently.

Also template most of the add_value_to_vec functions.
This commit is contained in:
John Ralls 2016-03-12 11:32:27 -08:00
parent 96a8a7b99f
commit 7d4ca43fd0
16 changed files with 406 additions and 838 deletions

View File

@ -83,6 +83,7 @@ extern "C"
#include <boost/regex.hpp>
#include <string>
#include <gnc-datetime.hpp>
#include <gnc-backend-prov.hpp>
#include "gnc-backend-dbi.h"
#include "gnc-backend-dbi-priv.h"
@ -2194,16 +2195,16 @@ row_get_value_at_col_name (GncSqlRow* row, const gchar* col_name)
GncDbiSqlRow* dbi_row = (GncDbiSqlRow*)row;
gushort type;
guint attrs;
GValue* value;
GValue *value;
type = dbi_result_get_field_type (dbi_row->result, col_name);
attrs = dbi_result_get_field_attribs (dbi_row->result, col_name);
value = g_new0 (GValue, 1);
g_assert (value != NULL);
switch (type)
{
case DBI_TYPE_INTEGER:
value = g_new0 (GValue, 1);
g_assert (value != NULL);
(void)g_value_init (value, G_TYPE_INT64);
g_value_set_int64 (value, dbi_result_get_longlong (dbi_row->result, col_name));
break;
@ -2211,11 +2212,15 @@ row_get_value_at_col_name (GncSqlRow* row, const gchar* col_name)
gnc_push_locale (LC_NUMERIC, "C");
if ((attrs & DBI_DECIMAL_SIZEMASK) == DBI_DECIMAL_SIZE4)
{
value = g_new0 (GValue, 1);
g_assert (value != NULL);
(void)g_value_init (value, G_TYPE_FLOAT);
g_value_set_float (value, dbi_result_get_float (dbi_row->result, col_name));
}
else if ((attrs & DBI_DECIMAL_SIZEMASK) == DBI_DECIMAL_SIZE8)
{
value = g_new0 (GValue, 1);
g_assert (value != NULL);
(void)g_value_init (value, G_TYPE_DOUBLE);
g_value_set_double (value, dbi_result_get_double (dbi_row->result, col_name));
}
@ -2226,6 +2231,8 @@ row_get_value_at_col_name (GncSqlRow* row, const gchar* col_name)
gnc_pop_locale (LC_NUMERIC);
break;
case DBI_TYPE_STRING:
value = g_new0 (GValue, 1);
g_assert (value != NULL);
(void)g_value_init (value, G_TYPE_STRING);
g_value_take_string (value, dbi_result_get_string_copy (dbi_row->result,
col_name));
@ -2238,11 +2245,11 @@ row_get_value_at_col_name (GncSqlRow* row, const gchar* col_name)
else
{
#if HAVE_LIBDBI_TO_LONGLONG
/* A less evil hack than the one equrie by libdbi-0.8, but
* still necessary to work around the same bug.
*/
time64 time = dbi_result_get_as_longlong(dbi_row->result,
col_name);
/* A less evil hack than the one equrie by libdbi-0.8, but
* still necessary to work around the same bug.
*/
time64 time = dbi_result_get_as_longlong(dbi_row->result,
col_name);
#else
/* A seriously evil hack to work around libdbi bug #15
* https://sourceforge.net/p/libdbi/bugs/15/. When libdbi
@ -2253,14 +2260,18 @@ row_get_value_at_col_name (GncSqlRow* row, const gchar* col_name)
guint64 row = dbi_result_get_currow (result);
guint idx = dbi_result_get_field_idx (result, col_name) - 1;
time64 time = result->rows[row]->field_values[idx].d_datetime;
if (time < MINTIME || time > MAXTIME)
return nullptr;
value = g_new0 (GValue, 1);
g_assert (value != NULL);
#endif //HAVE_LIBDBI_TO_LONGLONG
(void)g_value_init (value, G_TYPE_INT64);
g_value_set_int64 (value, time);
}
break;
default:
PERR ("Field %s: unknown DBI_TYPE: %d\n", col_name, type);
g_free (value);
return NULL;
}
@ -2431,19 +2442,20 @@ stmt_to_sql (GncSqlStatement* stmt)
static void
stmt_add_where_cond(GncSqlStatement* stmt, QofIdTypeConst type_name,
gpointer obj, const GncSqlColumnTableEntry& table_row,
GValue* value )
gpointer obj, const PairVec& col_values)
{
GncDbiSqlStatement* dbi_stmt = (GncDbiSqlStatement*)stmt;
gchar* buf;
gchar* value_str;
value_str = gnc_sql_get_sql_value (dbi_stmt->conn, value);
buf = g_strdup_printf (" WHERE %s = %s", table_row.col_name,
value_str);
g_free (value_str);
(void)g_string_append (dbi_stmt->sql, buf);
g_free (buf);
GncDbiSqlStatement* dbi_stmt = reinterpret_cast<GncDbiSqlStatement*>(stmt);
std::ostringstream sql;
sql << " WHERE ";
for (auto colpair : col_values)
{
if (colpair != *col_values.begin())
sql << " AND ";
sql << colpair.first << " = " <<
gnc_sql_connection_quote_string (dbi_stmt->conn,
colpair.second.c_str());
}
(void)g_string_append (dbi_stmt->sql, sql.str().c_str());
}
static GncSqlStatement*
@ -3046,7 +3058,7 @@ conn_add_columns_to_table(GncSqlConnection* conn, const char* table_name,
}
static gchar*
conn_quote_string (const GncSqlConnection* conn, gchar* unquoted_str)
conn_quote_string (const GncSqlConnection* conn, const char* unquoted_str)
{
GncDbiSqlConnection* dbi_conn = (GncDbiSqlConnection*)conn;
gchar* quoted_str;

View File

@ -441,8 +441,7 @@ load_account_guid (const GncSqlBackend* be, GncSqlRow* row,
static GncSqlColumnTypeHandler account_guid_handler
= { load_account_guid,
gnc_sql_add_objectref_guid_col_info_to_list,
gnc_sql_add_colname_to_list,
gnc_sql_add_gvalue_objectref_guid_to_slist
gnc_sql_add_objectref_guid_to_vec
};
/* ================================================================= */
void

View File

@ -148,91 +148,33 @@ add_address_col_info_to_list(const GncSqlBackend* be,
}
static void
add_address_colname_to_list (const GncSqlColumnTableEntry& table_row,
GList** pList)
add_value_address_to_vec (const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
PairVec& vec)
{
gnc_sql_add_subtable_colnames_to_list (table_row, col_table, pList);
}
auto addr = get_row_value_from_object<GncAddress*>(obj_name, pObject,
table_row);
static void
get_gvalue_address (const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row, GValue* value)
{
AddressGetterFunc getter;
GncAddress* addr;
g_return_if_fail (be != NULL);
g_return_if_fail (obj_name != NULL);
g_return_if_fail (pObject != NULL);
memset (value, 0, sizeof (GValue));
if (table_row.gobj_param_name != NULL)
if (addr == nullptr)
return;
for (auto const& subtable_row : col_table)
{
g_object_get (pObject, table_row.gobj_param_name, &addr, NULL);
}
else
{
getter = (AddressGetterFunc)gnc_sql_get_getter (obj_name, table_row);
addr = (*getter) (pObject);
}
g_value_init (value, gnc_address_get_type ());
g_value_set_object (value, addr);
}
static void
add_gvalue_address_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
GSList** pList)
{
GValue value;
GValue* subfield_value;
GncAddress* addr;
gchar* s;
QofAccessFunc getter;
g_return_if_fail (be != NULL);
g_return_if_fail (obj_name != NULL);
g_return_if_fail (pObject != NULL);
memset (&value, 0, sizeof (GValue));
get_gvalue_address (be, obj_name, pObject, table_row, &value);
if (G_VALUE_TYPE (&value) != 0)
{
addr = static_cast<decltype(addr)>(g_value_get_object(&value));
for (auto const& subtable_row : col_table)
{
subfield_value = g_new0 (GValue, 1);
if (subtable_row.gobj_param_name != NULL)
{
g_object_get (addr, subtable_row.gobj_param_name, &s, NULL);
}
else
{
getter = gnc_sql_get_getter (GNC_ID_ADDRESS, subtable_row);
s = (gchar*) (*getter) (addr, NULL);
}
g_value_init (subfield_value, G_TYPE_STRING);
if (s)
{
g_value_set_string (subfield_value, s);
}
else
{
g_value_set_string (subfield_value, "NULL");
}
(*pList) = g_slist_append ((*pList), subfield_value);
}
auto s = get_row_value_from_object<char*>(GNC_ID_ADDRESS, addr,
subtable_row);
if (s == nullptr)
continue;
std::ostringstream buf;
buf << table_row.col_name << "_" << subtable_row.col_name;
vec.emplace_back(make_pair(buf.str(), std::string{s}));
}
}
static GncSqlColumnTypeHandler address_handler
= { load_address,
add_address_col_info_to_list,
add_address_colname_to_list,
add_gvalue_address_to_slist
add_value_address_to_vec
};
/* ================================================================= */

File diff suppressed because it is too large Load Diff

View File

@ -55,7 +55,8 @@ struct GncSqlColumnInfo;
struct GncSqlColumnTableEntry;
using EntryVec = std::vector<GncSqlColumnTableEntry>;
using ColVec = std::vector<GncSqlColumnInfo>;
using LoadOrder = std::vector<std::string>;
using StrVec = std::vector<std::string>;
using PairVec = std::vector<std::pair<std::string, std::string>>;
typedef struct GncSqlConnection GncSqlConnection;
/**
@ -153,14 +154,14 @@ struct GncSqlStatement
void (*dispose) (GncSqlStatement*);
gchar* (*toSql) (GncSqlStatement*);
void (*addWhereCond) (GncSqlStatement*, QofIdTypeConst, gpointer,
const GncSqlColumnTableEntry&, GValue*);
const PairVec&);
};
#define gnc_sql_statement_dispose(STMT) \
(STMT)->dispose(STMT)
#define gnc_sql_statement_to_sql(STMT) \
(STMT)->toSql(STMT)
#define gnc_sql_statement_add_where_cond(STMT,TYPENAME,OBJ,COLDESC,VALUE) \
(STMT)->addWhereCond(STMT, TYPENAME, OBJ, COLDESC, VALUE)
#define gnc_sql_statement_add_where_cond(STMT,TYPENAME,OBJ,COL_VAL_PAIR) \
(STMT)->addWhereCond(STMT, TYPENAME, OBJ, COL_VAL_PAIR)
/**
* @struct GncSqlConnection
@ -181,7 +182,7 @@ struct GncSqlConnection
gboolean (*createTable) (GncSqlConnection*, const gchar*, const ColVec&); /**< Returns TRUE if successful, FALSE if error */
gboolean (*createIndex) (GncSqlConnection*, const gchar*, const gchar*, const EntryVec&); /**< Returns TRUE if successful, FALSE if error */
gboolean (*addColumnsToTable) (GncSqlConnection*, const gchar* table, const ColVec&); /**< Returns TRUE if successful, FALSE if error */
gchar* (*quoteString) (const GncSqlConnection*, gchar*);
gchar* (*quoteString) (const GncSqlConnection*, const char*);
};
#define gnc_sql_connection_dispose(CONN) (CONN)->dispose(CONN)
#define gnc_sql_connection_execute_select_statement(CONN,STMT) \
@ -434,18 +435,17 @@ typedef enum
} E_DB_OPERATION;
typedef void (*GNC_SQL_LOAD_FN) (const GncSqlBackend* be,
GncSqlRow* row,
QofSetterFunc setter, gpointer pObject,
const GncSqlColumnTableEntry& table);
GncSqlRow* row, QofSetterFunc setter,
gpointer pObject,
const GncSqlColumnTableEntry& table_row);
typedef void (*GNC_SQL_ADD_COL_INFO_TO_LIST_FN) (const GncSqlBackend* be,
const GncSqlColumnTableEntry& table_row,
const GncSqlColumnTableEntry& table_row,
ColVec& vec);
typedef void (*GNC_SQL_ADD_COLNAME_TO_LIST_FN) (const GncSqlColumnTableEntry& table_row, GList** pList);
typedef void (*GNC_SQL_ADD_GVALUE_TO_SLIST_FN) (const GncSqlBackend* be,
QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
GSList** pList);
typedef void (*GNC_SQL_ADD_VALUE_TO_VEC_FN) (const GncSqlBackend* be,
QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
PairVec& vec);
/**
* @struct GncSqlColumnTypeHandler
@ -469,14 +469,11 @@ typedef struct
GNC_SQL_ADD_COL_INFO_TO_LIST_FN add_col_info_to_list_fn;
/**
* Routine to add a column name string for the column type to a GList.
* 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.
*/
GNC_SQL_ADD_COLNAME_TO_LIST_FN add_colname_to_list_fn;
/**
* Routine to add a GValue for the property to a GSList.
*/
GNC_SQL_ADD_GVALUE_TO_SLIST_FN add_gvalue_to_slist_fn;
GNC_SQL_ADD_VALUE_TO_VEC_FN add_value_to_vec_fn;
} GncSqlColumnTypeHandler;
/**
@ -489,16 +486,6 @@ typedef struct
QofAccessFunc gnc_sql_get_getter (QofIdTypeConst obj_name,
const GncSqlColumnTableEntry& table_row);
/**
* Adds a column name to a list. If the column type spans multiple columns,
* all of the column names for the pieces are added.
*
* @param table_row DB table column
* @param pList List
*/
void gnc_sql_add_colname_to_list (const GncSqlColumnTableEntry& table_row,
GList** pList);
/**
* Performs an operation on the database.
*
@ -691,11 +678,11 @@ void gnc_sql_register_col_type_handler (const gchar* colType,
* @param table_row DB table column description
* @param pList List
*/
void gnc_sql_add_gvalue_objectref_guid_to_slist (const GncSqlBackend* be,
QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
GSList** pList);
void gnc_sql_add_objectref_guid_to_vec (const GncSqlBackend* be,
QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
PairVec& vec);
/**
* Adds a column info structure for an object reference GncGUID to the end of a
@ -720,28 +707,6 @@ void gnc_sql_add_objectref_guid_col_info_to_list (const GncSqlBackend* be,
guint gnc_sql_append_guid_list_to_sql (GString* str, GList* list,
guint maxCount);
/**
* Appends column names for a subtable to the end of a GList.
*
* @param table_row Main DB column description
* @param subtable Sub-column description table
* @param pList List
*/
void gnc_sql_add_subtable_colnames_to_list (const GncSqlColumnTableEntry& table_row,
const EntryVec& subtable,
GList** pList);
/**
* Returns a string corresponding to the SQL representation of a GValue. The
* caller must free the string.
*
* @param conn SQL connection
* @param value Value to be converted
* @return String
*/
gchar* gnc_sql_get_sql_value (const GncSqlConnection* conn,
const GValue* value);
/**
* Initializes DB table version information.
*
@ -822,7 +787,7 @@ gboolean gnc_sql_add_columns_to_table (GncSqlBackend* be, const char* table_name
*
* @param load_order NULL-terminated array of object type ID strings
*/
void gnc_sql_set_load_order(LoadOrder&& load_order);
void gnc_sql_set_load_order(StrVec&& load_order);
void _retrieve_guid_ (gpointer pObject, gpointer pValue);
@ -836,6 +801,95 @@ typedef struct
gboolean is_ok;
} write_objects_t;
template <typename T> T
get_row_value_from_object(QofIdTypeConst obj_name, const gpointer pObject,
const GncSqlColumnTableEntry& table_row)
{
return get_row_value_from_object<T>(obj_name, pObject, table_row,
std::is_pointer<T>());
}
template <typename T> T
get_row_value_from_object(QofIdTypeConst obj_name, const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
std::true_type)
{
g_return_val_if_fail(obj_name != nullptr && pObject != nullptr, nullptr);
T result = nullptr;
if (table_row.gobj_param_name != nullptr)
g_object_get(pObject, table_row.gobj_param_name, &result, NULL );
else
{
QofAccessFunc getter = gnc_sql_get_getter(obj_name, table_row);
if (getter != nullptr)
result = reinterpret_cast<T>((getter)(pObject, nullptr));
}
return result;
}
template <typename T> T
get_row_value_from_object(QofIdTypeConst obj_name, const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
std::false_type)
{
g_return_val_if_fail(obj_name != nullptr && pObject != nullptr,
static_cast<T>(0));
T result = static_cast<T>(0);
if (table_row.gobj_param_name != nullptr)
g_object_get(pObject, table_row.gobj_param_name, &result, NULL );
else
{
QofAccessFunc getter = gnc_sql_get_getter(obj_name, table_row);
if (getter != nullptr)
result = reinterpret_cast<T>((getter)(pObject, nullptr));
}
return result;
}
template <typename T> void
add_value_to_vec(const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
PairVec& vec)
{
add_value_to_vec<T>(be, obj_name, pObject, table_row, vec,
std::is_pointer<T>());
}
template <typename T> void
add_value_to_vec(const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
PairVec& vec, std::true_type)
{
T s = get_row_value_from_object<T>(obj_name, pObject, table_row);
if (s != nullptr)
{
std::ostringstream stream;
stream << *s;
vec.emplace_back(std::make_pair(std::string{table_row.col_name},
stream.str()));
return;
}
}
template <typename T> void
add_value_to_vec(const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
PairVec& vec, std::false_type)
{
T s = get_row_value_from_object<T>(obj_name, pObject, table_row);
std::ostringstream stream;
stream << s;
vec.emplace_back(std::make_pair(std::string{table_row.col_name},
stream.str()));
return;
}
#endif /* GNC_BACKEND_SQL_H */
/**

View File

@ -390,8 +390,7 @@ load_billterm_guid (const GncSqlBackend* be, GncSqlRow* row,
static GncSqlColumnTypeHandler billterm_guid_handler
= { load_billterm_guid,
gnc_sql_add_objectref_guid_col_info_to_list,
gnc_sql_add_colname_to_list,
gnc_sql_add_gvalue_objectref_guid_to_slist
gnc_sql_add_objectref_guid_to_vec
};
/* ================================================================= */
void

View File

@ -522,8 +522,7 @@ load_budget_guid (const GncSqlBackend* be, GncSqlRow* row,
static GncSqlColumnTypeHandler budget_guid_handler
= { load_budget_guid,
gnc_sql_add_objectref_guid_col_info_to_list,
gnc_sql_add_colname_to_list,
gnc_sql_add_gvalue_objectref_guid_to_slist
gnc_sql_add_objectref_guid_to_vec
};
/* ================================================================= */
void

View File

@ -314,8 +314,7 @@ load_commodity_guid (const GncSqlBackend* be, GncSqlRow* row,
static GncSqlColumnTypeHandler commodity_guid_handler
= { load_commodity_guid,
gnc_sql_add_objectref_guid_col_info_to_list,
gnc_sql_add_colname_to_list,
gnc_sql_add_gvalue_objectref_guid_to_slist
gnc_sql_add_objectref_guid_to_vec
};
/* ================================================================= */
void

View File

@ -325,8 +325,7 @@ load_invoice_guid (const GncSqlBackend* be, GncSqlRow* row,
static GncSqlColumnTypeHandler invoice_guid_handler
= { load_invoice_guid,
gnc_sql_add_objectref_guid_col_info_to_list,
gnc_sql_add_colname_to_list,
gnc_sql_add_gvalue_objectref_guid_to_slist
gnc_sql_add_objectref_guid_to_vec
};
/* ================================================================= */
void

View File

@ -256,8 +256,7 @@ load_lot_guid (const GncSqlBackend* be, GncSqlRow* row,
static GncSqlColumnTypeHandler lot_guid_handler
= { load_lot_guid,
gnc_sql_add_objectref_guid_col_info_to_list,
gnc_sql_add_colname_to_list,
gnc_sql_add_gvalue_objectref_guid_to_slist
gnc_sql_add_objectref_guid_to_vec
};
/* ================================================================= */
void

View File

@ -240,8 +240,7 @@ load_order_guid (const GncSqlBackend* be, GncSqlRow* row,
static GncSqlColumnTypeHandler order_guid_handler
= { load_order_guid,
gnc_sql_add_objectref_guid_col_info_to_list,
gnc_sql_add_colname_to_list,
gnc_sql_add_gvalue_objectref_guid_to_slist
gnc_sql_add_objectref_guid_to_vec
};
/* ================================================================= */
void

View File

@ -191,50 +191,33 @@ add_owner_col_info_to_list(const GncSqlBackend* be,
}
static void
add_colname_to_list (const GncSqlColumnTableEntry& table_row, GList** pList)
add_value_owner_to_vec (const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
PairVec& vec)
{
gchar* buf;
buf = g_strdup_printf ("%s_type", table_row.col_name);
(*pList) = g_list_append ((*pList), buf);
buf = g_strdup_printf ("%s_guid", table_row.col_name);
(*pList) = g_list_append ((*pList), buf);
}
static void
add_gvalue_owner_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,
const gpointer pObject,
const GncSqlColumnTableEntry& table_row,
GSList** pList)
{
GValue* subfield_value;
GncOwner* owner;
gchar* buf;
const GncGUID* guid;
gchar guid_buf[GUID_ENCODING_LENGTH + 1];
GncOwnerType type;
QofInstance* inst = NULL;
OwnerGetterFunc getter;
g_return_if_fail (be != NULL);
g_return_if_fail (obj_name != NULL);
g_return_if_fail (pObject != NULL);
getter = (OwnerGetterFunc)gnc_sql_get_getter (obj_name, table_row);
owner = (*getter) (pObject);
auto getter = (OwnerGetterFunc)gnc_sql_get_getter (obj_name, table_row);
auto owner = (*getter) (pObject);
if (owner != NULL)
QofInstance* inst = nullptr;
GncOwnerType type;
std::ostringstream buf;
buf << table_row.col_name << "_type";
std::string type_hdr{buf.str()};
buf.str("");
buf << table_row.col_name << "_guid";
std::string guid_hdr{buf.str()};
buf.str("");
if (owner != nullptr)
{
buf = g_strdup_printf ("%s_type", table_row.col_name);
subfield_value = g_new0 (GValue, 1);
g_value_init (subfield_value, G_TYPE_INT);
type = gncOwnerGetType (owner);
g_value_set_int (subfield_value, type);
(*pList) = g_slist_append ((*pList), subfield_value);
g_free (buf);
buf = g_strdup_printf ("%s_guid", table_row.col_name);
subfield_value = g_new0 (GValue, 1);
switch (type)
{
case GNC_OWNER_CUSTOMER:
@ -256,37 +239,31 @@ add_gvalue_owner_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,
default:
PWARN ("Invalid owner type: %d\n", type);
}
g_value_init (subfield_value, G_TYPE_STRING);
if (inst != NULL)
{
guid = qof_instance_get_guid (inst);
if (guid != NULL)
{
(void)guid_to_string_buff (guid, guid_buf);
g_value_take_string (subfield_value, g_strdup_printf ("%s", guid_buf));
}
}
(*pList) = g_slist_append ((*pList), subfield_value);
g_free (buf);
}
else
if (inst == nullptr)
{
subfield_value = g_new0 (GValue, 1);
g_value_init (subfield_value, G_TYPE_STRING);
g_value_set_string (subfield_value, "NULL");
(*pList) = g_slist_append ((*pList), subfield_value);
subfield_value = g_new0 (GValue, 1);
g_value_init (subfield_value, G_TYPE_STRING);
g_value_set_string (subfield_value, "NULL");
(*pList) = g_slist_append ((*pList), subfield_value);
/* Twice, once for type, once for guid. */
vec.emplace_back (std::make_pair (type_hdr, std::string{"NULL"}));
vec.emplace_back (std::make_pair (guid_hdr, std::string{"NULL"}));
return;
}
buf << type;
vec.emplace_back(std::make_pair(type_hdr, buf.str()));
buf.str("");
auto guid = qof_instance_get_guid(inst);
if (guid != nullptr)
buf << guid;
else
buf << "NULL";
vec.emplace_back(std::make_pair(guid_hdr, buf.str()));
}
static GncSqlColumnTypeHandler owner_handler
= { load_owner,
add_owner_col_info_to_list,
add_colname_to_list,
add_gvalue_owner_to_slist
add_value_owner_to_vec
};
/* ================================================================= */

View File

@ -546,8 +546,7 @@ load_taxtable_guid (const GncSqlBackend* be, GncSqlRow* row,
static GncSqlColumnTypeHandler taxtable_guid_handler
= { load_taxtable_guid,
gnc_sql_add_objectref_guid_col_info_to_list,
gnc_sql_add_colname_to_list,
gnc_sql_add_gvalue_objectref_guid_to_slist
gnc_sql_add_objectref_guid_to_vec
};
/* ================================================================= */
void

View File

@ -1491,8 +1491,7 @@ load_tx_guid (const GncSqlBackend* be, GncSqlRow* row,
static GncSqlColumnTypeHandler tx_guid_handler
= { load_tx_guid,
gnc_sql_add_objectref_guid_col_info_to_list,
gnc_sql_add_colname_to_list,
gnc_sql_add_gvalue_objectref_guid_to_slist
gnc_sql_add_objectref_guid_to_vec
};
/* ================================================================= */
void

View File

@ -556,12 +556,12 @@ test_add_gvalue_guid_to_slist (Fixture *fixture, gconstpointer pData)
{
}*/
// Not Used
/* gnc_sql_add_gvalue_objectref_guid_to_slist
/* gnc_sql_add_objectref_guid_to_vec
void
gnc_sql_add_gvalue_objectref_guid_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,// 1
gnc_sql_add_objectref_guid_to_vec (const GncSqlBackend* be, QofIdTypeConst obj_name,// 1
*/
/* static void
test_gnc_sql_add_gvalue_objectref_guid_to_slist (Fixture *fixture, gconstpointer pData)
test_gnc_sql_add_objectref_guid_to_vec (Fixture *fixture, gconstpointer pData)
{
}*/
// Not Used
@ -624,12 +624,12 @@ add_timespec_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableE
test_add_timespec_col_info_to_list (Fixture *fixture, gconstpointer pData)
{
}*/
/* add_gvalue_timespec_to_slist
/* add_value_timespec_to_vec
static void
add_gvalue_timespec_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,// 2
*/
/* static void
test_add_gvalue_timespec_to_slist (Fixture *fixture, gconstpointer pData)
test_add_value_timespec_to_vec (Fixture *fixture, gconstpointer pData)
{
}*/
/* load_date
@ -648,12 +648,12 @@ add_date_col_info_to_list (const GncSqlBackend* be, const GncSqlColumnTableEntry
test_add_date_col_info_to_list (Fixture *fixture, gconstpointer pData)
{
}*/
/* add_gvalue_date_to_slist
/* add_value_date_to_vec
static void
add_gvalue_date_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,// 2
add_value_date_to_vec (const GncSqlBackend* be, QofIdTypeConst obj_name,// 2
*/
/* static void
test_add_gvalue_date_to_slist (Fixture *fixture, gconstpointer pData)
test_add_value_date_to_vec (Fixture *fixture, gconstpointer pData)
{
}*/
/* load_numeric
@ -680,12 +680,12 @@ add_numeric_colname_to_list (const GncSqlColumnTableEntry& table_row, GList** pL
test_add_numeric_colname_to_list (Fixture *fixture, gconstpointer pData)
{
}*/
/* add_gvalue_numeric_to_slist
/* add_value_numeric_to_vec
static void
add_gvalue_numeric_to_slist (const GncSqlBackend* be, QofIdTypeConst obj_name,// 2
add_value_numeric_to_vec (const GncSqlBackend* be, QofIdTypeConst obj_name,// 2
*/
/* static void
test_add_gvalue_numeric_to_slist (Fixture *fixture, gconstpointer pData)
test_add_value_numeric_to_vec (Fixture *fixture, gconstpointer pData)
{
}*/
/* get_handler
@ -980,36 +980,36 @@ test_suite_gnc_backend_sql (void)
// GNC_TEST_ADD (suitename, "gnc sql add subtable colnames to list", Fixture, nullptr, test_gnc_sql_add_subtable_colnames_to_list, teardown);
// GNC_TEST_ADD (suitename, "load string", Fixture, nullptr, test_load_string, teardown);
// GNC_TEST_ADD (suitename, "add string col info to list", Fixture, nullptr, test_add_string_col_info_to_list, teardown);
// GNC_TEST_ADD (suitename, "add gvalue string to slist", Fixture, nullptr, test_add_gvalue_string_to_slist, teardown);
// GNC_TEST_ADD (suitename, "add value string to vec", Fixture, nullptr, test_add_value_string_to_vec, teardown);
// GNC_TEST_ADD (suitename, "load int", Fixture, nullptr, test_load_int, teardown);
// GNC_TEST_ADD (suitename, "add int col info to list", Fixture, nullptr, test_add_int_col_info_to_list, teardown);
// GNC_TEST_ADD (suitename, "add gvalue int to slist", Fixture, nullptr, test_add_gvalue_int_to_slist, teardown);
// GNC_TEST_ADD (suitename, "add value int to vec", Fixture, nullptr, test_add_value_int_to_vec, teardown);
// GNC_TEST_ADD (suitename, "load boolean", Fixture, nullptr, test_load_boolean, teardown);
// GNC_TEST_ADD (suitename, "add boolean col info to list", Fixture, nullptr, test_add_boolean_col_info_to_list, teardown);
// GNC_TEST_ADD (suitename, "add gvalue boolean to slist", Fixture, nullptr, test_add_gvalue_boolean_to_slist, teardown);
// GNC_TEST_ADD (suitename, "add value boolean to vec", Fixture, nullptr, test_add_value_boolean_to_vec, teardown);
// GNC_TEST_ADD (suitename, "load int64", Fixture, nullptr, test_load_int64, teardown);
// GNC_TEST_ADD (suitename, "add int64 col info to list", Fixture, nullptr, test_add_int64_col_info_to_list, teardown);
// GNC_TEST_ADD (suitename, "add gvalue int64 to slist", Fixture, nullptr, test_add_gvalue_int64_to_slist, teardown);
// GNC_TEST_ADD (suitename, "add value int64 to vec", Fixture, nullptr, test_add_value_int64_to_vec, teardown);
// GNC_TEST_ADD (suitename, "load double", Fixture, nullptr, test_load_double, teardown);
// GNC_TEST_ADD (suitename, "add double col info to list", Fixture, nullptr, test_add_double_col_info_to_list, teardown);
// GNC_TEST_ADD (suitename, "add gvalue double to slist", Fixture, nullptr, test_add_gvalue_double_to_slist, teardown);
// GNC_TEST_ADD (suitename, "add value double to vec", Fixture, nullptr, test_add_value_double_to_vec, teardown);
// GNC_TEST_ADD (suitename, "load guid", Fixture, nullptr, test_load_guid, teardown);
// GNC_TEST_ADD (suitename, "add guid col info to list", Fixture, nullptr, test_add_guid_col_info_to_list, teardown);
// GNC_TEST_ADD (suitename, "add gvalue guid to slist", Fixture, nullptr, test_add_gvalue_guid_to_slist, teardown);
// GNC_TEST_ADD (suitename, "gnc sql add gvalue objectref guid to slist", Fixture, nullptr, test_gnc_sql_add_gvalue_objectref_guid_to_slist, teardown);
// GNC_TEST_ADD (suitename, "add value guid to vec", Fixture, nullptr, test_add_value_guid_to_vec, teardown);
// GNC_TEST_ADD (suitename, "gnc sql add gvalue objectref guid to slist", Fixture, nullptr, test_gnc_sql_add_objectref_guid_to_vec, teardown);
// GNC_TEST_ADD (suitename, "gnc sql add objectref guid col info to list", Fixture, nullptr, test_gnc_sql_add_objectref_guid_col_info_to_list, teardown);
GNC_TEST_ADD_FUNC (suitename, "gnc sql convert timespec to string",
test_gnc_sql_convert_timespec_to_string);
// GNC_TEST_ADD (suitename, "load timespec", Fixture, nullptr, test_load_timespec, teardown);
// GNC_TEST_ADD (suitename, "add timespec col info to list", Fixture, nullptr, test_add_timespec_col_info_to_list, teardown);
// GNC_TEST_ADD (suitename, "add gvalue timespec to slist", Fixture, nullptr, test_add_gvalue_timespec_to_slist, teardown);
// GNC_TEST_ADD (suitename, "add value timespec to vec", Fixture, nullptr, test_add_value_timespec_to_vec, teardown);
// GNC_TEST_ADD (suitename, "load date", Fixture, nullptr, test_load_date, teardown);
// GNC_TEST_ADD (suitename, "add date col info to list", Fixture, nullptr, test_add_date_col_info_to_list, teardown);
// GNC_TEST_ADD (suitename, "add gvalue date to slist", Fixture, nullptr, test_add_gvalue_date_to_slist, teardown);
// GNC_TEST_ADD (suitename, "add value date to vec", Fixture, nullptr, test_add_value_date_to_vec, teardown);
// GNC_TEST_ADD (suitename, "load numeric", Fixture, nullptr, test_load_numeric, teardown);
// GNC_TEST_ADD (suitename, "add numeric col info to list", Fixture, nullptr, test_add_numeric_col_info_to_list, teardown);
// GNC_TEST_ADD (suitename, "add numeric colname to list", Fixture, nullptr, test_add_numeric_colname_to_list, teardown);
// GNC_TEST_ADD (suitename, "add gvalue numeric to slist", Fixture, nullptr, test_add_gvalue_numeric_to_slist, teardown);
// GNC_TEST_ADD (suitename, "add value numeric to vec", Fixture, nullptr, test_add_value_numeric_to_vec, teardown);
// GNC_TEST_ADD (suitename, "get handler", Fixture, nullptr, test_get_handler, teardown);
// GNC_TEST_ADD (suitename, "register standard col type handlers", Fixture, nullptr, test_register_standard_col_type_handlers, teardown);
// GNC_TEST_ADD (suitename, " retrieve guid ", Fixture, nullptr, test__retrieve_guid_, teardown);

View File

@ -39,6 +39,8 @@ typedef struct
class GncDateImpl;
class GncDateTimeImpl;
using time64 = int64_t;
constexpr const time64 MINTIME = -17987443200;
constexpr const time64 MAXTIME = 253402214400;
class GncDate
{