r16765 - gnucash/branches/gda-dev2/src/backend/gda - For Timespec columns, standardize how Timespec is retrieved and set from
Phil Longstaff
plongstaff at cvs.gnucash.org
Sat Dec 29 15:28:10 EST 2007
Author: plongstaff
Date: 2007-12-29 15:28:09 -0500 (Sat, 29 Dec 2007)
New Revision: 16765
Trac: http://svn.gnucash.org/trac/changeset/16765
Modified:
gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c
gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c
gnucash/branches/gda-dev2/src/backend/gda/gnc-price-gda.c
gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c
gnucash/branches/gda-dev2/src/backend/gda/gnc-transaction-gda.c
Log:
For Timespec columns, standardize how Timespec is retrieved and set from
objects (by value).
Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c 2007-12-29 19:40:28 UTC (rev 16764)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-gda.c 2007-12-29 20:28:09 UTC (rev 16765)
@@ -300,7 +300,7 @@
static void
gnc_gda_destroy_backend(QofBackend *be)
{
- g_free(be);
+ g_free( be );
}
/* ================================================================= */
@@ -870,8 +870,8 @@
g_return_if_fail( type != NULL && pData != NULL && be_data != NULL );
g_return_if_fail( pData->version == GNC_GDA_BACKEND_VERSION );
+ if( be_data->ok ) return;
if( strcmp( type, be_data->pQueryInfo->searchObj ) != 0 ) return;
- if( be_data->ok ) return;
if( pData->free_query != NULL ) {
(pData->free_query)( be_data->be, be_data->pCompiledQuery );
Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c 2007-12-29 19:40:28 UTC (rev 16764)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-backend-util-gda.c 2007-12-29 20:28:09 UTC (rev 16765)
@@ -639,6 +639,8 @@
}
/* ----------------------------------------------------------------- */
+typedef Timespec (*TimespecAccessFunc)( const gpointer );
+
static void
load_timespec( const GncGdaBackend* be, GdaDataModel* pModel, gint row,
QofSetterFunc setter, gpointer pObject,
@@ -681,25 +683,23 @@
get_gvalue_timespec( const GncGdaBackend* be, QofIdTypeConst obj_name,
const gpointer pObject, const col_cvt_t* table_row, GValue* value )
{
- QofAccessFunc getter;
- Timespec* pTimespec;
+ TimespecAccessFunc getter;
+ Timespec ts;
+ GDate* date;
+ gint y, m, d;
+ gchar iso8601_buf[33];
memset( value, 0, sizeof( GValue ) );
- getter = gnc_gda_get_getter( obj_name, table_row );
- pTimespec = (Timespec*)(*getter)( pObject, NULL );
- if( pTimespec != NULL ) {
- GDate* date;
- gint y, m, d;
- gchar iso8601_buf[33];
+ getter = (TimespecAccessFunc)gnc_gda_get_getter( obj_name, table_row );
+ ts = (*getter)( pObject );
- date = g_date_new();
- (void)gnc_timespec_to_iso8601_buff( *pTimespec, iso8601_buf );
- sscanf( iso8601_buf, "%d-%d-%d", &y, &m, &d );
- g_date_set_dmy( date, d, m, y );
- g_value_init( value, G_TYPE_DATE );
- g_value_set_boxed( value, date );
- }
+ date = g_date_new();
+ (void)gnc_timespec_to_iso8601_buff( ts, iso8601_buf );
+ sscanf( iso8601_buf, "%d-%d-%d", &y, &m, &d );
+ g_date_set_dmy( date, d, m, y );
+ g_value_init( value, G_TYPE_DATE );
+ g_value_set_boxed( value, date );
}
static void
@@ -837,8 +837,8 @@
return 0;
}
+typedef gnc_numeric (*NumericGetterFunc)( const gpointer );
typedef void (*NumericSetterFunc)( gpointer, gnc_numeric );
-typedef gnc_numeric (*NumericGetterFunc)( const gpointer );
static void
load_numeric( const GncGdaBackend* be, GdaDataModel* pModel, gint row,
Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-price-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-price-gda.c 2007-12-29 19:40:28 UTC (rev 16764)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-price-gda.c 2007-12-29 20:28:09 UTC (rev 16765)
@@ -43,9 +43,6 @@
#define TABLE_NAME "prices"
-static gpointer get_date( gpointer pObject, const QofParam* param );
-static void set_date( gpointer pObject, gpointer pValue );
-
#define PRICE_MAX_SOURCE_LEN 50
#define PRICE_MAX_TYPE_LEN 50
@@ -54,7 +51,7 @@
{ "guid", CT_GUID, 0, COL_NNUL, "guid" },
{ "commodity_guid", CT_COMMODITYREF, 0, COL_NNUL, NULL, PRICE_COMMODITY },
{ "currency_guid", CT_COMMODITYREF, 0, COL_NNUL, NULL, PRICE_CURRENCY },
- { "date", CT_TIMESPEC, 0, COL_NNUL, NULL, NULL, get_date, set_date },
+ { "date", CT_TIMESPEC, 0, COL_NNUL, NULL, PRICE_DATE },
{ "source", CT_STRING, PRICE_MAX_SOURCE_LEN, 0, NULL, PRICE_SOURCE },
{ "type", CT_STRING, PRICE_MAX_TYPE_LEN, 0, NULL, PRICE_TYPE },
{ "value", CT_NUMERIC, 0, COL_NNUL, NULL, PRICE_VALUE },
@@ -63,25 +60,6 @@
/* ================================================================= */
-static gpointer
-get_date( gpointer pObject, const QofParam* param )
-{
- const GNCPrice* pPrice = GNC_PRICE(pObject);
- static Timespec t;
-
- t = gnc_price_get_time( pPrice );
- return &t;
-}
-
-static void
-set_date( gpointer pObject, gpointer pValue )
-{
- GNCPrice* pPrice = GNC_PRICE(pObject);
- const Timespec* pTimespec = (const Timespec*)pValue;
-
- gnc_price_set_time( pPrice, *pTimespec );
-}
-
static GNCPrice*
load_single_price( GncGdaBackend* be, GdaDataModel* pModel, int row )
{
Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c 2007-12-29 19:40:28 UTC (rev 16764)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-slots-gda.c 2007-12-29 20:28:09 UTC (rev 16765)
@@ -63,8 +63,8 @@
static void set_string_val( gpointer pObject, gpointer pValue );
static gpointer get_double_val( gpointer pObject, const QofParam* param );
static void set_double_val( gpointer pObject, gpointer pValue );
-static gpointer get_timespec_val( gpointer pObject, const QofParam* param );
-static void set_timespec_val( gpointer pObject, gpointer pValue );
+static Timespec get_timespec_val( gpointer pObject, const QofParam* param );
+static void set_timespec_val( gpointer pObject, Timespec ts );
static gpointer get_guid_val( gpointer pObject, const QofParam* param );
static void set_guid_val( gpointer pObject, gpointer pValue );
static gnc_numeric get_numeric_val( gpointer pObject, const QofParam* param );
@@ -82,7 +82,8 @@
{ "int64_val", CT_INT64, 0, 0, NULL, NULL, get_int64_val, set_int64_val },
{ "string_val", CT_STRING, SLOT_MAX_PATHNAME_LEN, 0, NULL, NULL, get_string_val, set_string_val },
{ "double_val", CT_DOUBLE, 0, 0, NULL, NULL, get_double_val, set_double_val },
- { "timespec_val", CT_TIMESPEC, 0, 0, NULL, NULL, get_timespec_val, set_timespec_val },
+ { "timespec_val", CT_TIMESPEC, 0, 0, NULL, NULL,
+ (QofAccessFunc)get_timespec_val, (QofSetterFunc)set_timespec_val },
{ "guid_val", CT_GUID, 0, 0, NULL, NULL, get_guid_val, set_guid_val },
{ "numeric_val", CT_NUMERIC, 0, 0, NULL, NULL,
(QofAccessFunc)get_numeric_val, (QofSetterFunc)set_numeric_val },
@@ -215,27 +216,22 @@
}
}
-static gpointer
+static Timespec
get_timespec_val( gpointer pObject, const QofParam* param )
{
slot_info_t* pInfo = (slot_info_t*)pObject;
- static Timespec ts;
- if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_TIMESPEC ) {
- ts = kvp_value_get_timespec( pInfo->pKvpValue );
- return (gpointer)&ts;
- } else {
- return NULL;
- }
+//if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_TIMESPEC ) {
+ return kvp_value_get_timespec( pInfo->pKvpValue );
}
static void
-set_timespec_val( gpointer pObject, gpointer pValue )
+set_timespec_val( gpointer pObject, Timespec ts )
{
slot_info_t* pInfo = (slot_info_t*)pObject;
if( pInfo->value_type == KVP_TYPE_TIMESPEC ) {
- kvp_frame_set_timespec( pInfo->pKvpFrame, pInfo->path->str, *(Timespec*)pValue );
+ kvp_frame_set_timespec( pInfo->pKvpFrame, pInfo->path->str, ts );
}
}
Modified: gnucash/branches/gda-dev2/src/backend/gda/gnc-transaction-gda.c
===================================================================
--- gnucash/branches/gda-dev2/src/backend/gda/gnc-transaction-gda.c 2007-12-29 19:40:28 UTC (rev 16764)
+++ gnucash/branches/gda-dev2/src/backend/gda/gnc-transaction-gda.c 2007-12-29 20:28:09 UTC (rev 16765)
@@ -37,6 +37,7 @@
#include "Account.h"
#include "Transaction.h"
+#include "engine-helpers.h"
#include "gnc-backend-util-gda.h"
#include "gnc-transaction-gda.h"
@@ -56,11 +57,6 @@
const GUID* guid;
} split_info_t;
-static gpointer get_tx_post_date( gpointer pObject, const QofParam* param );
-static void set_tx_post_date( gpointer pObject, gpointer pValue );
-static gpointer get_tx_enter_date( gpointer pObject, const QofParam* param );
-static void set_tx_enter_date( gpointer pObject, gpointer pValue );
-
#define TX_MAX_NUM_LEN 50
#define TX_MAX_DESCRIPTION_LEN 500
@@ -70,8 +66,10 @@
{ "currency_guid", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)xaccTransGetCurrency, (QofSetterFunc)xaccTransSetCurrency },
{ "num", CT_STRING, TX_MAX_NUM_LEN, COL_NNUL, NULL, TRANS_NUM },
- { "post_date", CT_TIMESPEC, 0, COL_NNUL, NULL, NULL, get_tx_post_date, set_tx_post_date },
- { "enter_date", CT_TIMESPEC, 0, COL_NNUL, NULL, NULL, get_tx_enter_date, set_tx_enter_date },
+ { "post_date", CT_TIMESPEC, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)xaccTransRetDatePostedTS, (QofSetterFunc)gnc_transaction_set_date_posted },
+ { "enter_date", CT_TIMESPEC, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)xaccTransRetDateEnteredTS, (QofSetterFunc)gnc_transaction_set_date_entered },
{ "description", CT_STRING, TX_MAX_DESCRIPTION_LEN, 0, NULL, NULL,
(QofAccessFunc)xaccTransGetDescription, (QofSetterFunc)xaccTransSetDescription },
{ NULL }
@@ -79,8 +77,7 @@
static gpointer get_split_reconcile_state( gpointer pObject, const QofParam* param );
static void set_split_reconcile_state( gpointer pObject, gpointer pValue );
-static gpointer get_split_reconcile_date( gpointer pObject, const QofParam* param );
-static void set_split_reconcile_date( gpointer pObject, gpointer pValue );
+static void set_split_reconcile_date( gpointer pObject, Timespec ts );
#define SPLIT_MAX_MEMO_LEN 50
#define SPLIT_MAX_ACTION_LEN 50
@@ -93,7 +90,8 @@
{ "memo", CT_STRING, SPLIT_MAX_MEMO_LEN, COL_NNUL, NULL, SPLIT_MEMO },
{ "action", CT_STRING, SPLIT_MAX_ACTION_LEN, COL_NNUL, NULL, SPLIT_ACTION },
{ "reconcile_state", CT_STRING, 1, COL_NNUL, NULL, NULL, get_split_reconcile_state, set_split_reconcile_state },
- { "reconcile_date", CT_TIMESPEC, 0, COL_NNUL, NULL, NULL, get_split_reconcile_date, set_split_reconcile_date },
+ { "reconcile_date", CT_TIMESPEC, 0, COL_NNUL, NULL, NULL,
+ (QofAccessFunc)xaccSplitRetDateReconciledTS, (QofSetterFunc)set_split_reconcile_date },
{ "value", CT_NUMERIC, 0, COL_NNUL, NULL, SPLIT_VALUE },
{ "quantity", CT_NUMERIC, 0, COL_NNUL, NULL, SPLIT_AMOUNT },
{ NULL }
@@ -110,44 +108,6 @@
/* ================================================================= */
static gpointer
-get_tx_post_date( gpointer pObject, const QofParam* param )
-{
- const Transaction* pTx = GNC_TRANS(pObject);
- static Timespec ts;
-
- ts = xaccTransRetDatePostedTS( pTx );
- return (gpointer)&ts;
-}
-
-static void
-set_tx_post_date( gpointer pObject, gpointer pValue )
-{
- Transaction* pTx = GNC_TRANS(pObject);
- Timespec* pTS = (Timespec*)pValue;
-
- xaccTransSetDatePostedTS( pTx, pTS );
-}
-
-static gpointer
-get_tx_enter_date( gpointer pObject, const QofParam* param )
-{
- const Transaction* pTx = GNC_TRANS(pObject);
- static Timespec ts;
-
- ts = xaccTransRetDateEnteredTS( pTx );
- return (gpointer)&ts;
-}
-
-static void
-set_tx_enter_date( gpointer pObject, gpointer pValue )
-{
- Transaction* pTx = GNC_TRANS(pObject);
- Timespec* pTS = (Timespec*)pValue;
-
- xaccTransSetDateEnteredTS( pTx, pTS );
-}
-
-static gpointer
get_split_reconcile_state( gpointer pObject, const QofParam* param )
{
const Split* pSplit = GNC_SPLIT(pObject);
@@ -167,23 +127,10 @@
xaccSplitSetReconcile( pSplit, s[0] );
}
-static gpointer
-get_split_reconcile_date( gpointer pObject, const QofParam* param )
-{
- const Split* pSplit = GNC_SPLIT(pObject);
- static Timespec ts;
-
- ts = xaccSplitRetDateReconciledTS( pSplit );
- return (gpointer)&ts;
-}
-
static void
-set_split_reconcile_date( gpointer pObject, gpointer pValue )
+set_split_reconcile_date( gpointer pObject, Timespec ts )
{
- Split* pSplit = GNC_SPLIT(pObject);
- Timespec* pTS = (Timespec*)pValue;
-
- xaccSplitSetDateReconciledTS( pSplit, pTS );
+ xaccSplitSetDateReconciledTS( GNC_SPLIT(pObject), &ts );
}
static void
@@ -237,6 +184,7 @@
bal = gnc_numeric_add( bal, val, GNC_DENOM_AUTO, GNC_HOW_DENOM_LCD );
}
}
+ g_object_unref( G_OBJECT(ret) );
return bal;
}
@@ -268,7 +216,7 @@
/* Create the query */
query = gnc_gda_create_query_from_sql( be, sql );
*start_balance = get_account_balance_from_query( be, query );
-
+ g_object_unref( G_OBJECT(query) );
g_free( sql );
/*
@@ -285,6 +233,7 @@
query = gnc_gda_create_query_from_sql( be, sql );
*cleared_balance = get_account_balance_from_query( be, query );
+ g_object_unref( G_OBJECT(query) );
g_free( sql );
@@ -302,6 +251,7 @@
query = gnc_gda_create_query_from_sql( be, sql );
*reconciled_balance = get_account_balance_from_query( be, query );
+ g_object_unref( G_OBJECT(query) );
g_free( sql );
}
More information about the gnucash-changes
mailing list