mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Fix some splint issues
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@17928 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
905d7551a8
commit
e9929bd401
@ -12,7 +12,6 @@ AM_CFLAGS = \
|
||||
-I${top_srcdir}/lib/libc\
|
||||
${QOF_CFLAGS} \
|
||||
${GLIB_CFLAGS} \
|
||||
${LIBGDA_CFLAGS} \
|
||||
${GCONF_CFLAGS} \
|
||||
${WARN_CFLAGS}
|
||||
|
||||
|
@ -58,6 +58,7 @@ static void set_parent_guid( gpointer pObject, gpointer pValue );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "name", CT_STRING, ACCOUNT_MAX_NAME_LEN, COL_NNUL, "name" },
|
||||
{ "account_type", CT_STRING, ACCOUNT_MAX_TYPE_LEN, COL_NNUL, NULL, ACCOUNT_TYPE_ },
|
||||
@ -68,11 +69,14 @@ static const GncSqlColumnTableEntry col_table[] =
|
||||
{ "code", CT_STRING, ACCOUNT_MAX_CODE_LEN, 0, "code" },
|
||||
{ "description", CT_STRING, ACCOUNT_MAX_DESCRIPTION_LEN, 0, "description" },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
static GncSqlColumnTableEntry parent_col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "parent_guid", CT_GUID, 0, 0, NULL, NULL, NULL, set_parent_guid },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
@ -162,7 +166,7 @@ load_single_account( GncSqlBackend* be, GncSqlRow* row,
|
||||
/* If we don't have a parent, it might be because the parent account hasn't
|
||||
been loaded yet. Remember the account and its parent guid for later. */
|
||||
if( gnc_account_get_parent( pAccount ) == NULL ) {
|
||||
account_parent_guid_struct* s = g_slice_new( account_parent_guid_struct );
|
||||
account_parent_guid_struct* s = g_malloc( (gsize)sizeof(account_parent_guid_struct) );
|
||||
s->pAccount = pAccount;
|
||||
gnc_sql_load_object( be, row, GNC_ID_ACCOUNT, s, parent_col_table );
|
||||
*l_accounts_needing_parents = g_list_prepend( *l_accounts_needing_parents, s );
|
||||
@ -178,9 +182,6 @@ load_all_accounts( GncSqlBackend* be )
|
||||
GncSqlResult* result;
|
||||
QofBook* pBook;
|
||||
gnc_commodity_table* pTable;
|
||||
int numRows;
|
||||
int r;
|
||||
Account* parent;
|
||||
GList* l_accounts_needing_parents = NULL;
|
||||
GList* list = NULL;
|
||||
GSList* bal_slist;
|
||||
@ -188,6 +189,8 @@ load_all_accounts( GncSqlBackend* be )
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
ENTER( "" );
|
||||
|
||||
pBook = be->primary_book;
|
||||
pTable = gnc_commodity_table_get_table( pBook );
|
||||
|
||||
@ -226,13 +229,13 @@ load_all_accounts( GncSqlBackend* be )
|
||||
progress_made = FALSE;
|
||||
for( elem = l_accounts_needing_parents; elem != NULL; elem = g_list_next( elem ) ) {
|
||||
account_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
|
||||
const gchar* name = xaccAccountGetName( s->pAccount );
|
||||
pParent = xaccAccountLookup( &s->guid, be->primary_book );
|
||||
if( pParent != NULL ) {
|
||||
gnc_account_append_child( pParent, s->pAccount );
|
||||
l_accounts_needing_parents = g_list_delete_link( l_accounts_needing_parents, elem );
|
||||
progress_made = TRUE;
|
||||
}
|
||||
g_free( elem );
|
||||
}
|
||||
}
|
||||
|
||||
@ -262,6 +265,8 @@ load_all_accounts( GncSqlBackend* be )
|
||||
}
|
||||
g_slist_free( bal_slist );
|
||||
}
|
||||
|
||||
LEAVE( "" );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
@ -274,7 +279,7 @@ create_account_tables( GncSqlBackend* be )
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
(void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
@ -291,6 +296,8 @@ gnc_sql_save_account( GncSqlBackend* be, QofInstance* inst )
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_ACCOUNT(inst), FALSE );
|
||||
|
||||
ENTER( "" );
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
|
||||
// If there is no commodity yet, this might be because a new account name
|
||||
@ -329,6 +336,8 @@ gnc_sql_save_account( GncSqlBackend* be, QofInstance* inst )
|
||||
}
|
||||
}
|
||||
|
||||
LEAVE( "" );
|
||||
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
@ -380,7 +389,11 @@ gnc_sql_init_account_handler( void )
|
||||
GNC_ID_ACCOUNT,
|
||||
gnc_sql_save_account, /* commit */
|
||||
load_all_accounts, /* initial_load */
|
||||
create_account_tables /* create_tables */
|
||||
create_account_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_ACCOUNT, GNC_SQL_BACKEND, &be_data );
|
||||
|
@ -59,7 +59,9 @@
|
||||
#include "gnc-slots-sql.h"
|
||||
#include "gnc-transaction-sql.h"
|
||||
|
||||
#if 0
|
||||
static const gchar* convert_search_obj( QofIdType objType );
|
||||
#endif
|
||||
static void gnc_sql_init_object_handlers( void );
|
||||
static void update_save_progress( GncSqlBackend* be );
|
||||
static void register_standard_col_type_handlers( void );
|
||||
@ -156,7 +158,6 @@ gnc_sql_load( GncSqlBackend* be, QofBook *book, QofBackendLoadType loadType )
|
||||
GncSqlObjectBackend* pData;
|
||||
int i;
|
||||
Account* root;
|
||||
GError* error = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( book != NULL );
|
||||
@ -166,7 +167,7 @@ gnc_sql_load( GncSqlBackend* be, QofBook *book, QofBackendLoadType loadType )
|
||||
be->loading = TRUE;
|
||||
|
||||
if( loadType == LOAD_TYPE_INITIAL_LOAD ) {
|
||||
g_assert( be->primary_book == NULL );
|
||||
/*# -ifempty */ g_assert( be->primary_book == NULL );
|
||||
be->primary_book = book;
|
||||
|
||||
/* Load any initial stuff. Some of this needs to happen in a certain order */
|
||||
@ -198,6 +199,7 @@ gnc_sql_load( GncSqlBackend* be, QofBook *book, QofBackendLoadType loadType )
|
||||
|
||||
/* ================================================================= */
|
||||
|
||||
#if 0
|
||||
static gint
|
||||
compare_namespaces(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
@ -244,6 +246,7 @@ write_commodities( GncSqlBackend* be, QofBook* book )
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static gboolean
|
||||
write_account_tree( GncSqlBackend* be, Account* root )
|
||||
@ -273,11 +276,6 @@ write_accounts( GncSqlBackend* be )
|
||||
return write_account_tree( be, gnc_book_get_root_account( be->primary_book ) );
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GncSqlBackend* be;
|
||||
gboolean is_ok;
|
||||
} write_objects_t;
|
||||
|
||||
static int
|
||||
write_tx( Transaction* tx, gpointer data )
|
||||
{
|
||||
@ -369,10 +367,10 @@ static void
|
||||
update_save_progress( GncSqlBackend* be )
|
||||
{
|
||||
if( be->be.percentage != NULL ) {
|
||||
gint percent_done;
|
||||
double percent_done;
|
||||
|
||||
be->operations_done++;
|
||||
percent_done = be->operations_done * 100 / be->obj_total;
|
||||
percent_done = be->operations_done * 100.0 / be->obj_total;
|
||||
if( percent_done > 100 ) {
|
||||
percent_done = 100;
|
||||
}
|
||||
@ -383,9 +381,6 @@ update_save_progress( GncSqlBackend* be )
|
||||
void
|
||||
gnc_sql_sync_all( GncSqlBackend* be, QofBook *book )
|
||||
{
|
||||
GError* error = NULL;
|
||||
gint row;
|
||||
gint numTables;
|
||||
gboolean is_ok;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
@ -406,7 +401,6 @@ gnc_sql_sync_all( GncSqlBackend* be, QofBook *book )
|
||||
be->obj_total += gnc_book_count_transactions( book );
|
||||
be->operations_done = 0;
|
||||
|
||||
error = NULL;
|
||||
gnc_sql_connection_begin_transaction( be->conn );
|
||||
|
||||
// FIXME: should write the set of commodities that are used
|
||||
@ -480,7 +474,6 @@ void
|
||||
gnc_sql_commit_edit( GncSqlBackend *be, QofInstance *inst )
|
||||
{
|
||||
sql_backend be_data;
|
||||
GError* error;
|
||||
gboolean is_dirty;
|
||||
gboolean is_destroying;
|
||||
gboolean is_infant;
|
||||
@ -517,7 +510,6 @@ gnc_sql_commit_edit( GncSqlBackend *be, QofInstance *inst )
|
||||
return;
|
||||
}
|
||||
|
||||
error = NULL;
|
||||
gnc_sql_connection_begin_transaction( be->conn );
|
||||
|
||||
be_data.is_known = FALSE;
|
||||
@ -554,7 +546,7 @@ gnc_sql_commit_edit( GncSqlBackend *be, QofInstance *inst )
|
||||
/* ---------------------------------------------------------------------- */
|
||||
|
||||
/* Query processing */
|
||||
|
||||
#if 0
|
||||
static const gchar*
|
||||
convert_search_obj( QofIdType objType )
|
||||
{
|
||||
@ -651,6 +643,7 @@ handle_and_term( QofQueryTerm* pTerm, gchar* sql )
|
||||
|
||||
strcat( sql, ")" );
|
||||
}
|
||||
#endif
|
||||
|
||||
static void
|
||||
compile_query_cb( const gchar* type, gpointer data_p, gpointer be_data_p )
|
||||
@ -677,9 +670,7 @@ gpointer
|
||||
gnc_sql_compile_query( QofBackend* pBEnd, QofQuery* pQuery )
|
||||
{
|
||||
GncSqlBackend *be = (GncSqlBackend*)pBEnd;
|
||||
GList* pBookList;
|
||||
QofIdType searchObj;
|
||||
gchar sql[1000];
|
||||
sql_backend be_data;
|
||||
gnc_sql_query_info* pQueryInfo;
|
||||
|
||||
@ -690,7 +681,7 @@ gnc_sql_compile_query( QofBackend* pBEnd, QofQuery* pQuery )
|
||||
|
||||
searchObj = qof_query_get_search_for( pQuery );
|
||||
|
||||
pQueryInfo = g_malloc( sizeof( gnc_sql_query_info ) );
|
||||
pQueryInfo = g_malloc( (gsize)sizeof( gnc_sql_query_info ) );
|
||||
|
||||
// Try various objects first
|
||||
be_data.is_ok = FALSE;
|
||||
@ -705,6 +696,7 @@ gnc_sql_compile_query( QofBackend* pBEnd, QofQuery* pQuery )
|
||||
return be_data.pQueryInfo;
|
||||
}
|
||||
|
||||
#if 0
|
||||
pBookList = qof_query_get_books( pQuery );
|
||||
|
||||
/* Convert search object type to table name */
|
||||
@ -733,6 +725,7 @@ gnc_sql_compile_query( QofBackend* pBEnd, QofQuery* pQuery )
|
||||
|
||||
DEBUG( "Compiled: %s\n", sql );
|
||||
pQueryInfo->pCompiledQuery = g_strdup( sql );
|
||||
#endif
|
||||
|
||||
LEAVE( "" );
|
||||
|
||||
@ -871,17 +864,17 @@ gnc_sql_get_integer_value( const GValue* value )
|
||||
g_return_val_if_fail( value != NULL, 0 );
|
||||
|
||||
if( G_VALUE_HOLDS_INT(value) ) {
|
||||
return g_value_get_int( value );
|
||||
return (gint64)g_value_get_int( value );
|
||||
} else if( G_VALUE_HOLDS_UINT(value) ) {
|
||||
return g_value_get_uint( value );
|
||||
return (gint64)g_value_get_uint( value );
|
||||
} else if( G_VALUE_HOLDS_LONG(value) ) {
|
||||
return g_value_get_long( value );
|
||||
return (gint64)g_value_get_long( value );
|
||||
} else if( G_VALUE_HOLDS_ULONG(value) ) {
|
||||
return g_value_get_ulong( value );
|
||||
return (gint64)g_value_get_ulong( value );
|
||||
} else if( G_VALUE_HOLDS_INT64(value) ) {
|
||||
return g_value_get_int64( value );
|
||||
} else if( G_VALUE_HOLDS_UINT64(value) ) {
|
||||
return g_value_get_uint64( value );
|
||||
return (gint64)g_value_get_uint64( value );
|
||||
} else {
|
||||
PWARN( "Unknown type: %s", G_VALUE_TYPE_NAME( value ) );
|
||||
}
|
||||
@ -1010,7 +1003,6 @@ add_gvalue_string_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
QofAccessFunc getter;
|
||||
gchar* s;
|
||||
GValue* value = g_new0( GValue, 1 );
|
||||
gchar* buf;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( obj_name != NULL );
|
||||
@ -1025,7 +1017,7 @@ add_gvalue_string_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
getter = gnc_sql_get_getter( obj_name, table_row );
|
||||
s = (gchar*)(*getter)( pObject, NULL );
|
||||
}
|
||||
g_value_init( value, G_TYPE_STRING );
|
||||
(void)g_value_init( value, G_TYPE_STRING );
|
||||
if( s ) {
|
||||
g_value_set_string( value, s );
|
||||
}
|
||||
@ -1060,7 +1052,7 @@ load_int( const GncSqlBackend* be, GncSqlRow* row,
|
||||
if( val == NULL ) {
|
||||
int_value = 0;
|
||||
} else {
|
||||
int_value = gnc_sql_get_integer_value( val );
|
||||
int_value = (gint)gnc_sql_get_integer_value( val );
|
||||
}
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, int_value, NULL );
|
||||
@ -1100,7 +1092,7 @@ add_gvalue_int_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
g_return_if_fail( pList != NULL );
|
||||
|
||||
value = g_new0( GValue, 1 );
|
||||
g_value_init( value, G_TYPE_INT );
|
||||
(void)g_value_init( value, G_TYPE_INT );
|
||||
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_get_property( pObject, table_row->gobj_param_name, value );
|
||||
@ -1140,7 +1132,7 @@ load_boolean( const GncSqlBackend* be, GncSqlRow* row,
|
||||
if( val == NULL ) {
|
||||
int_value = 0;
|
||||
} else {
|
||||
int_value = g_value_get_int64( val );
|
||||
int_value = (gint)gnc_sql_get_integer_value( val );
|
||||
}
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, int_value, NULL );
|
||||
@ -1187,7 +1179,7 @@ add_gvalue_boolean_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
b_getter = (BooleanAccessFunc)gnc_sql_get_getter( obj_name, table_row );
|
||||
int_value = ((*b_getter)( pObject )) ? 1 : 0;
|
||||
}
|
||||
g_value_init( value, G_TYPE_INT );
|
||||
(void)g_value_init( value, G_TYPE_INT );
|
||||
g_value_set_int( value, int_value );
|
||||
|
||||
(*pList) = g_slist_append( (*pList), value );
|
||||
@ -1260,7 +1252,7 @@ add_gvalue_int64_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
getter = (Int64AccessFunc)gnc_sql_get_getter( obj_name, table_row );
|
||||
i64_value = (*getter)( pObject );
|
||||
}
|
||||
g_value_init( value, G_TYPE_INT64 );
|
||||
(void)g_value_init( value, G_TYPE_INT64 );
|
||||
g_value_set_int64( value, i64_value );
|
||||
|
||||
(*pList) = g_slist_append( (*pList), value );
|
||||
@ -1291,7 +1283,7 @@ load_double( const GncSqlBackend* be, GncSqlRow* row,
|
||||
(*setter)( pObject, (gpointer)NULL );
|
||||
} else {
|
||||
if( G_VALUE_HOLDS(val, G_TYPE_INT) ) {
|
||||
d_value = g_value_get_int( val );
|
||||
d_value = (gdouble)g_value_get_int( val );
|
||||
} else {
|
||||
d_value = g_value_get_double( val );
|
||||
}
|
||||
@ -1333,11 +1325,11 @@ add_gvalue_double_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
pDouble = (*getter)( pObject, NULL );
|
||||
if( pDouble != NULL ) {
|
||||
d_value = *pDouble;
|
||||
g_value_init( value, G_TYPE_DOUBLE );
|
||||
(void)g_value_init( value, G_TYPE_DOUBLE );
|
||||
g_value_set_double( value, d_value );
|
||||
} else {
|
||||
g_value_init( value, G_TYPE_DOUBLE );
|
||||
g_value_set_double( value, 0 );
|
||||
(void)g_value_init( value, G_TYPE_DOUBLE );
|
||||
g_value_set_double( value, 0.0 );
|
||||
}
|
||||
|
||||
(*pList) = g_slist_append( (*pList), value );
|
||||
@ -1414,7 +1406,7 @@ add_gvalue_guid_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
getter = gnc_sql_get_getter( obj_name, table_row );
|
||||
guid = (*getter)( pObject, NULL );
|
||||
}
|
||||
g_value_init( value, G_TYPE_STRING );
|
||||
(void)g_value_init( value, G_TYPE_STRING );
|
||||
if( guid != NULL ) {
|
||||
(void)guid_to_string_buff( guid, guid_buf );
|
||||
g_value_set_string( value, guid_buf );
|
||||
@ -1455,7 +1447,7 @@ gnc_sql_add_gvalue_objectref_guid_to_slist( const GncSqlBackend* be, QofIdTypeCo
|
||||
if( inst != NULL ) {
|
||||
guid = qof_instance_get_guid( inst );
|
||||
}
|
||||
g_value_init( value, G_TYPE_STRING );
|
||||
(void)g_value_init( value, G_TYPE_STRING );
|
||||
if( guid != NULL ) {
|
||||
(void)guid_to_string_buff( guid, guid_buf );
|
||||
g_value_set_string( value, guid_buf );
|
||||
@ -1485,7 +1477,6 @@ load_timespec( const GncSqlBackend* be, GncSqlRow* row,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GDate* date;
|
||||
Timespec ts = {0, 0};
|
||||
TimespecSetterFunc ts_setter;
|
||||
|
||||
@ -1564,7 +1555,7 @@ add_gvalue_timespec_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
|
||||
datebuf = g_strdup_printf( TIMESPEC_STR_FORMAT,
|
||||
year, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec );
|
||||
g_value_init( value, G_TYPE_STRING );
|
||||
(void)g_value_init( value, G_TYPE_STRING );
|
||||
g_value_take_string( value, datebuf );
|
||||
|
||||
(*pList) = g_slist_append( (*pList), value );
|
||||
@ -1601,15 +1592,16 @@ load_date( const GncSqlBackend* be, GncSqlRow* row,
|
||||
// Format of date is YYYYMMDD
|
||||
const gchar* s = g_value_get_string( val );
|
||||
gchar buf[5];
|
||||
guint year, month, day;
|
||||
guint month, day;
|
||||
GDateYear year;
|
||||
|
||||
strncpy( buf, &s[0], 4 );
|
||||
buf[4] = '\0';
|
||||
year = atoi( buf );
|
||||
year = (GDateYear)atoi( buf );
|
||||
strncpy( buf, &s[4], 2 );
|
||||
buf[2] = '\0';
|
||||
month = atoi( buf );
|
||||
day = atoi( &s[6] );
|
||||
month = (guint)atoi( buf );
|
||||
day = (guint)atoi( &s[6] );
|
||||
|
||||
if( year != 0 || month != 0 || day != 0 ) {
|
||||
date = g_date_new_dmy( day, month, year );
|
||||
@ -1657,7 +1649,7 @@ add_gvalue_date_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
date = (GDate*)(*getter)( pObject, NULL );
|
||||
buf = g_strdup_printf( "%04d%02d%02d",
|
||||
g_date_get_year( date ), g_date_get_month( date ), g_date_get_day( date ) );
|
||||
g_value_init( value, G_TYPE_STRING );
|
||||
(void)g_value_init( value, G_TYPE_STRING );
|
||||
g_value_take_string( value, buf );
|
||||
|
||||
(*pList) = g_slist_append( (*pList), value );
|
||||
@ -1674,9 +1666,11 @@ typedef void (*NumericSetterFunc)( gpointer, gnc_numeric );
|
||||
|
||||
static const GncSqlColumnTableEntry numeric_col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "num", CT_INT64, 0, COL_NNUL, "guid" },
|
||||
{ "denom", CT_INT64, 0, COL_NNUL, "guid" },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
static void
|
||||
@ -1727,7 +1721,6 @@ add_numeric_col_info_to_list( const GncSqlBackend* be, const GncSqlColumnTableEn
|
||||
GncSqlColumnInfo* info;
|
||||
gchar* buf;
|
||||
const GncSqlColumnTableEntry* subtable_row;
|
||||
const gchar* type;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
@ -1773,10 +1766,10 @@ add_gvalue_numeric_to_slist( const GncSqlBackend* be, QofIdTypeConst obj_name,
|
||||
// }
|
||||
|
||||
num_value = g_new0( GValue, 1 );
|
||||
g_value_init( num_value, G_TYPE_INT64 );
|
||||
(void)g_value_init( num_value, G_TYPE_INT64 );
|
||||
g_value_set_int64( num_value, gnc_numeric_num( n ) );
|
||||
denom_value = g_new0( GValue, 1 );
|
||||
g_value_init( denom_value, G_TYPE_INT64 );
|
||||
(void)g_value_init( denom_value, G_TYPE_INT64 );
|
||||
g_value_set_int64( denom_value, gnc_numeric_denom( n ) );
|
||||
|
||||
(*pList) = g_slist_append( (*pList), num_value );
|
||||
@ -1852,8 +1845,10 @@ _retrieve_guid_( gpointer pObject, gpointer pValue )
|
||||
// Table to retrieve just the guid
|
||||
static GncSqlColumnTableEntry guid_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "guid", CT_GUID, 0, 0, NULL, NULL, NULL, _retrieve_guid_ },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
const GUID*
|
||||
@ -1872,8 +1867,10 @@ gnc_sql_load_guid( const GncSqlBackend* be, GncSqlRow* row )
|
||||
// Table to retrieve just the guid
|
||||
static GncSqlColumnTableEntry tx_guid_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "tx_guid", CT_GUID, 0, 0, NULL, NULL, NULL, _retrieve_guid_ },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
const GUID*
|
||||
@ -2052,14 +2049,14 @@ gnc_sql_append_guid_list_to_sql( GString* sql, GList* list, guint maxCount )
|
||||
|
||||
for( count = 0; list != NULL && count < maxCount; list = list->next, count++ ) {
|
||||
QofInstance* inst = QOF_INSTANCE(list->data);
|
||||
guid_to_string_buff( qof_instance_get_guid( inst ), guid_buf );
|
||||
(void)guid_to_string_buff( qof_instance_get_guid( inst ), guid_buf );
|
||||
|
||||
if( !first_guid ) {
|
||||
g_string_append( sql, "," );
|
||||
(void)g_string_append( sql, "," );
|
||||
}
|
||||
g_string_append( sql, "'" );
|
||||
g_string_append( sql, guid_buf );
|
||||
g_string_append( sql, "'" );
|
||||
(void)g_string_append( sql, "'" );
|
||||
(void)g_string_append( sql, guid_buf );
|
||||
(void)g_string_append( sql, "'" );
|
||||
first_guid = FALSE;
|
||||
}
|
||||
|
||||
@ -2233,16 +2230,16 @@ build_insert_statement( GncSqlBackend* be,
|
||||
GValue* value = (GValue*)node->data;
|
||||
gchar* value_str;
|
||||
if( node != values ) {
|
||||
g_string_append( sql, "," );
|
||||
(void)g_string_append( sql, "," );
|
||||
}
|
||||
value_str = gnc_sql_get_sql_value( be->conn, value );
|
||||
g_string_append( sql, value_str );
|
||||
(void)g_string_append( sql, value_str );
|
||||
g_free( value_str );
|
||||
g_value_reset( value );
|
||||
(void)g_value_reset( value );
|
||||
g_free( value );
|
||||
}
|
||||
g_slist_free( values );
|
||||
g_string_append( sql, ")" );
|
||||
(void)g_string_append( sql, ")" );
|
||||
|
||||
stmt = gnc_sql_connection_create_statement_from_sql( be->conn, sql->str );
|
||||
return stmt;
|
||||
@ -2291,12 +2288,12 @@ build_update_statement( GncSqlBackend* be,
|
||||
colname = colname->next, value = value->next ) {
|
||||
gchar* value_str;
|
||||
if( !firstCol ) {
|
||||
g_string_append( sql, "," );
|
||||
(void)g_string_append( sql, "," );
|
||||
}
|
||||
g_string_append( sql, (gchar*)colname->data );
|
||||
g_string_append( sql, "=" );
|
||||
(void)g_string_append( sql, (gchar*)colname->data );
|
||||
(void)g_string_append( sql, "=" );
|
||||
value_str = gnc_sql_get_sql_value( be->conn, (GValue*)(value->data) );
|
||||
g_string_append( sql, value_str );
|
||||
(void)g_string_append( sql, value_str );
|
||||
g_free( value_str );
|
||||
firstCol = FALSE;
|
||||
}
|
||||
@ -2472,7 +2469,6 @@ gnc_sql_upgrade_table( GncSqlBackend* be, const gchar* table_name,
|
||||
{
|
||||
gchar* sql;
|
||||
gchar* temp_table_name;
|
||||
GncSqlStatement* stmt;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( table_name != NULL );
|
||||
@ -2502,9 +2498,11 @@ gnc_sql_upgrade_table( GncSqlBackend* be, const gchar* table_name,
|
||||
|
||||
static GncSqlColumnTableEntry version_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ TABLE_COL_NAME, CT_STRING, MAX_TABLE_NAME_LEN },
|
||||
{ VERSION_COL_NAME, CT_INT },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -697,4 +697,9 @@ gpointer gnc_sql_compile_query( QofBackend* pBEnd, QofQuery* pQuery );
|
||||
void gnc_sql_free_query( QofBackend* pBEnd, gpointer pQuery );
|
||||
void gnc_sql_run_query( QofBackend* pBEnd, gpointer pQuery );
|
||||
|
||||
typedef struct {
|
||||
GncSqlBackend* be;
|
||||
gboolean is_ok;
|
||||
} write_objects_t;
|
||||
|
||||
#endif /* GNC_BACKEND_SQL_H_ */
|
||||
|
@ -54,10 +54,12 @@ static void set_root_template_guid( gpointer pObject, gpointer pValue );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "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 }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -193,10 +195,6 @@ create_book_tables( GncSqlBackend* be )
|
||||
gboolean
|
||||
gnc_sql_save_book( GncSqlBackend* be, QofInstance* inst)
|
||||
{
|
||||
const GUID* guid;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( QOF_IS_BOOK(inst), FALSE );
|
||||
@ -212,11 +210,15 @@ gnc_sql_init_book_handler( void )
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_BOOK,
|
||||
gnc_sql_save_book, /* commit */
|
||||
load_all_books, /* initial_load */
|
||||
create_book_tables /* create_tables */
|
||||
gnc_sql_save_book, /* commit */
|
||||
load_all_books, /* initial_load */
|
||||
create_book_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_BOOK, GNC_SQL_BACKEND, &be_data );
|
||||
(void)qof_object_register_backend( GNC_ID_BOOK, GNC_SQL_BACKEND, &be_data );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
||||
|
@ -52,11 +52,13 @@ static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "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 }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -95,7 +97,6 @@ load_all_budgets( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
int r;
|
||||
GList* list = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
@ -179,11 +180,6 @@ save_budget( GncSqlBackend* be, QofInstance* inst )
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GncSqlBackend* be;
|
||||
gboolean is_ok;
|
||||
} write_objects_t;
|
||||
|
||||
static void
|
||||
do_save_budget( QofInstance* inst, gpointer data )
|
||||
{
|
||||
@ -220,7 +216,9 @@ gnc_sql_init_budget_handler( void )
|
||||
save_budget, /* commit */
|
||||
load_all_budgets, /* initial_load */
|
||||
create_budget_tables, /* create_tables */
|
||||
NULL, NULL, NULL,
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
write_budgets /* write */
|
||||
};
|
||||
|
||||
|
@ -54,6 +54,7 @@ static void set_quote_source_name( gpointer pObject, gpointer pValue );
|
||||
#define COMMODITY_MAX_QUOTE_TZ_LEN 2048
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] = {
|
||||
/*# -fullinitblock */
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "namespace", CT_STRING, COMMODITY_MAX_NAMESPACE_LEN, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gnc_commodity_get_namespace,
|
||||
@ -67,6 +68,7 @@ static const GncSqlColumnTableEntry col_table[] = {
|
||||
get_quote_source_name, set_quote_source_name },
|
||||
{ "quote_tz", CT_STRING, COMMODITY_MAX_QUOTE_TZ_LEN, 0, "quote-tz" },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -103,8 +105,6 @@ static gnc_commodity*
|
||||
load_single_commodity( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
QofBook* pBook = be->primary_book;
|
||||
int col;
|
||||
const GValue* val;
|
||||
gnc_commodity* pCommodity;
|
||||
|
||||
pCommodity = gnc_commodity_new( pBook, NULL, NULL, NULL, NULL, 100 );
|
||||
@ -127,14 +127,11 @@ load_all_commodities( GncSqlBackend* be )
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
int r;
|
||||
gnc_commodity* pCommodity;
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
while( row != NULL ) {
|
||||
gnc_commodity* c;
|
||||
|
||||
pCommodity = load_single_commodity( be, row );
|
||||
|
||||
if( pCommodity != NULL ) {
|
||||
@ -172,8 +169,6 @@ create_commodities_tables( GncSqlBackend* be )
|
||||
static gboolean
|
||||
commit_commodity( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
const GUID* guid;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_COMMODITY(inst), FALSE );
|
||||
@ -255,7 +250,11 @@ gnc_sql_init_commodity_handler( void )
|
||||
GNC_ID_COMMODITY,
|
||||
commit_commodity, /* commit */
|
||||
load_all_commodities, /* initial_load */
|
||||
create_commodities_tables /* create_tables */
|
||||
create_commodities_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_COMMODITY, GNC_SQL_BACKEND, &be_data );
|
||||
|
@ -49,11 +49,13 @@ static void set_lot_is_closed( gpointer pObject, gboolean value );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "account_guid", CT_GUID, 0, 0, NULL, NULL, get_lot_account, set_lot_account },
|
||||
{ "is_closed", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)gnc_lot_is_closed, (QofSetterFunc)set_lot_is_closed },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -129,7 +131,6 @@ load_all_lots( GncSqlBackend* be )
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
int r;
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
GNCLot* lot;
|
||||
@ -185,11 +186,6 @@ commit_lot( GncSqlBackend* be, QofInstance* inst )
|
||||
return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_LOT, col_table );
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GncSqlBackend* be;
|
||||
gboolean is_ok;
|
||||
} write_objects_t;
|
||||
|
||||
static void
|
||||
do_save_lot( QofInstance* inst, gpointer data )
|
||||
{
|
||||
|
@ -49,6 +49,7 @@ static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "commodity_guid", CT_COMMODITYREF, 0, COL_NNUL, NULL, PRICE_COMMODITY },
|
||||
{ "currency_guid", CT_COMMODITYREF, 0, COL_NNUL, NULL, PRICE_CURRENCY },
|
||||
@ -57,6 +58,7 @@ static const GncSqlColumnTableEntry col_table[] =
|
||||
{ "type", CT_STRING, PRICE_MAX_TYPE_LEN, 0, NULL, PRICE_TYPE },
|
||||
{ "value", CT_NUMERIC, 0, COL_NNUL, NULL, PRICE_VALUE },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -94,7 +96,6 @@ load_all_prices( GncSqlBackend* be )
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
int r;
|
||||
GNCPrice* pPrice;
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
@ -170,11 +171,6 @@ save_price( GncSqlBackend* be, QofInstance* inst )
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GncSqlBackend* be;
|
||||
gboolean is_ok;
|
||||
} write_objects_t;
|
||||
|
||||
static gboolean
|
||||
write_price( GNCPrice* p, gpointer data )
|
||||
{
|
||||
|
@ -62,6 +62,7 @@ static void set_recurrence_period_start( gpointer pObject, gpointer pValue );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
get_obj_guid, set_obj_guid },
|
||||
{ "recurrence_mult", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
@ -71,14 +72,17 @@ static const GncSqlColumnTableEntry col_table[] =
|
||||
{ "recurrence_period_start", CT_GDATE, 0, COL_NNUL, NULL, NULL,
|
||||
get_recurrence_period_start, set_recurrence_period_start },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/* Special column table because we need to be able to access the table by
|
||||
a column other than the primary key */
|
||||
static const GncSqlColumnTableEntry guid_col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "obj_guid", CT_GUID, 0, 0, NULL, NULL, get_obj_guid, set_obj_guid },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -107,7 +111,7 @@ get_recurrence_mult( gpointer pObject )
|
||||
g_return_val_if_fail( pObject != NULL, 0 );
|
||||
g_return_val_if_fail( pInfo->pRecurrence != NULL, 0 );
|
||||
|
||||
return pInfo->pRecurrence->mult;
|
||||
return (gint)pInfo->pRecurrence->mult;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -118,7 +122,7 @@ set_recurrence_mult( gpointer pObject, gint value )
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pInfo->pRecurrence != NULL );
|
||||
|
||||
pInfo->pRecurrence->mult = value;
|
||||
pInfo->pRecurrence->mult = (guint16)value;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
@ -245,15 +249,13 @@ gnc_sql_set_recurrences_from_db( GncSqlBackend* be, const GUID* guid )
|
||||
{
|
||||
gchar* buf;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
gchar* field_name;
|
||||
GncSqlStatement* stmt;
|
||||
GError* error = NULL;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( guid != NULL, NULL );
|
||||
|
||||
guid_to_string_buff( guid, guid_buf );
|
||||
(void)guid_to_string_buff( guid, guid_buf );
|
||||
buf = g_strdup_printf( "SELECT * FROM %s WHERE obj_guid='%s'", TABLE_NAME, guid_buf );
|
||||
stmt = gnc_sql_connection_create_statement_from_sql( be->conn, buf );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
@ -332,9 +334,13 @@ gnc_sql_init_recurrence_handler( void )
|
||||
{
|
||||
GNC_SQL_BACKEND_VERSION,
|
||||
GNC_ID_ACCOUNT,
|
||||
NULL, /* commit - cannot occur */
|
||||
NULL, /* initial_load - cannot occur */
|
||||
create_recurrence_tables /* create_tables */
|
||||
NULL, /* commit - cannot occur */
|
||||
NULL, /* initial_load - cannot occur */
|
||||
create_recurrence_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( TABLE_NAME, GNC_SQL_BACKEND, &be_data );
|
||||
|
@ -61,6 +61,7 @@ static void set_template_act_guid( gpointer pObject, gpointer pValue );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "name", CT_STRING, SX_MAX_NAME_LEN, 0, NULL, GNC_SX_NAME },
|
||||
{ "enabled", CT_BOOLEAN, 0, COL_NNUL, NULL, NULL,
|
||||
@ -84,6 +85,7 @@ static const GncSqlColumnTableEntry col_table[] =
|
||||
{ "template_act_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
get_template_act_guid, set_template_act_guid },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -223,7 +225,6 @@ load_all_sxes( GncSqlBackend* be )
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row;
|
||||
int r;
|
||||
SchedXactions *sxes;
|
||||
GList* list = NULL;
|
||||
sxes = gnc_book_get_schedxactions( be->primary_book );
|
||||
@ -311,7 +312,11 @@ gnc_sql_init_schedxaction_handler( void )
|
||||
GNC_ID_SCHEDXACTION,
|
||||
gnc_sql_save_schedxaction, /* commit */
|
||||
load_all_sxes, /* initial_load */
|
||||
create_sx_tables /* create_tables */
|
||||
create_sx_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_SCHEDXACTION, GNC_SQL_BACKEND, &be_data );
|
||||
|
@ -76,6 +76,7 @@ static void set_numeric_val( gpointer pObject, gnc_numeric value );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
get_obj_guid, set_obj_guid },
|
||||
{ "name", CT_STRING, SLOT_MAX_PATHNAME_LEN, COL_NNUL, NULL, NULL,
|
||||
@ -95,14 +96,17 @@ static const GncSqlColumnTableEntry col_table[] =
|
||||
{ "numeric_val", CT_NUMERIC, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_numeric_val, (QofSetterFunc)set_numeric_val },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/* Special column table because we need to be able to access the table by
|
||||
a column other than the primary key */
|
||||
static const GncSqlColumnTableEntry obj_guid_col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "obj_guid", CT_GUID, 0, 0, NULL, NULL, get_obj_guid, _retrieve_guid_ },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -324,7 +328,7 @@ static void
|
||||
save_slot( const gchar* key, KvpValue* value, gpointer data )
|
||||
{
|
||||
slot_info_t* pSlot_info = (slot_info_t*)data;
|
||||
gint curlen;
|
||||
gsize curlen;
|
||||
|
||||
g_return_if_fail( key != NULL );
|
||||
g_return_if_fail( value != NULL );
|
||||
@ -338,9 +342,9 @@ save_slot( const gchar* key, KvpValue* value, gpointer data )
|
||||
curlen = pSlot_info->path->len;
|
||||
pSlot_info->pKvpValue = value;
|
||||
if( curlen != 0 ) {
|
||||
g_string_append( pSlot_info->path, "/" );
|
||||
(void)g_string_append( pSlot_info->path, "/" );
|
||||
}
|
||||
g_string_append( pSlot_info->path, key );
|
||||
(void)g_string_append( pSlot_info->path, key );
|
||||
|
||||
if( kvp_value_get_type( value ) == KVP_TYPE_FRAME ) {
|
||||
KvpFrame* pKvpFrame = kvp_value_get_frame( value );
|
||||
@ -352,7 +356,7 @@ save_slot( const gchar* key, KvpValue* value, gpointer data )
|
||||
col_table );
|
||||
}
|
||||
|
||||
g_string_truncate( pSlot_info->path, curlen );
|
||||
(void)g_string_truncate( pSlot_info->path, curlen );
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -374,7 +378,7 @@ gnc_sql_slots_save( GncSqlBackend* be, const GUID* guid, gboolean is_infant, Kvp
|
||||
slot_info.path = g_string_new( "" );
|
||||
slot_info.is_ok = TRUE;
|
||||
kvp_frame_for_each_slot( pFrame, save_slot, &slot_info );
|
||||
g_string_free( slot_info.path, TRUE );
|
||||
(void)g_string_free( slot_info.path, TRUE );
|
||||
|
||||
return slot_info.is_ok;
|
||||
}
|
||||
@ -412,7 +416,7 @@ load_slot( GncSqlBackend* be, GncSqlRow* row, KvpFrame* pFrame )
|
||||
gnc_sql_load_object( be, row, TABLE_NAME, &slot_info, col_table );
|
||||
|
||||
if( slot_info.path != NULL ) {
|
||||
g_string_free( slot_info.path, TRUE );
|
||||
(void)g_string_free( slot_info.path, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
@ -422,21 +426,19 @@ gnc_sql_slots_load( GncSqlBackend* be, QofInstance* inst )
|
||||
gchar* buf;
|
||||
GncSqlResult* result;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
gchar* field_name;
|
||||
GncSqlStatement* stmt;
|
||||
GValue value;
|
||||
const GUID* guid;
|
||||
KvpFrame* pFrame;
|
||||
GError* error = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != NULL );
|
||||
|
||||
guid = qof_instance_get_guid( inst );
|
||||
pFrame = qof_instance_get_slots( inst );
|
||||
guid_to_string_buff( guid, guid_buf );
|
||||
(void)guid_to_string_buff( guid, guid_buf );
|
||||
memset( &value, 0, sizeof( value ) );
|
||||
g_value_init( &value, G_TYPE_STRING );
|
||||
(void)g_value_init( &value, G_TYPE_STRING );
|
||||
g_value_set_string( &value, guid_buf );
|
||||
|
||||
buf = g_strdup_printf( "SELECT * FROM %s WHERE obj_guid='%s'", TABLE_NAME, guid_buf );
|
||||
@ -488,7 +490,7 @@ load_slot_for_list_item( GncSqlBackend* be, GncSqlRow* row, QofCollection* coll
|
||||
gnc_sql_load_object( be, row, TABLE_NAME, &slot_info, col_table );
|
||||
|
||||
if( slot_info.path != NULL ) {
|
||||
g_string_free( slot_info.path, TRUE );
|
||||
(void)g_string_free( slot_info.path, TRUE );
|
||||
}
|
||||
}
|
||||
|
||||
@ -498,8 +500,6 @@ gnc_sql_slots_load_for_list( GncSqlBackend* be, GList* list )
|
||||
QofCollection* coll;
|
||||
GncSqlStatement* stmt;
|
||||
GString* sql;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
gboolean first_guid = TRUE;
|
||||
GncSqlResult* result;
|
||||
gboolean single_item;
|
||||
|
||||
@ -514,15 +514,15 @@ gnc_sql_slots_load_for_list( GncSqlBackend* be, GList* list )
|
||||
sql = g_string_sized_new( 40+(GUID_ENCODING_LENGTH+3)*g_list_length( list ) );
|
||||
g_string_append_printf( sql, "SELECT * FROM %s WHERE %s ", TABLE_NAME, obj_guid_col_table[0].col_name );
|
||||
if( g_list_length( list ) != 1 ) {
|
||||
g_string_append( sql, "IN (" );
|
||||
(void)g_string_append( sql, "IN (" );
|
||||
single_item = FALSE;
|
||||
} else {
|
||||
g_string_append( sql, "= " );
|
||||
(void)g_string_append( sql, "= " );
|
||||
single_item = TRUE;
|
||||
}
|
||||
(void)gnc_sql_append_guid_list_to_sql( sql, list, G_MAXUINT );
|
||||
if( !single_item ) {
|
||||
g_string_append( sql, ")" );
|
||||
(void)g_string_append( sql, ")" );
|
||||
}
|
||||
|
||||
// Execute the query and load the slots
|
||||
@ -538,7 +538,7 @@ gnc_sql_slots_load_for_list( GncSqlBackend* be, GList* list )
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
g_string_free( sql, FALSE );
|
||||
(void)g_string_free( sql, FALSE );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
@ -577,7 +577,11 @@ gnc_sql_init_slots_handler( void )
|
||||
GNC_ID_ACCOUNT,
|
||||
NULL, /* commit - cannot occur */
|
||||
NULL, /* initial_load - cannot occur */
|
||||
create_slots_tables /* create_tables */
|
||||
create_slots_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( TABLE_NAME, GNC_SQL_BACKEND, &be_data );
|
||||
|
@ -65,6 +65,7 @@ typedef struct {
|
||||
|
||||
static const GncSqlColumnTableEntry tx_col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "currency_guid", CT_COMMODITYREF, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)xaccTransGetCurrency, (QofSetterFunc)xaccTransSetCurrency },
|
||||
@ -77,6 +78,7 @@ static const GncSqlColumnTableEntry tx_col_table[] =
|
||||
{ "description", CT_STRING, TX_MAX_DESCRIPTION_LEN, 0, NULL, NULL,
|
||||
(QofAccessFunc)xaccTransGetDescription, (QofSetterFunc)xaccTransSetDescription },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
static gpointer get_split_reconcile_state( gpointer pObject, const QofParam* param );
|
||||
@ -89,6 +91,7 @@ static void set_split_lot( gpointer pObject, gpointer pLot );
|
||||
|
||||
static const GncSqlColumnTableEntry split_col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "tx_guid", CT_TXREF, 0, COL_NNUL, NULL, SPLIT_TRANS },
|
||||
{ "account_guid", CT_ACCOUNTREF, 0, COL_NNUL, NULL, SPLIT_ACCOUNT },
|
||||
@ -103,12 +106,15 @@ static const GncSqlColumnTableEntry split_col_table[] =
|
||||
{ "lot_guid", CT_LOTREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)xaccSplitGetLot, set_split_lot },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
static const GncSqlColumnTableEntry guid_col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "tx_guid", CT_GUID, 0, 0, "guid" },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
static void retrieve_numeric_value( gpointer pObject, gnc_numeric value );
|
||||
@ -179,25 +185,16 @@ set_split_lot( gpointer pObject, gpointer pLot )
|
||||
gnc_lot_add_split( lot, split );
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Table to retrieve just the quantity
|
||||
static GncSqlColumnTableEntry quantity_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "quantity", CT_NUMERIC, 0, COL_NNUL, NULL, NULL, NULL, (QofSetterFunc)retrieve_numeric_value },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
static gnc_numeric
|
||||
get_gnc_numeric_from_row( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
gnc_numeric val = gnc_numeric_zero();
|
||||
|
||||
g_return_val_if_fail( be != NULL, val );
|
||||
g_return_val_if_fail( row != NULL, val );
|
||||
|
||||
gnc_sql_load_object( be, row, NULL, &val, quantity_table );
|
||||
|
||||
return val;
|
||||
}
|
||||
#endif
|
||||
|
||||
static Split*
|
||||
load_single_split( GncSqlBackend* be, GncSqlRow* row )
|
||||
@ -222,63 +219,16 @@ load_single_split( GncSqlBackend* be, GncSqlRow* row )
|
||||
gnc_sql_load_object( be, row, GNC_ID_SPLIT, pSplit, split_col_table );
|
||||
}
|
||||
|
||||
g_assert( pSplit == xaccSplitLookup( &split_guid, be->primary_book ) );
|
||||
/*# -ifempty */g_assert( pSplit == xaccSplitLookup( &split_guid, be->primary_book ) );
|
||||
|
||||
return pSplit;
|
||||
}
|
||||
|
||||
static void
|
||||
load_all_splits_for_tx( GncSqlBackend* be, const GUID* tx_guid )
|
||||
{
|
||||
GncSqlResult* result;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
GncSqlStatement* stmt;
|
||||
GValue value;
|
||||
gchar* buf;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( tx_guid != NULL );
|
||||
|
||||
guid_to_string_buff( tx_guid, guid_buf );
|
||||
memset( &value, 0, sizeof( GValue ) );
|
||||
g_value_init( &value, G_TYPE_STRING );
|
||||
g_value_set_string( &value, guid_buf );
|
||||
|
||||
buf = g_strdup_printf( "SELECT * FROM %s WHERE tx_guid='%s'", SPLIT_TABLE, guid_buf );
|
||||
stmt = gnc_sql_create_statement_from_sql( be, buf );
|
||||
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
int r;
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row;
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
Split* s;
|
||||
|
||||
s = load_single_split( be, row );
|
||||
if( s != NULL ) {
|
||||
list = g_list_append( list, s );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
load_splits_for_tx_list( GncSqlBackend* be, GList* list )
|
||||
{
|
||||
GString* sql;
|
||||
QofCollection* col;
|
||||
GncSqlResult* result;
|
||||
gboolean first_guid = TRUE;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
@ -287,7 +237,7 @@ load_splits_for_tx_list( GncSqlBackend* be, GList* list )
|
||||
sql = g_string_sized_new( 40+(GUID_ENCODING_LENGTH+3)*g_list_length( list ) );
|
||||
g_string_append_printf( sql, "SELECT * FROM %s WHERE %s IN (", SPLIT_TABLE, guid_col_table[0].col_name );
|
||||
(void)gnc_sql_append_guid_list_to_sql( sql, list, G_MAXUINT );
|
||||
g_string_append( sql, ")" );
|
||||
(void)g_string_append( sql, ")" );
|
||||
|
||||
// Execute the query and load the splits
|
||||
result = gnc_sql_execute_select_sql( be, sql->str );
|
||||
@ -311,7 +261,7 @@ load_splits_for_tx_list( GncSqlBackend* be, GList* list )
|
||||
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
g_string_free( sql, FALSE );
|
||||
(void)g_string_free( sql, FALSE );
|
||||
}
|
||||
|
||||
static Transaction*
|
||||
@ -358,8 +308,6 @@ typedef struct {
|
||||
gnc_numeric end_reconciled_bal;
|
||||
} full_acct_balances_t;
|
||||
|
||||
static Account* g_acct;
|
||||
|
||||
/**
|
||||
* Save the start/end balances for an account.
|
||||
*/
|
||||
@ -375,7 +323,7 @@ save_account_balances( Account* acc, gpointer pData )
|
||||
gnc_numeric* pstart_r;
|
||||
gnc_numeric* pend_r;
|
||||
|
||||
newbal = g_malloc( sizeof( full_acct_balances_t ) );
|
||||
newbal = g_malloc( (gsize)sizeof( full_acct_balances_t ) );
|
||||
newbal->acc = acc;
|
||||
g_object_get( acc,
|
||||
"start-balance", &pstart,
|
||||
@ -736,7 +684,7 @@ void gnc_sql_transaction_load_tx_for_account( GncSqlBackend* be, Account* accoun
|
||||
g_return_if_fail( account != NULL );
|
||||
|
||||
guid = qof_instance_get_guid( QOF_INSTANCE(account) );
|
||||
guid_to_string_buff( guid, guid_buf );
|
||||
(void)guid_to_string_buff( guid, guid_buf );
|
||||
subquery_sql = g_strdup_printf( "SELECT DISTINCT tx_guid FROM %s WHERE account_guid='%s'", SPLIT_TABLE, guid_buf );
|
||||
query_sql = g_strdup_printf( "SELECT * FROM %s WHERE guid IN (%s)", TRANSACTION_TABLE, subquery_sql );
|
||||
g_free( subquery_sql );
|
||||
@ -775,7 +723,6 @@ compile_split_query( GncSqlBackend* be, QofQuery* pQuery )
|
||||
{
|
||||
const GUID* acct_guid;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
GncSqlResult* result;
|
||||
split_query_info_t* query_info;
|
||||
gchar* subquery_sql;
|
||||
gchar* query_sql;
|
||||
@ -784,11 +731,11 @@ compile_split_query( GncSqlBackend* be, QofQuery* pQuery )
|
||||
g_return_val_if_fail( pQuery != NULL, NULL );
|
||||
|
||||
acct_guid = get_guid_from_query( pQuery );
|
||||
guid_to_string_buff( acct_guid, guid_buf );
|
||||
(void)guid_to_string_buff( acct_guid, guid_buf );
|
||||
subquery_sql = g_strdup_printf( "SELECT DISTINCT tx_guid FROM %s WHERE account_guid='%s'", SPLIT_TABLE, guid_buf );
|
||||
query_sql = g_strdup_printf( "SELECT * FROM %s WHERE guid IN (%s)", TRANSACTION_TABLE, subquery_sql );
|
||||
|
||||
query_info = g_malloc( sizeof(split_query_info_t) );
|
||||
query_info = g_malloc( (gsize)sizeof(split_query_info_t) );
|
||||
query_info->stmt = gnc_sql_create_statement_from_sql( be, query_sql );
|
||||
query_info->has_been_run = FALSE;
|
||||
query_info->acct = xaccAccountLookup( acct_guid, be->primary_book );
|
||||
@ -870,10 +817,12 @@ set_acct_bal_balance( gpointer pObject, gnc_numeric value )
|
||||
|
||||
static const GncSqlColumnTableEntry acct_balances_col_table[] =
|
||||
{
|
||||
/*# -fullinitblock */
|
||||
{ "account_guid", CT_GUID, 0, 0, NULL, NULL, NULL, set_acct_bal_account_from_guid },
|
||||
{ "reconcile_state", CT_STRING, 1, 0, NULL, NULL, NULL, set_acct_bal_reconcile_state },
|
||||
{ "quantity", CT_NUMERIC, 0, 0, NULL, NULL, NULL, (QofSetterFunc)set_acct_bal_balance },
|
||||
{ NULL }
|
||||
/*# +fullinitblock */
|
||||
};
|
||||
|
||||
static single_acct_balance_t*
|
||||
@ -884,7 +833,7 @@ load_single_acct_balances( const GncSqlBackend* be, GncSqlRow* row )
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
bal = g_malloc( sizeof(single_acct_balance_t) );
|
||||
bal = g_malloc( (gsize)sizeof(single_acct_balance_t) );
|
||||
bal->be = be;
|
||||
gnc_sql_load_object( be, row, NULL, bal, acct_balances_col_table );
|
||||
|
||||
@ -895,9 +844,7 @@ GSList*
|
||||
gnc_sql_get_account_balances_slist( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlResult* result;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
GncSqlStatement* stmt;
|
||||
GValue value;
|
||||
gchar* buf;
|
||||
GSList* bal_slist = NULL;
|
||||
|
||||
@ -910,8 +857,6 @@ gnc_sql_get_account_balances_slist( GncSqlBackend* be )
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
int r;
|
||||
GList* list = NULL;
|
||||
GncSqlRow* row;
|
||||
acct_balances_t* bal = NULL;
|
||||
|
||||
@ -931,7 +876,7 @@ gnc_sql_get_account_balances_slist( GncSqlBackend* be )
|
||||
bal = NULL;
|
||||
}
|
||||
if( bal == NULL ) {
|
||||
bal = g_malloc( sizeof(acct_balances_t) );
|
||||
bal = g_malloc( (gsize)sizeof(acct_balances_t) );
|
||||
bal->acct = single_bal->acct;
|
||||
bal->balance = gnc_numeric_zero();
|
||||
bal->cleared_balance = gnc_numeric_zero();
|
||||
@ -1013,7 +958,11 @@ gnc_sql_init_transaction_handler( void )
|
||||
GNC_ID_TRANS,
|
||||
commit_transaction, /* commit */
|
||||
NULL,
|
||||
create_transaction_tables /* create tables */
|
||||
create_transaction_tables, /* create tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
static GncSqlObjectBackend be_data_split =
|
||||
{
|
||||
@ -1024,7 +973,8 @@ gnc_sql_init_transaction_handler( void )
|
||||
NULL, /* create tables */
|
||||
compile_split_query,
|
||||
run_split_query,
|
||||
free_split_query
|
||||
free_split_query,
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
qof_object_register_backend( GNC_ID_TRANS, GNC_SQL_BACKEND, &be_data_tx );
|
||||
|
Loading…
Reference in New Issue
Block a user