Remove Timespec from the SQL backend.

This commit is contained in:
John Ralls 2018-08-04 14:18:39 -07:00
parent 755773ac4c
commit 20f6e4e690
11 changed files with 71 additions and 163 deletions

View File

@ -138,7 +138,7 @@ setup_memory (Fixture* fixture, gconstpointer pData)
frame->set ({"int64-val"}, new KvpValue (INT64_C (100)));
frame->set ({"double-val"}, new KvpValue (3.14159));
frame->set ({"numeric-val"}, new KvpValue (gnc_numeric_zero ()));
frame->set ({"timespec-val"}, new KvpValue (gnc_time(nullptr)));
frame->set ({"time-val"}, new KvpValue (gnc_time(nullptr)));
frame->set ({"string-val"}, new KvpValue ("abcdefghijklmnop"));
auto guid = qof_instance_get_guid (QOF_INSTANCE (acct1));
frame->set ({"guid-val"}, new KvpValue (const_cast<GncGUID*> (guid_copy (

View File

@ -70,9 +70,9 @@ static void entry_set_bill (gpointer pObject, gpointer val);
static EntryVec col_table
({
gnc_sql_make_table_entry<CT_GUID>("guid", 0, COL_NNUL | COL_PKEY, "guid"),
gnc_sql_make_table_entry<CT_TIME64>("date", 0, COL_NNUL, ENTRY_DATE,
gnc_sql_make_table_entry<CT_TIME>("date", 0, COL_NNUL, ENTRY_DATE,
true),
gnc_sql_make_table_entry<CT_TIME64>("date_entered", 0, 0,
gnc_sql_make_table_entry<CT_TIME>("date_entered", 0, 0,
ENTRY_DATE_ENTERED, true),
gnc_sql_make_table_entry<CT_STRING>(
"description", MAX_DESCRIPTION_LEN, 0, "description"),

View File

@ -67,9 +67,9 @@ static EntryVec col_table
gnc_sql_make_table_entry<CT_GUID>("guid", 0, COL_NNUL | COL_PKEY, "guid"),
gnc_sql_make_table_entry<CT_STRING>("id", MAX_ID_LEN, COL_NNUL, INVOICE_ID,
true),
gnc_sql_make_table_entry<CT_TIME64>("date_opened", 0, 0, INVOICE_OPENED,
gnc_sql_make_table_entry<CT_TIME>("date_opened", 0, 0, INVOICE_OPENED,
true),
gnc_sql_make_table_entry<CT_TIME64>("date_posted", 0, 0, INVOICE_POSTED,
gnc_sql_make_table_entry<CT_TIME>("date_posted", 0, 0, INVOICE_POSTED,
true),
gnc_sql_make_table_entry<CT_STRING>("notes", MAX_NOTES_LEN, COL_NNUL,
"notes"),

View File

@ -66,9 +66,9 @@ static EntryVec col_table
gnc_sql_make_table_entry<CT_STRING>(
"reference", MAX_REFERENCE_LEN, COL_NNUL, "reference"),
gnc_sql_make_table_entry<CT_BOOLEAN>("active", 0, COL_NNUL, "order"),
gnc_sql_make_table_entry<CT_TIMESPEC>("date_opened", 0, COL_NNUL,
gnc_sql_make_table_entry<CT_TIME>("date_opened", 0, COL_NNUL,
"date-opened"),
gnc_sql_make_table_entry<CT_TIMESPEC>("date_closed", 0, COL_NNUL,
gnc_sql_make_table_entry<CT_TIME>("date_closed", 0, COL_NNUL,
"date-closed"),
gnc_sql_make_table_entry<CT_OWNERREF>("owner", 0, COL_NNUL,
ORDER_OWNER, true),

View File

@ -63,7 +63,7 @@ static const EntryVec col_table
"commodity"),
gnc_sql_make_table_entry<CT_COMMODITYREF>("currency_guid", 0, COL_NNUL,
"currency"),
gnc_sql_make_table_entry<CT_TIMESPEC>("date", 0, COL_NNUL, "date"),
gnc_sql_make_table_entry<CT_TIME>("date", 0, COL_NNUL, "date"),
gnc_sql_make_table_entry<CT_STRING>("source", PRICE_MAX_SOURCE_LEN, 0,
"source"),
gnc_sql_make_table_entry<CT_STRING>("type", PRICE_MAX_TYPE_LEN, 0, "type"),

View File

@ -90,8 +90,8 @@ static gpointer get_string_val (gpointer pObject);
static void set_string_val (gpointer pObject, gpointer pValue);
static gpointer get_double_val (gpointer pObject);
static void set_double_val (gpointer pObject, gpointer pValue);
static Timespec get_timespec_val (gpointer pObject);
static void set_timespec_val (gpointer pObject, Timespec *ts);
static time64 get_time_val (gpointer pObject);
static void set_time_val (gpointer pObject, time64 t);
static gpointer get_guid_val (gpointer pObject);
static void set_guid_val (gpointer pObject, gpointer pValue);
static gnc_numeric get_numeric_val (gpointer pObject);
@ -112,7 +112,7 @@ enum
int64_val_col,
string_val_col,
double_val_col,
timespec_val_col,
time_val_col,
guid_val_col,
numeric_val_col,
gdate_val_col
@ -140,9 +140,9 @@ static const EntryVec col_table
gnc_sql_make_table_entry<CT_DOUBLE>("double_val", 0, 0,
(QofAccessFunc)get_double_val,
set_double_val),
gnc_sql_make_table_entry<CT_TIMESPEC>("timespec_val", 0, 0,
(QofAccessFunc)get_timespec_val,
(QofSetterFunc)set_timespec_val),
gnc_sql_make_table_entry<CT_TIME>("time_val", 0, 0,
(QofAccessFunc)get_time_val,
(QofSetterFunc)set_time_val),
gnc_sql_make_table_entry<CT_GUID>("guid_val", 0, 0,
(QofAccessFunc)get_guid_val,
set_guid_val),
@ -390,24 +390,24 @@ set_double_val (gpointer pObject, gpointer pValue)
set_slot_from_value (pInfo, value);
}
static Timespec
get_timespec_val (gpointer pObject)
static time64
get_time_val (gpointer pObject)
{
slot_info_t* pInfo = (slot_info_t*)pObject;
g_return_val_if_fail (pObject != NULL, gnc_dmy2timespec (1, 1, 1970));
g_return_val_if_fail (pObject != NULL, 0);
//if( kvp_value_get_type( pInfo->pKvpValue ) == KvpValue::Type::TIME64 ) {
auto t = pInfo->pKvpValue->get<Time64> ();
return {t.t, 0};
return t.t;
}
static void
set_timespec_val (gpointer pObject, Timespec *ts)
set_time_val (gpointer pObject, time64 time)
{
slot_info_t* pInfo = (slot_info_t*)pObject;
KvpValue* value = NULL;
Time64 t{ts->tv_sec};
Time64 t{time};
g_return_if_fail (pObject != NULL);
if (pInfo->value_type != KvpValue::Type::TIME64) return;

View File

@ -246,7 +246,7 @@ protected:
bool m_loading; /**< We are performing an initial load */
bool m_in_query; /**< We are processing a query */
bool m_is_pristine_db; /**< Are we saving to a new pristine db? */
const char* m_timespec_format = nullptr; /**< Server-specific date-time string format */
const char* m_time_format = nullptr; /**< Server-specific date-time string format */
VersionVec m_versions; /**< Version number for each table */
private:
bool write_account_tree(Account*);

View File

@ -367,111 +367,18 @@ GncSqlColumnTableEntryImpl<CT_GUID>::add_to_query(QofIdTypeConst obj_name,
}
}
/* ----------------------------------------------------------------- */
typedef Timespec (*TimespecAccessFunc) (const gpointer);
typedef void (*TimespecSetterFunc) (const gpointer, Timespec*);
#define TIMESPEC_COL_SIZE (4+3+3+3+3+3)
template<> void
GncSqlColumnTableEntryImpl<CT_TIMESPEC>::load (const GncSqlBackend* sql_be,
GncSqlRow& row,
QofIdTypeConst obj_name,
gpointer pObject) const noexcept
{
Timespec ts = {0, 0};
gboolean isOK = FALSE;
g_return_if_fail (pObject != NULL);
g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
try
{
auto val = row.get_time64_at_col(m_col_name);
timespecFromTime64 (&ts, val);
}
catch (std::invalid_argument&)
{
try
{
auto val = row.get_string_at_col(m_col_name);
GncDateTime time(val);
ts.tv_sec = static_cast<time64>(time);
}
catch (const std::invalid_argument& err)
{
if (strcmp(err.what(), "Column empty.") != 0)
{
auto val = row.get_string_at_col(m_col_name);
PWARN("An invalid date %s was found in your database."
"It has been set to 1 January 1970.", val.c_str());
}
ts.tv_sec = 0;
}
}
set_parameter(pObject, &ts,
reinterpret_cast<TimespecSetterFunc>(get_setter(obj_name)),
m_gobj_param_name);
}
template<> void
GncSqlColumnTableEntryImpl<CT_TIMESPEC>::add_to_table(ColVec& vec) const noexcept
{
GncSqlColumnInfo info{*this, BCT_DATETIME, TIMESPEC_COL_SIZE, FALSE};
vec.emplace_back(std::move(info));
}
template<> void
GncSqlColumnTableEntryImpl<CT_TIMESPEC>::add_to_query(QofIdTypeConst obj_name,
const gpointer pObject,
PairVec& vec) const noexcept
{
TimespecAccessFunc ts_getter;
Timespec ts;
/* Can't use get_row_value_from_object because g_object_get returns a
* Timespec* and the getter returns a Timespec. Will be fixed by the
* replacement of timespecs with time64s.
*/
g_return_if_fail (obj_name != NULL);
g_return_if_fail (pObject != NULL);
if (m_gobj_param_name != NULL)
{
Timespec* pts;
g_object_get (pObject, m_gobj_param_name, &pts, NULL);
ts = *pts;
}
else
{
ts_getter = (TimespecAccessFunc)get_getter (obj_name);
g_return_if_fail (ts_getter != NULL);
ts = (*ts_getter) (pObject);
}
if (ts.tv_sec > MINTIME && ts.tv_sec < MAXTIME)
{
GncDateTime time(ts.tv_sec);
vec.emplace_back (std::make_pair (std::string{m_col_name},
time.format_zulu ("'%Y-%m-%d %H:%M:%S'")));
}
else
{
vec.emplace_back (std::make_pair (std::string{m_col_name},
"NULL"));
}
}
/* ----------------------------------------------------------------- */
typedef time64 (*Time64AccessFunc) (const gpointer);
typedef void (*Time64SetterFunc) (const gpointer, time64);
constexpr int TIME_COL_SIZE = 4 + 3 + 3 + 3 + 3 + 3;
template<> void
GncSqlColumnTableEntryImpl<CT_TIME64>::load (const GncSqlBackend* sql_be,
GncSqlColumnTableEntryImpl<CT_TIME>::load (const GncSqlBackend* sql_be,
GncSqlRow& row,
QofIdTypeConst obj_name,
gpointer pObject)
const noexcept
{
time64 t;
time64 t{0};
g_return_if_fail (m_gobj_param_name != nullptr || get_setter(obj_name) != nullptr);
try
{
@ -485,33 +392,62 @@ GncSqlColumnTableEntryImpl<CT_TIME64>::load (const GncSqlBackend* sql_be,
GncDateTime time(val);
t = static_cast<time64>(time);
}
catch (std::invalid_argument&)
catch (const std::invalid_argument& err)
{
return;
if (strcmp(err.what(), "Column empty.") != 0)
{
auto val = row.get_string_at_col (m_col_name);
PWARN("An invalid date %s was found in your database."
"It has been set to 1 January 1970.", val.c_str());
}
}
}
set_parameter(pObject, t,
reinterpret_cast<Time64SetterFunc>(get_setter(obj_name)),
m_gobj_param_name);
if (m_gobj_param_name != nullptr)
{
Time64 t64{t};
set_parameter(pObject, &t64, m_gobj_param_name);
}
else
{
set_parameter(pObject, t,
reinterpret_cast<Time64SetterFunc>(get_setter(obj_name)),
nullptr);
}
}
template<> void
GncSqlColumnTableEntryImpl<CT_TIME64>::add_to_table(ColVec& vec) const noexcept
GncSqlColumnTableEntryImpl<CT_TIME>::add_to_table(ColVec& vec) const noexcept
{
GncSqlColumnInfo info{*this, BCT_DATETIME, TIMESPEC_COL_SIZE, FALSE};
GncSqlColumnInfo info{*this, BCT_DATETIME, TIME_COL_SIZE, FALSE};
vec.emplace_back(std::move(info));
}
template<> void
GncSqlColumnTableEntryImpl<CT_TIME64>::add_to_query(QofIdTypeConst obj_name,
GncSqlColumnTableEntryImpl<CT_TIME>::add_to_query(QofIdTypeConst obj_name,
const gpointer pObject,
PairVec& vec) const noexcept
{
auto t = get_row_value_from_object<time64>(obj_name, pObject);
if (t > MINTIME && t < MAXTIME)
/* We still can't use get_row_value_from_object because while g_value could
* contentedly store a time64 in an int64, KVP wouldn't be able to tell them
* apart, so we have the struct Time64 hack, see engine/gnc-date.c.
*/
time64 t64;
if (m_gobj_param_name != nullptr)
{
GncDateTime time(t);
Time64* t;
g_object_get (pObject, m_gobj_param_name, &t, nullptr);
t64 = t->t;
}
else
{
auto getter = (Time64AccessFunc)get_getter (obj_name);
g_return_if_fail(getter != nullptr);
t64 = (*getter)(pObject);
}
if (t64 > MINTIME && t64 < MAXTIME)
{
GncDateTime time(t64);
vec.emplace_back (std::make_pair (std::string{m_col_name},
time.format_zulu ("'%Y-%m-%d %H:%M:%S'")));
}
@ -539,7 +475,7 @@ GncSqlColumnTableEntryImpl<CT_GDATE>::load (const GncSqlBackend* sql_be,
g_date_clear (&date, 1);
try
{
/* timespec_to_gdate applies the tz, and gdates are saved
/* time64_to_gdate applies the tz, and gdates are saved
* as ymd, so we don't want that.
*/
auto time = row.get_time64_at_col(m_col_name);
@ -667,7 +603,7 @@ GncSqlColumnTableEntryImpl<CT_NUMERIC>::add_to_query(QofIdTypeConst obj_name,
const gpointer pObject,
PairVec& vec) const noexcept
{
/* We can't use get_row_value_from_object for the same reason as Timespec. */
/* We can't use get_row_value_from_object for the same reason as time64. */
NumericGetterFunc getter;
gnc_numeric n;

View File

@ -71,8 +71,7 @@ enum GncSqlObjectType
CT_GUID,
CT_INT,
CT_INT64,
CT_TIMESPEC,
CT_TIME64,
CT_TIME,
CT_GDATE,
CT_NUMERIC,
CT_DOUBLE,

View File

@ -90,8 +90,8 @@ static const EntryVec tx_col_table
gnc_sql_make_table_entry<CT_COMMODITYREF>("currency_guid", 0, COL_NNUL,
"currency"),
gnc_sql_make_table_entry<CT_STRING>("num", TX_MAX_NUM_LEN, COL_NNUL, "num"),
gnc_sql_make_table_entry<CT_TIMESPEC>("post_date", 0, 0, "post-date"),
gnc_sql_make_table_entry<CT_TIMESPEC>("enter_date", 0, 0, "enter-date"),
gnc_sql_make_table_entry<CT_TIME>("post_date", 0, 0, "post-date"),
gnc_sql_make_table_entry<CT_TIME>("enter_date", 0, 0, "enter-date"),
gnc_sql_make_table_entry<CT_STRING>("description", TX_MAX_DESCRIPTION_LEN,
0, "description"),
};
@ -116,7 +116,7 @@ static const EntryVec split_col_table
gnc_sql_make_table_entry<CT_STRING>("reconcile_state", 1, COL_NNUL,
(QofAccessFunc)get_split_reconcile_state,
set_split_reconcile_state),
gnc_sql_make_table_entry<CT_TIMESPEC>("reconcile_date", 0, 0,
gnc_sql_make_table_entry<CT_TIME>("reconcile_date", 0, 0,
"reconcile-date"),
gnc_sql_make_table_entry<CT_NUMERIC>("value", 0, COL_NNUL, "value"),
gnc_sql_make_table_entry<CT_NUMERIC>("quantity", 0, COL_NNUL, "amount"),
@ -127,7 +127,7 @@ static const EntryVec split_col_table
static const EntryVec post_date_col_table
{
gnc_sql_make_table_entry<CT_TIMESPEC>("post_date", 0, 0, "post-date"),
gnc_sql_make_table_entry<CT_TIME>("post_date", 0, 0, "post-date"),
};
static const EntryVec account_guid_col_table

View File

@ -597,30 +597,6 @@ gnc_sql_add_objectref_guid_col_info_to_list (,// 1
test_gnc_sql_add_objectref_guid_col_info_to_list (Fixture *fixture, gconstpointer pData)
{
}*/
/* load_timespec
static void
load_timespec (const GncSqlBackend* sql_be, GncSqlRow& row,// 2
*/
/* static void
test_load_timespec (Fixture *fixture, gconstpointer pData)
{
}*/
/* add_timespec_col_info_to_list
static void
add_timespec_col_info_to_list (const GncSqlBackend* sql_be, const GncSqlColumnTableEntry& table_row,// 2
*/
/* static void
test_add_timespec_col_info_to_list (Fixture *fixture, gconstpointer pData)
{
}*/
/* add_value_timespec_to_vec
static void
add_gvalue_timespec_to_slist (const GncSqlBackend* sql_be, QofIdTypeConst obj_name,// 2
*/
/* static void
test_add_value_timespec_to_vec (Fixture *fixture, gconstpointer pData)
{
}*/
/* load_date
static void
load_date (const GncSqlBackend* sql_be, GncSqlRow& row,// 2
@ -915,9 +891,6 @@ test_suite_gnc_backend_sql (void)
// 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 (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 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 value date to vec", Fixture, nullptr, test_add_value_date_to_vec, teardown);