45 #if defined( S_SPLINT_S )
46 #include "splint-defs.h"
51 #define TABLE_NAME "accounts"
52 #define TABLE_VERSION 1
54 static gpointer get_parent( gpointer pObject );
55 static void set_parent( gpointer pObject, gpointer pValue );
56 static void set_parent_guid( gpointer pObject, gpointer pValue );
58 #define ACCOUNT_MAX_NAME_LEN 2048
59 #define ACCOUNT_MAX_TYPE_LEN 2048
60 #define ACCOUNT_MAX_CODE_LEN 2048
61 #define ACCOUNT_MAX_DESCRIPTION_LEN 2048
67 {
"name", CT_STRING, ACCOUNT_MAX_NAME_LEN,
COL_NNUL,
"name" },
68 {
"account_type", CT_STRING, ACCOUNT_MAX_TYPE_LEN,
COL_NNUL, NULL, ACCOUNT_TYPE_ },
69 {
"commodity_guid", CT_COMMODITYREF, 0, 0,
"commodity" },
70 {
"commodity_scu", CT_INT, 0,
COL_NNUL,
"commodity-scu" },
71 {
"non_std_scu", CT_BOOLEAN, 0,
COL_NNUL,
"non-std-scu" },
73 "parent_guid", CT_GUID, 0, 0, NULL, NULL,
76 {
"code", CT_STRING, ACCOUNT_MAX_CODE_LEN, 0,
"code" },
77 {
"description", CT_STRING, ACCOUNT_MAX_DESCRIPTION_LEN, 0,
"description" },
78 {
"hidden", CT_BOOLEAN, 0, 0,
"hidden" },
79 {
"placeholder", CT_BOOLEAN, 0, 0,
"placeholder" },
86 {
"parent_guid", CT_GUID, 0, 0, NULL, NULL, NULL, set_parent_guid },
100 get_parent( gpointer pObject )
106 g_return_val_if_fail( pObject != NULL, NULL );
107 g_return_val_if_fail( GNC_IS_ACCOUNT(pObject), NULL );
109 pAccount = GNC_ACCOUNT(pObject);
111 if ( pParent == NULL )
120 return (gpointer)parent_guid;
124 set_parent( gpointer pObject, gpointer pValue )
131 g_return_if_fail( pObject != NULL );
132 g_return_if_fail( GNC_IS_ACCOUNT(pObject) );
134 pAccount = GNC_ACCOUNT(pObject);
139 if ( pParent != NULL )
147 set_parent_guid( gpointer pObject, gpointer pValue )
152 g_return_if_fail( pObject != NULL );
153 g_return_if_fail( pValue != NULL );
160 GList** l_accounts_needing_parents )
165 g_return_val_if_fail( be != NULL, NULL );
166 g_return_val_if_fail( row != NULL, NULL );
167 g_return_val_if_fail( l_accounts_needing_parents != NULL, NULL );
174 if ( pAccount == NULL )
185 && pAccount != gnc_book_get_root_account( be->
book ) )
188 g_assert( s != NULL );
190 s->pAccount = pAccount;
192 *l_accounts_needing_parents = g_list_prepend( *l_accounts_needing_parents, s );
204 GList* l_accounts_needing_parents = NULL;
208 g_return_if_fail( be != NULL );
217 LEAVE(
"stmt == NULL" );
221 gnc_sql_statement_dispose( stmt );
222 if ( result != NULL )
224 GncSqlRow* row = gnc_sql_result_get_first_row( result );
227 while ( row != NULL )
229 load_single_account( be, row, &l_accounts_needing_parents );
230 row = gnc_sql_result_get_next_row( result );
232 gnc_sql_result_dispose( result );
234 sql = g_strdup_printf(
"SELECT DISTINCT guid FROM %s", TABLE_NAME );
243 if ( l_accounts_needing_parents != NULL )
245 gboolean progress_made = TRUE;
250 while ( progress_made )
252 progress_made = FALSE;
253 for ( elem = l_accounts_needing_parents; elem != NULL; )
257 if ( pParent != NULL )
262 next_elem = g_list_next( elem );
263 l_accounts_needing_parents = g_list_delete_link( l_accounts_needing_parents, elem );
266 progress_made = TRUE;
272 elem = g_list_next( elem );
278 root = gnc_book_get_root_account( pBook );
279 while ( l_accounts_needing_parents != NULL )
287 l_accounts_needing_parents = g_list_delete_link( l_accounts_needing_parents, l_accounts_needing_parents );
293 for ( bal = bal_slist; bal != NULL; bal = bal->next )
297 qof_instance_increase_editlevel (balances->acct);
298 g_object_set( balances->acct,
299 "start-balance", &balances->balance,
300 "start-cleared-balance", &balances->cleared_balance,
301 "start-reconciled-balance", &balances->reconciled_balance,
304 qof_instance_decrease_editlevel (balances->acct);
306 if ( bal_slist != NULL )
308 g_slist_free( bal_slist );
321 g_return_if_fail( be != NULL );
334 Account* pAcc = GNC_ACCOUNT(inst);
337 gboolean is_ok = FALSE;
341 g_return_val_if_fail( be != NULL, FALSE );
342 g_return_val_if_fail( inst != NULL, FALSE );
343 g_return_val_if_fail( GNC_IS_ACCOUNT(inst), FALSE );
345 ENTER(
"inst=%p", inst );
347 is_infant = qof_instance_get_infant( inst );
370 if ( op != OP_DB_DELETE && commodity != NULL )
372 is_ok = gnc_sql_save_commodity( be, commodity );
394 LEAVE(
"is_ok=%d", is_ok );
409 g_return_if_fail( be != NULL );
410 g_return_if_fail( row != NULL );
411 g_return_if_fail( pObject != NULL );
412 g_return_if_fail( table_row != NULL );
414 val = gnc_sql_row_get_value_at_col_name( row, table_row->
col_name );
415 if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
419 if ( account != NULL )
423 qof_instance_increase_editlevel (pObject);
425 qof_instance_decrease_editlevel (pObject);
429 g_return_if_fail( setter != NULL );
430 (*setter)( pObject, (
const gpointer)account );
435 PWARN(
"Account ref '%s' not found", g_value_get_string( val ) );
441 = { load_account_guid,
448 gnc_sql_init_account_handler(
void )
452 GNC_SQL_BACKEND_VERSION,
454 gnc_sql_save_account,
456 create_account_tables,
Account * gnc_account_get_parent(const Account *acc)
gboolean qof_object_register_backend(QofIdTypeConst type_name, const char *backend_name, gpointer be_data)
void gnc_account_append_child(Account *new_parent, Account *child)
const GncGUID * qof_instance_get_guid(gconstpointer)
gint gnc_sql_get_table_version(const GncSqlBackend *be, const gchar *table_name)
QofBook * qof_instance_get_book(gconstpointer)
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
load and save data to SQL
void gnc_sql_add_colname_to_list(const GncSqlColumnTableEntry *table_row, GList **pList)
GNCAccountType xaccAccountGetType(const Account *acc)
load and save accounts data to SQL
GncSqlStatement * gnc_sql_create_select_statement(GncSqlBackend *be, const gchar *table_name)
gboolean qof_instance_get_destroying(gconstpointer ptr)
gboolean string_to_guid(const gchar *string, GncGUID *guid)
gboolean gnc_sql_create_table(GncSqlBackend *be, const gchar *table_name, gint table_version, const GncSqlColumnTableEntry *col_table)
load and save data to SQL
void gnc_sql_register_col_type_handler(const gchar *colType, const GncSqlColumnTypeHandler *handler)
void gnc_sql_add_objectref_guid_col_info_to_list(const GncSqlBackend *be, const GncSqlColumnTableEntry *table_row, GList **pList)
gpointer(* QofAccessFunc)(gpointer object, const QofParam *param)
#define ENTER(format, args...)
#define PWARN(format, args...)
const GncGUID * gnc_sql_load_guid(const GncSqlBackend *be, GncSqlRow *row)
void gnc_sql_slots_load_for_sql_subquery(GncSqlBackend *be, const gchar *subquery, BookLookupFn lookup_fn)
Account handling public routines.
load and save accounts data to SQL
void gnc_sql_add_gvalue_objectref_guid_to_slist(const GncSqlBackend *be, QofIdTypeConst obj_name, const gpointer pObject, const GncSqlColumnTableEntry *table_row, GSList **pList)
load and save data to SQL
GSList * gnc_sql_get_account_balances_slist(GncSqlBackend *be)
GncSqlResult * gnc_sql_execute_select_statement(GncSqlBackend *be, GncSqlStatement *stmt)
void gnc_sql_load_object(const GncSqlBackend *be, GncSqlRow *row, QofIdTypeConst obj_name, gpointer pObject, const GncSqlColumnTableEntry *table)
const gchar * gobj_param_name
gboolean gnc_sql_slots_delete(GncSqlBackend *be, const GncGUID *guid)
void xaccAccountBeginEdit(Account *acc)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
#define LEAVE(format, args...)
void(* QofSetterFunc)(gpointer, gpointer)
Account * xaccMallocAccount(QofBook *book)
gboolean gnc_sql_do_db_operation(GncSqlBackend *be, E_DB_OPERATION op, const gchar *table_name, QofIdTypeConst obj_name, gpointer pObject, const GncSqlColumnTableEntry *table)
void xaccAccountCommitEdit(Account *acc)
Commodity handling public routines.
gboolean gnc_sql_slots_save(GncSqlBackend *be, const GncGUID *guid, gboolean is_infant, KvpFrame *pFrame)
const gchar * QofLogModule
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)