r15145 - gnucash/branches/gda-dev/src - 1) Replace column size magic numbers by #defines
Phil Longstaff
plongstaff at cvs.gnucash.org
Sun Nov 26 09:21:52 EST 2006
Author: plongstaff
Date: 2006-11-26 09:21:50 -0500 (Sun, 26 Nov 2006)
New Revision: 15145
Trac: http://svn.gnucash.org/trac/changeset/15145
Modified:
gnucash/branches/gda-dev/src/backend/Makefile.am
gnucash/branches/gda-dev/src/backend/gda/Makefile.am
gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c
gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h
gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c
gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c
gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c
gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c
gnucash/branches/gda-dev/src/bin/Makefile.am
Log:
1) Replace column size magic numbers by #defines
2) Use some common code
3) Save/restore budgets (except recurrence)
4) Add gnucash-gdb to bin
Modified: gnucash/branches/gda-dev/src/backend/Makefile.am
===================================================================
--- gnucash/branches/gda-dev/src/backend/Makefile.am 2006-11-26 04:07:45 UTC (rev 15144)
+++ gnucash/branches/gda-dev/src/backend/Makefile.am 2006-11-26 14:21:50 UTC (rev 15145)
@@ -1,3 +1,3 @@
-SUBDIRS = file ${SQL_DIR}
-DIST_SUBDIRS = file postgres
+SUBDIRS = file ${SQL_DIR} gda
+DIST_SUBDIRS = file postgres gda
Modified: gnucash/branches/gda-dev/src/backend/gda/Makefile.am
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/Makefile.am 2006-11-26 04:07:45 UTC (rev 15144)
+++ gnucash/branches/gda-dev/src/backend/gda/Makefile.am 2006-11-26 14:21:50 UTC (rev 15145)
@@ -20,6 +20,7 @@
gnc-account-gda.c \
gnc-budget-gda.c \
gnc-commodity-gda.c \
+ gnc-lots-gda.c \
gnc-price-gda.c \
gnc-slots-gda.c \
gnc-transaction-gda.c
Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c 2006-11-26 04:07:45 UTC (rev 15144)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-account-gda.c 2006-11-26 14:21:50 UTC (rev 15145)
@@ -49,25 +49,46 @@
static void set_commodity( gpointer pObject, const gpointer pValue );
static gpointer get_parent( gpointer pObject );
static void set_parent( gpointer pObject, const gpointer pValue );
+static void retrieve_guid( gpointer pObject, const gpointer pValue );
+#define ACCOUNT_MAX_NAME_LEN 50
+#define ACCOUNT_MAX_TYPE_LEN 50
+#define ACCOUNT_MAX_CODE_LEN 100
+#define ACCOUNT_MAX_DESCRIPTION_LEN 500
+
static col_cvt_t col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, NULL,
+ { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, NULL,
(GNC_GDA_FN_GETTER)qof_entity_get_guid,
(GNC_GDA_FN_SETTER)xaccAccountSetGUID },
- { "name", CT_STRING, 50, COL_NNUL, ACCOUNT_NAME_ },
- { "account_type", CT_INT, 0, COL_NNUL, NULL,
- (GNC_GDA_FN_GETTER)xaccAccountGetType,
- (GNC_GDA_FN_SETTER)xaccAccountSetType },
- { "commodity_guid", CT_GUID, 0, COL_NNUL, NULL,
+ { "name", CT_STRING, ACCOUNT_MAX_NAME_LEN, COL_NNUL, ACCOUNT_NAME_ },
+ { "account_type", CT_STRING, ACCOUNT_MAX_TYPE_LEN, COL_NNUL, ACCOUNT_TYPE_ },
+ { "commodity_guid", CT_GUID, 0, COL_NNUL, NULL,
get_commodity, set_commodity },
- { "parent_guid", CT_GUID, 0, 0, NULL, get_parent, set_parent },
- { "code", CT_STRING, 100, 0, ACCOUNT_CODE_ },
- { "description", CT_STRING, 500, 0, ACCOUNT_DESCRIPTION_ },
+ { "parent_guid", CT_GUID, 0, 0, NULL, get_parent, set_parent },
+ { "code", CT_STRING, ACCOUNT_MAX_CODE_LEN, 0, ACCOUNT_CODE_ },
+ { "description", CT_STRING, ACCOUNT_MAX_DESCRIPTION_LEN, 0, ACCOUNT_DESCRIPTION_ },
{ NULL }
};
+// Table to retrieve just the guid
+static col_cvt_t guid_table[] =
+{
+ { "guid", CT_GUID, 0, 0, NULL, NULL, retrieve_guid },
+ { NULL }
+};
+
+
/* ================================================================= */
+static void
+retrieve_guid( gpointer pObject, const gpointer pValue )
+{
+ GUID** ppGuid = (GUID**)pObject;
+ GUID* guid = (GUID*)pValue;
+
+ *ppGuid = guid;
+}
+
static gpointer
get_commodity( gpointer pObject )
{
@@ -125,39 +146,38 @@
load_account( GncGdaBackend* be, GdaDataModel* pModel, int row,
Account* pAccount )
{
+ const GUID* guid;
+ GUID acc_guid;
+
+ gnc_gda_load_object( pModel, row, GNC_ID_ACCOUNT, &guid, guid_table );
+ acc_guid = *guid;
+
if( pAccount == NULL ) {
- pAccount = xaccMallocAccount( be->primary_book );
+ pAccount = xaccAccountLookup( &acc_guid, be->primary_book );
+ if( pAccount == NULL ) {
+ pAccount = xaccMallocAccount( be->primary_book );
+ }
}
gnc_gda_load_object( pModel, row, GNC_ID_ACCOUNT, pAccount, col_table );
gnc_gda_slots_load( be, xaccAccountGetGUID( pAccount ),
qof_instance_get_slots( (QofInstance*)pAccount ) );
+ qof_instance_mark_clean( (QofInstance*)pAccount );
+
return pAccount;
}
static void
load_accounts( GncGdaBackend* be )
{
- GError* error = NULL;
gchar* buf;
- GdaQuery* query;
GdaObject* ret;
QofBook* pBook = be->primary_book;
gnc_commodity_table* pTable = gnc_commodity_table_get_table( pBook );
buf = g_strdup_printf( "SELECT * FROM %s", TABLE_NAME );
- query = gda_query_new_from_sql( be->pDict, buf, &error );
+ ret = gnc_gda_execute_sql( be, buf );
g_free( buf );
- if( query == NULL ) {
- printf( "SQL error: %s\n", error->message );
- return;
- }
- error = NULL;
- ret = gda_query_execute( query, NULL, FALSE, &error );
-
- if( error != NULL ) {
- printf( "SQL error: %s\n", error->message );
- }
if( GDA_IS_DATA_MODEL( ret ) ) {
GdaDataModel* pModel = (GdaDataModel*)ret;
int numRows = gda_data_model_get_n_rows( pModel );
@@ -191,6 +211,7 @@
commit_account( GncGdaBackend* be, QofInstance* inst )
{
Account* pAcc = (Account*)inst;
+ const GUID* guid;
// Ensure the commodity is in the db
gnc_gda_save_commodity( be, xaccAccountGetCommodity( pAcc ) );
@@ -201,9 +222,15 @@
GNC_ID_ACCOUNT, pAcc,
col_table );
+ // Delete old slot info
+ guid = qof_instance_get_guid( inst );
+
+ gnc_gda_slots_delete( be, guid );
+
// Now, commit any slots
- gnc_gda_slots_save( be, qof_instance_get_guid( inst ),
- qof_instance_get_slots( inst ) );
+ if( !inst->do_free ) {
+ gnc_gda_slots_save( be, guid, qof_instance_get_slots( inst ) );
+ }
}
/* ================================================================= */
Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c 2006-11-26 04:07:45 UTC (rev 15144)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.c 2006-11-26 14:21:50 UTC (rev 15145)
@@ -58,6 +58,7 @@
#include "gnc-account-gda.h"
#include "gnc-budget-gda.h"
#include "gnc-commodity-gda.h"
+#include "gnc-lots-gda.h"
#include "gnc-price-gda.h"
#include "gnc-slots-gda.h"
#include "gnc-transaction-gda.h"
@@ -203,12 +204,19 @@
const gchar* col_name = "";
const gchar* equals = "";
gint int_value;
+ QofAccessFunc getter;
if( include_name ) {
col_name = table_row->col_name;
equals = "=";
}
- int_value = (gint)(*table_row->getter)( pObject );
+ if( table_row->param_name != NULL ) {
+ getter = qof_class_get_parameter_getter( obj_name,
+ table_row->param_name );
+ int_value = (gint)(*getter)( pObject, NULL );
+ } else {
+ int_value = (gint)(*table_row->getter)( pObject );
+ }
buf = g_strdup_printf( "%s%s%d", col_name, equals, int_value );
return buf;
@@ -1207,7 +1215,7 @@
return;
}
- qof_instance_mark_clean( inst );
+ //qof_instance_mark_clean( inst );
}
/* ---------------------------------------------------------------------- */
@@ -1474,6 +1482,7 @@
gnc_gda_init_price_handler();
gnc_gda_init_transaction_handler();
gnc_gda_init_slots_handler();
+ gnc_gda_init_lot_handler();
}
/* ================================================================= */
@@ -1519,26 +1528,6 @@
gnc_be->primary_book = NULL;
-#if 0
- {
- QofCollection* col;
- QofEntity e;
- const GUID* g;
- QofEntity* pEntity;
- GUID g2;
-
- col = qof_collection_new( "Test" );
- qof_entity_init( &e, "Test", col );
- g = qof_entity_get_guid( &e );
- pEntity = qof_collection_lookup_entity( col, g );
- g_assert( pEntity == &e );
- guid_new( &g2 );
- qof_entity_set_guid( &e, &g2 );
- pEntity = qof_collection_lookup_entity( col, &g2 );
- g_assert( pEntity == &e );
- }
-#endif
-
return be;
}
Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h 2006-11-26 04:07:45 UTC (rev 15144)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-backend-gda.h 2006-11-26 14:21:50 UTC (rev 15145)
@@ -83,7 +83,8 @@
CT_INT64,
CT_TIMESPEC,
CT_NUMERIC,
- CT_DOUBLE
+ CT_DOUBLE,
+ CT_BOOLEAN
} E_COL_TYPE;
typedef struct {
Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c 2006-11-26 04:07:45 UTC (rev 15144)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-budget-gda.c 2006-11-26 14:21:50 UTC (rev 15145)
@@ -37,12 +37,140 @@
#include "gnc-backend-gda.h"
#include "gnc-budget-gda.h"
+#include "gnc-slots-gda.h"
+#include "gnc-budget.h"
+
+#define BUDGET_TABLE "budgets"
+
static QofLogModule log_module = GNC_MOD_BACKEND;
+static void retrieve_guid( gpointer pObject, const gpointer pValue );
+
+#define BUDGET_MAX_NAME_LEN 50
+#define BUDGET_MAX_DESCRIPTION_LEN 500
+
+static col_cvt_t col_table[] =
+{
+ { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, NULL,
+ (GNC_GDA_FN_GETTER)qof_entity_get_guid,
+ (GNC_GDA_FN_SETTER)qof_entity_set_guid },
+ { "name", CT_STRING, BUDGET_MAX_NAME_LEN, COL_NNUL, "name" },
+ { "description", CT_STRING, BUDGET_MAX_DESCRIPTION_LEN, 0, "description" },
+ { "num_periods", CT_INT, 0, COL_NNUL, "num_periods" },
+ { NULL }
+};
+
+// Table to retrieve just the guid
+static col_cvt_t guid_table[] =
+{
+ { "guid", CT_GUID, 0, 0, NULL, NULL, retrieve_guid },
+ { NULL }
+};
+
+
/* ================================================================= */
+static void
+retrieve_guid( gpointer pObject, const gpointer pValue )
+{
+ GUID** ppGuid = (GUID**)pObject;
+ GUID* guid = (GUID*)pValue;
+
+ *ppGuid = guid;
+}
+
+/* ================================================================= */
+static GncBudget*
+load_budget( GncGdaBackend* be, GdaDataModel* pModel, int row,
+ GncBudget* pBudget )
+{
+ const GUID* guid;
+ GUID budget_guid;
+
+ gnc_gda_load_object( pModel, row, GNC_ID_BUDGET, &guid, guid_table );
+ budget_guid = *guid;
+
+ if( pBudget == NULL ) {
+ pBudget = gnc_budget_lookup( &budget_guid, be->primary_book );
+ if( pBudget == NULL ) {
+ pBudget = gnc_budget_new( be->primary_book );
+ }
+ }
+
+ gnc_gda_load_object( pModel, row, GNC_ID_BUDGET, pBudget, col_table );
+ gnc_gda_slots_load( be, gnc_budget_get_guid( pBudget ),
+ qof_instance_get_slots( (QofInstance*)pBudget ) );
+
+ qof_instance_mark_clean( (QofInstance*)pBudget );
+
+ return pBudget;
+}
+
+static void
+load_budgets( GncGdaBackend* be )
+{
+ gchar* buf;
+ GdaObject* ret;
+ QofBook* pBook = be->primary_book;
+
+ buf = g_strdup_printf( "SELECT * FROM %s", BUDGET_TABLE );
+ ret = gnc_gda_execute_sql( be, buf );
+ g_free( buf );
+ if( GDA_IS_DATA_MODEL( ret ) ) {
+ GdaDataModel* pModel = (GdaDataModel*)ret;
+ int numRows = gda_data_model_get_n_rows( pModel );
+ int r;
+
+ for( r = 0; r < numRows; r++ ) {
+ (void)load_budget( be, pModel, r, NULL );
+ }
+ }
+}
+
+/* ================================================================= */
+static void
+create_budget_tables( GncGdaBackend* be )
+{
+ gnc_gda_create_table_if_needed( be, BUDGET_TABLE, col_table );
+}
+
+/* ================================================================= */
+static void
+commit_budget( GncGdaBackend* be, QofInstance* inst )
+{
+ GncBudget* pBudget = (GncBudget*)inst;
+ const GUID* guid;
+
+ (void)gnc_gda_do_db_operation( be,
+ (inst->do_free ? OP_DB_DELETE : OP_DB_ADD_OR_UPDATE ),
+ BUDGET_TABLE,
+ GNC_ID_BUDGET, pBudget,
+ col_table );
+
+ // Delete old slot info
+ guid = qof_instance_get_guid( inst );
+
+ gnc_gda_slots_delete( be, guid );
+
+ // Now, commit any slots
+ if( !inst->do_free ) {
+ gnc_gda_slots_save( be, guid, qof_instance_get_slots( inst ) );
+ }
+}
+
+/* ================================================================= */
void
gnc_gda_init_budget_handler( void )
{
+ static GncGdaDataType_t be_data =
+ {
+ GNC_GDA_BACKEND_VERSION,
+ GNC_ID_BUDGET,
+ commit_budget, /* commit */
+ load_budgets, /* initial_load */
+ create_budget_tables /* create_tables */
+ };
+
+ qof_object_register_backend( GNC_ID_BUDGET, GNC_GDA_BACKEND, &be_data );
}
/* ========================== END OF FILE ===================== */
Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c 2006-11-26 04:07:45 UTC (rev 15144)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-commodity-gda.c 2006-11-26 14:21:50 UTC (rev 15145)
@@ -48,31 +48,38 @@
#define COMMODITIES_TABLE "commodities"
+#define COMMODITY_MAX_NAMESPACE_LEN 40
+#define COMMODITY_MAX_MNEMONIC_LEN 40
+#define COMMODITY_MAX_FULLNAME_LEN 100
+#define COMMODITY_MAX_CUSIP_LEN 50
+#define COMMODITY_MAX_QUOTESOURCE_LEN 50
+#define COMMODITY_MAX_QUOTE_TZ_LEN 50
+
static col_cvt_t col_table[] = {
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, NULL,
+ { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, NULL,
(GNC_GDA_FN_GETTER)qof_entity_get_guid,
(GNC_GDA_FN_SETTER)qof_entity_set_guid },
- { "namespace", CT_STRING, 40, COL_NNUL, NULL,
+ { "namespace", CT_STRING, COMMODITY_MAX_NAMESPACE_LEN, COL_NNUL, NULL,
(GNC_GDA_FN_GETTER)gnc_commodity_get_namespace,
(GNC_GDA_FN_SETTER)gnc_commodity_set_namespace },
- { "mnemonic", CT_STRING, 40, COL_NNUL, NULL,
+ { "mnemonic", CT_STRING, COMMODITY_MAX_MNEMONIC_LEN, COL_NNUL, NULL,
(GNC_GDA_FN_GETTER)gnc_commodity_get_mnemonic,
(GNC_GDA_FN_SETTER)gnc_commodity_set_mnemonic },
- { "fullname", CT_STRING, 100, COL_NNUL, NULL,
+ { "fullname", CT_STRING, COMMODITY_MAX_FULLNAME_LEN, COL_NNUL, NULL,
(GNC_GDA_FN_GETTER)gnc_commodity_get_fullname,
(GNC_GDA_FN_SETTER)gnc_commodity_set_fullname },
- { "cusip", CT_STRING, 50, COL_NNUL, NULL,
+ { "cusip", CT_STRING, COMMODITY_MAX_CUSIP_LEN, COL_NNUL, NULL,
(GNC_GDA_FN_GETTER)gnc_commodity_get_cusip,
(GNC_GDA_FN_SETTER)gnc_commodity_set_cusip },
- { "fraction", CT_INT, 0, COL_NNUL, NULL,
+ { "fraction", CT_INT, 0, COL_NNUL, NULL,
(GNC_GDA_FN_GETTER)gnc_commodity_get_fraction,
(GNC_GDA_FN_SETTER)gnc_commodity_set_fraction },
- { "quote_flag", CT_INT, 0, COL_NNUL, NULL,
+ { "quote_flag", CT_INT, 0, COL_NNUL, NULL,
(GNC_GDA_FN_GETTER)gnc_commodity_get_quote_flag,
(GNC_GDA_FN_SETTER)gnc_commodity_set_quote_flag },
- { "quote_source", CT_STRING, 50, 0, NULL,
+ { "quote_source", CT_STRING, COMMODITY_MAX_QUOTESOURCE_LEN, 0, NULL,
get_quote_source_name, set_quote_source_name },
- { "quote_tz", CT_STRING, 50, 0, NULL,
+ { "quote_tz", CT_STRING, COMMODITY_MAX_QUOTE_TZ_LEN, 0, NULL,
(GNC_GDA_FN_GETTER)gnc_commodity_get_quote_tz,
(GNC_GDA_FN_SETTER)gnc_commodity_set_quote_tz },
{ NULL }
@@ -114,32 +121,21 @@
gnc_gda_load_object( pModel, row, GNC_ID_COMMODITY, pCommodity, col_table );
+ qof_instance_mark_clean( (QofInstance*)pCommodity );
+
return pCommodity;
}
static void
load_commodities( GncGdaBackend* be )
{
- GError* error = NULL;
gchar* buf;
- GdaQuery* query;
GdaObject* ret;
- QofBook* pBook = be->primary_book;
- gnc_commodity_table* pTable = gnc_commodity_table_get_table( pBook );
+ gnc_commodity_table* pTable = gnc_commodity_table_get_table( be->primary_book );
buf = g_strdup_printf( "SELECT * FROM %s", COMMODITIES_TABLE );
- query = gda_query_new_from_sql( be->pDict, buf, &error );
+ ret = gnc_gda_execute_sql( be, buf );
g_free( buf );
- if( query == NULL ) {
- printf( "SQL error: %s\n", error->message );
- return;
- }
- error = NULL;
- ret = gda_query_execute( query, NULL, FALSE, &error );
-
- if( error != NULL ) {
- printf( "SQL error: %s\n", error->message );
- }
if( GDA_IS_DATA_MODEL( ret ) ) {
GdaDataModel* pModel = (GdaDataModel*)ret;
int numRows = gda_data_model_get_n_rows( pModel );
Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c 2006-11-26 04:07:45 UTC (rev 15144)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-price-gda.c 2006-11-26 14:21:50 UTC (rev 15145)
@@ -52,6 +52,9 @@
static gpointer get_commodity( gpointer pObject );
static void set_commodity( gpointer pObject, const gpointer pValue );
+#define PRICE_MAX_SOURCE_LEN 50
+#define PRICE_MAX_TYPE_LEN 50
+
static col_cvt_t col_table[] =
{
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, NULL,
@@ -63,9 +66,9 @@
get_currency, set_currency },
{ "date", CT_TIMESPEC, 0, COL_NNUL, NULL,
get_date, set_date },
- { "source", CT_STRING, 50, 0, PRICE_SOURCE },
- { "type", CT_STRING, 50, 0, PRICE_TYPE },
- { "value", CT_NUMERIC, COL_NNUL, 0, NULL, get_value, set_value },
+ { "source", CT_STRING, PRICE_MAX_SOURCE_LEN, 0, PRICE_SOURCE },
+ { "type", CT_STRING, PRICE_MAX_TYPE_LEN, 0, PRICE_TYPE },
+ { "value", CT_NUMERIC, 0, COL_NNUL, NULL, get_value, set_value },
{ NULL }
};
@@ -159,32 +162,22 @@
gnc_gda_load_object( pModel, row, GNC_ID_PRICE, pPrice, col_table );
+ qof_instance_mark_clean( (QofInstance*)pPrice );
+
return pPrice;
}
static void
load_prices( GncGdaBackend* be )
{
- GError* error = NULL;
gchar* buf;
- GdaQuery* query;
GdaObject* ret;
QofBook* pBook = be->primary_book;
GNCPriceDB* pPriceDB = gnc_book_get_pricedb( pBook );
buf = g_strdup_printf( "SELECT * FROM %s", TABLE_NAME );
- query = gda_query_new_from_sql( be->pDict, buf, &error );
+ ret = gnc_gda_execute_sql( be, buf );
g_free( buf );
- if( query == NULL ) {
- printf( "SQL error: %s\n", error->message );
- return;
- }
- error = NULL;
- ret = gda_query_execute( query, NULL, FALSE, &error );
-
- if( error != NULL ) {
- printf( "SQL error: %s\n", error->message );
- }
if( GDA_IS_DATA_MODEL( ret ) ) {
GdaDataModel* pModel = (GdaDataModel*)ret;
int numRows = gda_data_model_get_n_rows( pModel );
Modified: gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c
===================================================================
--- gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c 2006-11-26 04:07:45 UTC (rev 15144)
+++ gnucash/branches/gda-dev/src/backend/gda/gnc-transaction-gda.c 2006-11-26 14:21:50 UTC (rev 15145)
@@ -61,23 +61,29 @@
static void retrieve_guid( gpointer pObject, const gpointer pValue );
static gpointer get_tx_currency( gpointer pObject );
static void set_tx_currency( gpointer pObject, const gpointer pValue );
+static gpointer get_tx_num( gpointer pObject );
+static void set_tx_num( gpointer pObject, const gpointer pValue );
static gpointer get_tx_post_date( gpointer pObject );
static void set_tx_post_date( gpointer pObject, const gpointer pValue );
static gpointer get_tx_enter_date( gpointer pObject );
static void set_tx_enter_date( gpointer pObject, const gpointer pValue );
+#define TX_MAX_NUM_LEN 50
+#define TX_MAX_DESCRIPTION_LEN 500
+
static col_cvt_t tx_col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, NULL,
+ { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, NULL,
get_guid, set_guid },
- { "currency_guid", CT_GUID, 0, COL_NNUL, NULL,
+ { "currency_guid", CT_GUID, 0, COL_NNUL, NULL,
get_tx_currency, set_tx_currency },
- { "num", CT_STRING, 50, COL_NNUL, TRANS_NUM },
- { "post_date", CT_TIMESPEC, 0, COL_NNUL, NULL,
+ { "num", CT_STRING, TX_MAX_NUM_LEN, COL_NNUL, NULL,
+ get_tx_num, set_tx_num },
+ { "post_date", CT_TIMESPEC, 0, COL_NNUL, NULL,
get_tx_post_date, set_tx_post_date },
- { "enter_date", CT_TIMESPEC, 0, COL_NNUL, NULL,
+ { "enter_date", CT_TIMESPEC, 0, COL_NNUL, NULL,
get_tx_enter_date, set_tx_enter_date },
- { "description", CT_STRING, 500, 0, NULL,
+ { "description", CT_STRING, TX_MAX_DESCRIPTION_LEN, 0, NULL,
(GNC_GDA_FN_GETTER)xaccTransGetDescription,
(GNC_GDA_FN_SETTER)xaccTransSetDescription },
{ NULL }
@@ -103,23 +109,26 @@
static gpointer get_split_account( gpointer pObject );
static void set_split_account( gpointer pObject, const gpointer pValue );
+#define SPLIT_MAX_MEMO_LEN 50
+#define SPLIT_MAX_ACTION_LEN 50
+
static col_cvt_t split_col_table[] =
{
- { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, NULL,
+ { "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, NULL,
get_guid, set_guid },
- { "tx_guid", CT_GUID, 0, COL_NNUL, NULL,
+ { "tx_guid", CT_GUID, 0, COL_NNUL, NULL,
get_split_tx_guid, set_split_tx_guid },
- { "memo", CT_STRING, 50, COL_NNUL, SPLIT_MEMO },
- { "action", CT_STRING, 50, COL_NNUL, SPLIT_ACTION },
- { "reconcile_state", CT_STRING, 1, COL_NNUL, NULL,
+ { "memo", CT_STRING, SPLIT_MAX_MEMO_LEN, COL_NNUL, SPLIT_MEMO },
+ { "action", CT_STRING, SPLIT_MAX_ACTION_LEN, COL_NNUL, SPLIT_ACTION },
+ { "reconcile_state", CT_STRING, 1, COL_NNUL, NULL,
get_split_reconcile_state, set_split_reconcile_state },
- { "reconcile_date", CT_TIMESPEC, 0, COL_NNUL, NULL,
+ { "reconcile_date", CT_TIMESPEC, 0, COL_NNUL, NULL,
get_split_reconcile_date, set_split_reconcile_date },
- { "value", CT_NUMERIC, 0, COL_NNUL, NULL,
+ { "value", CT_NUMERIC, 0, COL_NNUL, NULL,
get_split_value, set_split_value },
- { "quantity", CT_NUMERIC, 0, COL_NNUL, NULL,
+ { "quantity", CT_NUMERIC, 0, COL_NNUL, NULL,
get_split_quantity, set_split_quantity },
- { "account_guid", CT_GUID, 0, COL_NNUL, NULL,
+ { "account_guid", CT_GUID, 0, COL_NNUL, NULL,
get_split_account, set_split_account },
{ NULL }
};
@@ -177,6 +186,25 @@
}
static gpointer
+get_tx_num( gpointer pObject )
+{
+ Transaction* pTx = (Transaction*)pObject;
+ const gchar* s;
+
+ s = xaccTransGetNum( pTx );
+ return (gpointer)s;
+}
+
+static void
+set_tx_num( gpointer pObject, const gpointer pValue )
+{
+ Transaction* pTx = (Transaction*)pObject;
+ const gchar* s = (const gchar*)pValue;
+
+ xaccTransSetNum( pTx, s );
+}
+
+static gpointer
get_tx_post_date( gpointer pObject )
{
Transaction* pTx = (Transaction*)pObject;
@@ -352,33 +380,22 @@
g_assert( pSplit == xaccSplitLookup( &split_guid, be->primary_book ) );
+ qof_instance_mark_clean( (QofInstance*)pSplit );
+
return pSplit;
}
static void
load_splits( GncGdaBackend* be, const GUID* guid )
{
- GError* error = NULL;
gchar* buf;
- GdaQuery* query;
GdaObject* ret;
gchar guid_buf[GUID_ENCODING_LENGTH+1];
guid_to_string_buff( guid, guid_buf );
buf = g_strdup_printf( "SELECT * FROM %s where tx_guid='%s'",
SPLIT_TABLE, guid_buf );
- query = gda_query_new_from_sql( be->pDict, buf, &error );
- g_free( buf );
- if( query == NULL ) {
- printf( "SQL error: %s\n", error->message );
- return;
- }
- error = NULL;
- ret = gda_query_execute( query, NULL, FALSE, &error );
-
- if( error != NULL ) {
- printf( "SQL error: %s\n", error->message );
- }
+ ret = gnc_gda_execute_sql( be, buf );
if( GDA_IS_DATA_MODEL( ret ) ) {
GdaDataModel* pModel = (GdaDataModel*)ret;
int numRows = gda_data_model_get_n_rows( pModel );
@@ -410,6 +427,8 @@
gnc_gda_slots_load( be, qof_instance_get_guid( (QofInstance*)pTx ),
qof_instance_get_slots( (QofInstance*)pTx ) );
load_splits( be, qof_instance_get_guid( (QofInstance*)pTx ) );
+
+ qof_instance_mark_clean( (QofInstance*)pTx );
xaccTransCommitEdit( pTx );
g_assert( pTx == xaccTransLookup( &tx_guid, be->primary_book ) );
@@ -490,20 +509,36 @@
}
/* ================================================================= */
static void
+delete_split_slots_cb( gpointer data, gpointer user_data )
+{
+ split_info_t* split_info = (split_info_t*)user_data;
+ Split* pSplit = (Split*)data;
+
+ gnc_gda_slots_delete( split_info->be, qof_instance_get_guid( (QofInstance*)pSplit ) );
+}
+
+static void
delete_splits( GncGdaBackend* be, Transaction* pTx )
{
+ split_info_t split_info;
+
(void)gnc_gda_do_db_operation( be, OP_DB_DELETE, SPLIT_TABLE,
SPLIT_TABLE, pTx, guid_col_table );
+ split_info.be = be;
+
+ g_list_foreach( xaccTransGetSplitList( pTx ), delete_split_slots_cb, &split_info );
}
static void
-save_split( gpointer data, gpointer user_data )
+save_split_cb( gpointer data, gpointer user_data )
{
split_info_t* split_info = (split_info_t*)user_data;
Split* pSplit = (Split*)data;
(void)gnc_gda_do_db_operation( split_info->be, OP_DB_ADD, SPLIT_TABLE,
GNC_ID_SPLIT, pSplit, split_col_table );
+ gnc_gda_slots_save( split_info->be, qof_instance_get_guid( (QofInstance*)pSplit ),
+ qof_instance_get_slots( (QofInstance*)pSplit ) );
}
static void
@@ -513,13 +548,14 @@
split_info.be = be;
split_info.guid = tx_guid;
- g_list_foreach( pSplitList, save_split, &split_info );
+ g_list_foreach( pSplitList, save_split_cb, &split_info );
}
static void
commit_transaction( GncGdaBackend* be, QofInstance* inst )
{
Transaction* pTx = (Transaction*)inst;
+ const GUID* guid;
// Ensure the commodity is in the db
gnc_gda_save_commodity( be, xaccTransGetCurrency( pTx ) );
@@ -530,12 +566,17 @@
GNC_ID_TRANS, pTx,
tx_col_table );
- // Delete any old splits for this transaction
+ guid = qof_instance_get_guid( inst );
+
+ // Delete any old slots and splits for this transaction
+ gnc_gda_slots_delete( be, guid );
delete_splits( be, pTx );
- // Now, commit any slots
- save_splits( be, qof_instance_get_guid( inst ),
- xaccTransGetSplitList( pTx ) );
+ if( !inst->do_free ) {
+ // Now, commit any slots and splits
+ gnc_gda_slots_save( be, guid, qof_instance_get_slots( inst ) );
+ save_splits( be, guid, xaccTransGetSplitList( pTx ) );
+ }
}
/* ================================================================= */
Modified: gnucash/branches/gda-dev/src/bin/Makefile.am
===================================================================
--- gnucash/branches/gda-dev/src/bin/Makefile.am 2006-11-26 04:07:45 UTC (rev 15144)
+++ gnucash/branches/gda-dev/src/bin/Makefile.am 2006-11-26 14:21:50 UTC (rev 15145)
@@ -53,8 +53,21 @@
mv $@.tmp $@
chmod u+x $@
-CLEANFILES = $(BUILT_SOURCES) gnucash gnucash-valgrind
+gnucash-gdb: gnucash-gdb.in ${top_builddir}/config.status Makefile
+ rm -f $@.tmp
+ sed < $< > $@.tmp \
+ -e 's#@-BIN_DIR-@#${bindir}#g' \
+ -e 's#@-GNC_GUILE_MODULE_DIR-@#${GNC_SHAREDIR}/guile-modules#g' \
+ -e 's#@-GNC_SCM_INSTALL_DIR-@#${GNC_SCM_INSTALL_DIR}#g' \
+ -e 's#@-GNC_LIB_INSTALLDIR-@#${libdir}#' \
+ -e 's#@-GNC_PKGLIB_INSTALLDIR-@#${pkglibdir}#g' \
+ -e 's#@-GNC_MODULE_DIR-@#${GNC_MODULE_DIR}#g' \
+ -e "s#@-TOP_SRC_DIR-@#`pwd`/${top_srcdir}#g"
+ mv $@.tmp $@
+ chmod u+x $@
+CLEANFILES = $(BUILT_SOURCES) gnucash gnucash-valgrind gnucash-gdb
+
# We handle gnucash scripts in a somewhat unexpected way, but we do
# this so that a user who doesn't necessarily have the right
# directories in their path can still invoke these commands via their
@@ -72,13 +85,13 @@
# by these top-level "common" scripts.
gnc_common_scripts = gnucash-env gnucash-make-guids
-bin_SCRIPTS = ${gnc_common_scripts} update-gnucash-gconf gnucash gnucash-valgrind
+bin_SCRIPTS = ${gnc_common_scripts} update-gnucash-gconf gnucash gnucash-valgrind gnucash-gdb
# if you change gncoverridedir, make sure you change ./overrides/Makefile.am too.
gncoverridesdir = ${GNC_LIBEXECDIR}/overrides
EXTRA_DIST = generate-gnc-script update-gnucash-gconf.in \
- gnucash.in gnucash-valgrind.in
+ gnucash.in gnucash-valgrind.in gnucash-gdb.in
## Gnucash scripts -- real code is in overrides, these just get you there.
${gnc_common_scripts}: generate-gnc-script ${top_builddir}/config.status
More information about the gnucash-changes
mailing list