More common code merging - commodity/account/tx guids

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/branches/gda-dev@16689 57a11ea4-9604-0410-9ed3-97b8803252fd
zzzoldfeatures/gda-dev
Phil Longstaff 19 years ago
parent 05cba49d00
commit 303ccc169f

@ -47,8 +47,6 @@ static QofLogModule log_module = GNC_MOD_BACKEND;
#define TABLE_NAME "accounts"
static gpointer get_commodity( gpointer pObject, const QofParam* );
static void set_commodity( gpointer pObject, gpointer pValue );
static gpointer get_parent( gpointer pObject, const QofParam* );
static void set_parent( gpointer pObject, gpointer pValue );
static void set_parent_guid( gpointer pObject, gpointer pValue );
@ -63,9 +61,8 @@ static col_cvt_t col_table[] =
{ "guid", CT_GUID, 0, COL_NNUL, "guid" },
{ "name", CT_STRING, ACCOUNT_MAX_NAME_LEN, COL_NNUL, "name" },
{ "account_type", CT_STRING, ACCOUNT_MAX_TYPE_LEN, COL_NNUL, NULL, ACCOUNT_TYPE_ },
// { "commodity_guid", CT_GUID_C, 0, COL_NNUL, NULL, NULL, get_commodity, set_commodity },
{ "commodity_guid", CT_GUID_C, 0, COL_NNUL, "commodity" },
{ "parent_guid", CT_GUID_A, 0, 0, NULL, NULL, get_parent, set_parent },
{ "parent_guid", CT_GUID, 0, 0, NULL, NULL, get_parent, set_parent },
{ "code", CT_STRING, ACCOUNT_MAX_CODE_LEN, 0, "code" },
{ "description", CT_STRING, ACCOUNT_MAX_DESCRIPTION_LEN, 0, "description" },
{ NULL }
@ -82,26 +79,6 @@ typedef struct {
} account_parent_guid_struct;
/* ================================================================= */
static gpointer
get_commodity( gpointer pObject, const QofParam* param )
{
const Account* pAccount = GNC_ACCOUNT(pObject);
return (gpointer)qof_instance_get_guid(
QOF_INSTANCE(xaccAccountGetCommodity( pAccount )) );
}
static void
set_commodity( gpointer pObject, gpointer pValue )
{
Account* pAccount = GNC_ACCOUNT(pObject);
QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pAccount) );
gnc_commodity* pCommodity;
GUID* guid = (GUID*)pValue;
pCommodity = gnc_commodity_find_commodity_by_guid( guid, pBook );
xaccAccountSetCommodity( pAccount, pCommodity );
}
static gpointer
get_parent( gpointer pObject, const QofParam* param )

@ -603,6 +603,7 @@ load_account_guid( GncGdaBackend* be, GdaDataModel* pModel, gint row,
const GValue* val;
GUID guid;
const GUID* pGuid;
Account* account = NULL;
val = gda_data_model_get_value_at_col_name( pModel, table->col_name, row );
if( gda_value_is_null( val ) ) {
@ -611,10 +612,13 @@ load_account_guid( GncGdaBackend* be, GdaDataModel* pModel, gint row,
string_to_guid( g_value_get_string( val ), &guid );
pGuid = &guid;
}
if( pGuid != NULL ) {
account = xaccAccountLookup( pGuid, be->primary_book );
}
if( table->gobj_param_name != NULL ) {
g_object_set( pObject, table->gobj_param_name, pGuid, NULL );
g_object_set( pObject, table->gobj_param_name, account, NULL );
} else {
(*setter)( pObject, (const gpointer)pGuid );
(*setter)( pObject, (const gpointer)account );
}
}
@ -623,16 +627,20 @@ get_gvalue_account_guid( GncGdaBackend* be, QofIdTypeConst obj_name, gpointer pO
const col_cvt_t* table_row, GValue* value )
{
QofAccessFunc getter;
const GUID* guid;
const GUID* guid = NULL;
gchar guid_buf[GUID_ENCODING_LENGTH+1];
Account* account;
memset( value, 0, sizeof( GValue ) );
if( table_row->gobj_param_name != NULL ) {
g_object_get( pObject, table_row->gobj_param_name, &guid, NULL );
g_object_get( pObject, table_row->gobj_param_name, &account, NULL );
} else {
getter = get_getter( obj_name, table_row );
guid = (*getter)( pObject, NULL );
account = (*getter)( pObject, NULL );
}
if( account != NULL ) {
guid = qof_instance_get_guid( QOF_INSTANCE(account) );
}
if( guid != NULL ) {
(void)guid_to_string_buff( guid, guid_buf );
@ -769,6 +777,7 @@ load_tx_guid( GncGdaBackend* be, GdaDataModel* pModel, gint row,
const GValue* val;
GUID guid;
const GUID* pGuid;
Transaction* tx = NULL;
val = gda_data_model_get_value_at_col_name( pModel, table->col_name, row );
if( gda_value_is_null( val ) ) {
@ -777,10 +786,13 @@ load_tx_guid( GncGdaBackend* be, GdaDataModel* pModel, gint row,
string_to_guid( g_value_get_string( val ), &guid );
pGuid = &guid;
}
if( pGuid != NULL ) {
tx = xaccTransLookup( pGuid, be->primary_book );
}
if( table->gobj_param_name != NULL ) {
g_object_set( pObject, table->gobj_param_name, pGuid, NULL );
g_object_set( pObject, table->gobj_param_name, tx, NULL );
} else {
(*setter)( pObject, (const gpointer)pGuid );
(*setter)( pObject, (const gpointer)tx );
}
}
@ -789,16 +801,20 @@ get_gvalue_tx_guid( GncGdaBackend* be, QofIdTypeConst obj_name, gpointer pObject
const col_cvt_t* table_row, GValue* value )
{
QofAccessFunc getter;
const GUID* guid;
const GUID* guid = NULL;
gchar guid_buf[GUID_ENCODING_LENGTH+1];
Transaction* tx;
memset( value, 0, sizeof( GValue ) );
if( table_row->gobj_param_name != NULL ) {
g_object_get( pObject, table_row->gobj_param_name, &guid, NULL );
g_object_get( pObject, table_row->gobj_param_name, &tx, NULL );
} else {
getter = get_getter( obj_name, table_row );
guid = (*getter)( pObject, NULL );
tx = (*getter)( pObject, NULL );
}
if( tx != NULL ) {
guid = qof_instance_get_guid( QOF_INSTANCE(tx) );
}
if( guid != NULL ) {
(void)guid_to_string_buff( guid, guid_buf );

@ -57,8 +57,8 @@ static void set_root_template_guid( gpointer pObject, gpointer pValue );
static col_cvt_t col_table[] =
{
{ "guid", CT_GUID, 0, COL_NNUL, "guid" },
{ "root_account_guid", CT_GUID_A, 0, COL_NNUL, NULL, NULL, get_root_account_guid, set_root_account_guid },
{ "root_template_guid", CT_GUID_A, 0, COL_NNUL, NULL, NULL, get_root_template_guid, set_root_template_guid },
{ "root_account_guid", CT_GUID, 0, COL_NNUL, NULL, NULL, get_root_account_guid, set_root_account_guid },
{ "root_template_guid", CT_GUID, 0, COL_NNUL, NULL, NULL, get_root_template_guid, set_root_template_guid },
{ NULL }
};

@ -51,7 +51,7 @@ static void set_lot_is_closed( gpointer pObject, gpointer pValue );
static col_cvt_t col_table[] =
{
{ "guid", CT_GUID, 0, COL_NNUL, "guid" },
{ "account_guid", CT_GUID_A, 0, COL_NNUL, NULL, NULL, get_lot_account, set_lot_account },
{ "account_guid", CT_GUID, 0, COL_NNUL, NULL, NULL, get_lot_account, set_lot_account },
{ "is_closed", CT_STRING, 1, COL_NNUL, NULL, NULL, get_lot_is_closed, set_lot_is_closed },
{ NULL }
};

@ -73,7 +73,7 @@ static col_cvt_t col_table[] =
{ "adv_notify", CT_INT, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)xaccSchedXactionGetAdvanceReminder,
(QofSetterFunc)xaccSchedXactionSetAdvanceReminder },
{ "template_act_guid", CT_GUID_A, 0, COL_NNUL, NULL, NULL, get_template_act_guid, set_template_act_guid },
{ "template_act_guid", CT_GUID, 0, COL_NNUL, NULL, NULL, get_template_act_guid, set_template_act_guid },
{ NULL }
};

@ -72,19 +72,15 @@ static col_cvt_t tx_col_table[] =
{
{ "guid", CT_GUID, 0, COL_NNUL, "guid" },
{ "currency_guid", CT_GUID_C, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)xaccTransGetCurrency,
(QofSetterFunc)xaccTransSetCurrency },
(QofAccessFunc)xaccTransGetCurrency, (QofSetterFunc)xaccTransSetCurrency },
{ "num", CT_STRING, TX_MAX_NUM_LEN, COL_NNUL, NULL, NULL, get_tx_num, set_tx_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 },
{ "description", CT_STRING, TX_MAX_DESCRIPTION_LEN, 0, NULL, NULL,
(QofAccessFunc)xaccTransGetDescription,
(QofSetterFunc)xaccTransSetDescription },
(QofAccessFunc)xaccTransGetDescription, (QofSetterFunc)xaccTransSetDescription },
{ NULL }
};
static gpointer get_split_tx_guid( gpointer pObject, const QofParam* param );
static void set_split_tx_guid( gpointer pObject, gpointer pValue );
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 );
@ -93,8 +89,6 @@ static gpointer get_split_value( gpointer pObject, const QofParam* param );
static void set_split_value( gpointer pObject, gpointer pValue );
static gpointer get_split_quantity( gpointer pObject, const QofParam* param );
static void set_split_quantity( gpointer pObject, gpointer pValue );
static gpointer get_split_account_guid( gpointer pObject, const QofParam* param );
static void set_split_account_guid( gpointer pObject, gpointer pValue );
#define SPLIT_MAX_MEMO_LEN 50
#define SPLIT_MAX_ACTION_LEN 50
@ -102,8 +96,10 @@ static void set_split_account_guid( gpointer pObject, gpointer pValue );
static col_cvt_t split_col_table[] =
{
{ "guid", CT_GUID, 0, COL_NNUL, "guid" },
{ "tx_guid", CT_GUID_T, 0, COL_NNUL, NULL, NULL, get_split_tx_guid, set_split_tx_guid },
{ "account_guid", CT_GUID_A, 0, COL_NNUL, NULL, NULL, get_split_account_guid, set_split_account_guid },
{ "tx_guid", CT_GUID_T, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)xaccSplitGetParent, (QofSetterFunc)xaccSplitSetParent },
{ "account_guid", CT_GUID_A, 0, COL_NNUL, NULL, NULL,
(QofAccessFunc)xaccSplitGetAccount, (QofSetterFunc)xaccSplitSetAccount },
{ "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 },
@ -119,6 +115,8 @@ static col_cvt_t guid_col_table[] =
{ NULL }
};
static void retrieve_numeric_value( gpointer pObject, gpointer pValue );
/* ================================================================= */
static gpointer
get_guid( gpointer pObject, const QofParam* param )
@ -192,26 +190,6 @@ set_tx_enter_date( gpointer pObject, gpointer pValue )
xaccTransSetDateEnteredTS( pTx, pTS );
}
static gpointer
get_split_tx_guid( gpointer pObject, const QofParam* param )
{
const Split* pSplit = GNC_SPLIT(pObject);
Transaction* pTx = xaccSplitGetParent( pSplit );
return (gpointer)qof_instance_get_guid( QOF_INSTANCE(pTx) );
}
static void
set_split_tx_guid( gpointer pObject, gpointer pValue )
{
Split* pSplit = GNC_SPLIT(pObject);
QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pSplit) );
GUID* guid = (GUID*)pValue;
Transaction* pTx = xaccTransLookup( guid, pBook );
xaccSplitSetParent( pSplit, pTx );
}
static gpointer
get_split_reconcile_state( gpointer pObject, const QofParam* param )
{
@ -289,28 +267,6 @@ set_split_quantity( gpointer pObject, gpointer pValue )
xaccSplitSetAmount( pSplit, *pV );
}
static gpointer
get_split_account_guid( gpointer pObject, const QofParam* param )
{
const Split* pSplit = GNC_SPLIT(pObject);
Account* pAccount = xaccSplitGetAccount( pSplit );
return (gpointer)qof_instance_get_guid( QOF_INSTANCE(pAccount) );
}
static void
set_split_account_guid( gpointer pObject, gpointer pValue )
{
Split* pSplit = GNC_SPLIT(pObject);
QofBook* pBook = qof_instance_get_book( QOF_INSTANCE(pSplit) );
GUID* guid = (GUID*)pValue;
Account* pAccount = xaccAccountLookup( guid, pBook );
xaccSplitSetAccount( pSplit, pAccount );
}
static void retrieve_numeric_value( gpointer pObject, gpointer pValue );
static void
retrieve_numeric_value( gpointer pObject, gpointer pValue )
{
@ -321,7 +277,7 @@ retrieve_numeric_value( gpointer pObject, gpointer pValue )
}
// Table to retrieve just the guid
// Table to retrieve just the quantity
static col_cvt_t quantity_table[] =
{
{ "quantity", CT_NUMERIC, 0, COL_NNUL, NULL, NULL, NULL, retrieve_numeric_value },

Loading…
Cancel
Save