mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Re-indentation of source code (sql parts).
This also strips trailing whitespaces from lines where they existed. This re-indentation was done using astyle-1.24 using the following options: astyle --indent=spaces=4 --brackets=break --pad-oper --pad-header --suffix git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18971 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
88d3b83579
commit
50163126ea
@ -152,10 +152,10 @@ typedef struct
|
||||
provider_functions_t* provider;
|
||||
gint last_error; // Code of the last error that occurred. This is set in the error callback function
|
||||
gint error_repeat; // Used in case of transient errors. After such error, another attempt at the
|
||||
// original call is allowed. error_repeat tracks the number of attempts and can
|
||||
// be used to prevent infinite loops.
|
||||
// original call is allowed. error_repeat tracks the number of attempts and can
|
||||
// be used to prevent infinite loops.
|
||||
gboolean retry; // Signals the calling function that it should retry (the error handler detected
|
||||
// transient error and managed to resolve it, but it can't run the original query)
|
||||
// transient error and managed to resolve it, but it can't run the original query)
|
||||
} GncDbiSqlConnection;
|
||||
|
||||
#define DBI_MAX_CONN_ATTEMPTS 5
|
||||
@ -323,7 +323,8 @@ mysql_error_fn( dbi_conn conn, void* user_data )
|
||||
{
|
||||
PERR( "DBI error: %s - Failed to reconnect after %d attempts.\n", msg, DBI_MAX_CONN_ATTEMPTS );
|
||||
gnc_dbi_set_error( dbi_conn, ERR_BACKEND_CANT_CONNECT, 0, FALSE );
|
||||
} else
|
||||
}
|
||||
else
|
||||
{
|
||||
PINFO( "DBI error: %s - Reconnecting...\n", msg );
|
||||
gnc_dbi_set_error( dbi_conn, ERR_BACKEND_CONN_LOST, 1, TRUE );
|
||||
@ -811,10 +812,12 @@ gnc_dbi_sync_all( QofBackend* qbe, /*@ dependent @*/ QofBook *book )
|
||||
const gchar* table_name = (const gchar*)node->data;
|
||||
dbi_result result;
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
gnc_dbi_init_error( ((GncDbiSqlConnection*)(be->sql_be.conn)) );
|
||||
result = dbi_conn_queryf( be->conn, "DROP TABLE %s", table_name );
|
||||
} while ( ((GncDbiSqlConnection*)(be->sql_be.conn))->retry );
|
||||
}
|
||||
while ( ((GncDbiSqlConnection*)(be->sql_be.conn))->retry );
|
||||
if ( result != NULL )
|
||||
{
|
||||
status = dbi_result_free( result );
|
||||
@ -1445,10 +1448,12 @@ conn_execute_select_statement( GncSqlConnection* conn, GncSqlStatement* stmt )
|
||||
dbi_result result;
|
||||
|
||||
DEBUG( "SQL: %s\n", dbi_stmt->sql->str );
|
||||
do {
|
||||
do
|
||||
{
|
||||
gnc_dbi_init_error( dbi_conn );
|
||||
result = dbi_conn_query( dbi_conn->conn, dbi_stmt->sql->str );
|
||||
} while ( dbi_conn->retry );
|
||||
}
|
||||
while ( dbi_conn->retry );
|
||||
if ( result == NULL )
|
||||
{
|
||||
PERR( "Error executing SQL %s\n", dbi_stmt->sql->str );
|
||||
@ -1467,10 +1472,12 @@ conn_execute_nonselect_statement( GncSqlConnection* conn, GncSqlStatement* stmt
|
||||
gint status;
|
||||
|
||||
DEBUG( "SQL: %s\n", dbi_stmt->sql->str );
|
||||
do {
|
||||
do
|
||||
{
|
||||
gnc_dbi_init_error( dbi_conn );
|
||||
result = dbi_conn_query( dbi_conn->conn, dbi_stmt->sql->str );
|
||||
} while( dbi_conn->retry );
|
||||
}
|
||||
while ( dbi_conn->retry );
|
||||
if ( result == NULL )
|
||||
{
|
||||
PERR( "Error executing SQL %s\n", dbi_stmt->sql->str );
|
||||
@ -1549,10 +1556,12 @@ conn_begin_transaction( /*@ unused @*/ GncSqlConnection* conn )
|
||||
|
||||
DEBUG( "BEGIN\n" );
|
||||
|
||||
do {
|
||||
do
|
||||
{
|
||||
gnc_dbi_init_error( dbi_conn );
|
||||
result = dbi_conn_queryf( dbi_conn->conn, "BEGIN" );
|
||||
} while( dbi_conn->retry );
|
||||
}
|
||||
while ( dbi_conn->retry );
|
||||
|
||||
status = dbi_result_free( result );
|
||||
if ( status < 0 )
|
||||
|
@ -110,7 +110,7 @@ int main (int argc, char ** argv)
|
||||
filename = tempnam( "/tmp", "test-sqlite3-" );
|
||||
printf( "Using filename: %s\n", filename );
|
||||
test_dbi_store_and_reload( "sqlite3", session_1, filename );
|
||||
#if 0
|
||||
#if 0
|
||||
printf( "TEST_MYSQL_URL='%s'\n", TEST_MYSQL_URL );
|
||||
if ( strlen( TEST_MYSQL_URL ) > 0 )
|
||||
{
|
||||
@ -123,7 +123,7 @@ int main (int argc, char ** argv)
|
||||
session_1 = create_session();
|
||||
test_dbi_store_and_reload( "pgsql", session_1, TEST_PGSQL_URL );
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
print_test_results();
|
||||
qof_close();
|
||||
exit(get_rv());
|
||||
|
@ -39,10 +39,11 @@ static QofLogModule log_module = GNC_MOD_BACKEND;
|
||||
|
||||
/* ================================================ */
|
||||
|
||||
struct _escape {
|
||||
/* pointer to memory used for escaping arguments */
|
||||
char * escape;
|
||||
size_t esc_buflen;
|
||||
struct _escape
|
||||
{
|
||||
/* pointer to memory used for escaping arguments */
|
||||
char * escape;
|
||||
size_t esc_buflen;
|
||||
};
|
||||
|
||||
/* ================================================ */
|
||||
@ -53,72 +54,74 @@ struct _escape {
|
||||
const char *
|
||||
sqlEscapeString (sqlEscape *b, const char *str)
|
||||
{
|
||||
const char *p, *src_head;
|
||||
char *dst_tail;
|
||||
size_t len, slen;
|
||||
const char *p, *src_head;
|
||||
char *dst_tail;
|
||||
size_t len, slen;
|
||||
|
||||
ENTER("str = %s", str);
|
||||
ENTER("str = %s", str);
|
||||
|
||||
if (!b || !str) { LEAVE("(null) args"); return NULL; }
|
||||
if (!b || !str) { LEAVE("(null) args"); return NULL; }
|
||||
|
||||
/* if a string is escaped twice, just return the first */
|
||||
if (b->escape == str) {
|
||||
LEAVE("%s: already escaped", str);
|
||||
return str;
|
||||
}
|
||||
/* if a string is escaped twice, just return the first */
|
||||
if (b->escape == str)
|
||||
{
|
||||
LEAVE("%s: already escaped", str);
|
||||
return str;
|
||||
}
|
||||
|
||||
/* if nothing to escape, just return */
|
||||
len = strlen (str);
|
||||
slen = strcspn (str, "\\\'");
|
||||
if (len == slen) {
|
||||
LEAVE("nothing to escape");
|
||||
return str;
|
||||
}
|
||||
/* if nothing to escape, just return */
|
||||
len = strlen (str);
|
||||
slen = strcspn (str, "\\\'");
|
||||
if (len == slen)
|
||||
{
|
||||
LEAVE("nothing to escape");
|
||||
return str;
|
||||
}
|
||||
|
||||
/* count to see how much space we'll need */
|
||||
p = str + slen + 1;
|
||||
while (*p)
|
||||
{
|
||||
len ++;
|
||||
p += 1 + strcspn (p, "\\\'");
|
||||
}
|
||||
/* count to see how much space we'll need */
|
||||
p = str + slen + 1;
|
||||
while (*p)
|
||||
{
|
||||
len ++;
|
||||
p += 1 + strcspn (p, "\\\'");
|
||||
}
|
||||
|
||||
/* get more space, if needed */
|
||||
if (len >= b->esc_buflen)
|
||||
{
|
||||
b->escape = g_realloc(b->escape, len+100);
|
||||
b->esc_buflen = len+100;
|
||||
}
|
||||
/* get more space, if needed */
|
||||
if (len >= b->esc_buflen)
|
||||
{
|
||||
b->escape = g_realloc(b->escape, len + 100);
|
||||
b->esc_buflen = len + 100;
|
||||
}
|
||||
|
||||
/* copy and escape */
|
||||
src_head = (char *) str;
|
||||
dst_tail = b->escape;
|
||||
p = src_head + strcspn (src_head, "\\\'");
|
||||
while (*p)
|
||||
{
|
||||
size_t cp_len = p - src_head;
|
||||
/* copy and escape */
|
||||
src_head = (char *) str;
|
||||
dst_tail = b->escape;
|
||||
p = src_head + strcspn (src_head, "\\\'");
|
||||
while (*p)
|
||||
{
|
||||
size_t cp_len = p - src_head;
|
||||
|
||||
strncpy (dst_tail, src_head, cp_len);
|
||||
dst_tail += cp_len;
|
||||
*dst_tail = '\\';
|
||||
dst_tail ++;
|
||||
*dst_tail = *p;
|
||||
dst_tail ++;
|
||||
strncpy (dst_tail, src_head, cp_len);
|
||||
dst_tail += cp_len;
|
||||
*dst_tail = '\\';
|
||||
dst_tail ++;
|
||||
*dst_tail = *p;
|
||||
dst_tail ++;
|
||||
|
||||
src_head = p+1;
|
||||
p = src_head + strcspn (src_head, "\\\'");
|
||||
}
|
||||
if (p != src_head)
|
||||
{
|
||||
size_t cp_len = p - src_head;
|
||||
src_head = p + 1;
|
||||
p = src_head + strcspn (src_head, "\\\'");
|
||||
}
|
||||
if (p != src_head)
|
||||
{
|
||||
size_t cp_len = p - src_head;
|
||||
|
||||
strncpy (dst_tail, src_head, cp_len);
|
||||
dst_tail += cp_len;
|
||||
}
|
||||
*dst_tail = 0;
|
||||
strncpy (dst_tail, src_head, cp_len);
|
||||
dst_tail += cp_len;
|
||||
}
|
||||
*dst_tail = 0;
|
||||
|
||||
LEAVE("b->escape = %s", b->escape);
|
||||
return b->escape;
|
||||
LEAVE("b->escape = %s", b->escape);
|
||||
return b->escape;
|
||||
}
|
||||
|
||||
/* ================================================ */
|
||||
@ -128,11 +131,11 @@ sqlEscapeString (sqlEscape *b, const char *str)
|
||||
sqlEscape *
|
||||
sqlEscape_new (void)
|
||||
{
|
||||
sqlEscape *b = g_new (sqlEscape, 1);
|
||||
sqlEscape *b = g_new (sqlEscape, 1);
|
||||
|
||||
b->escape = g_malloc (INITIAL_BUFSZ);
|
||||
b->esc_buflen = INITIAL_BUFSZ;
|
||||
return (b);
|
||||
b->escape = g_malloc (INITIAL_BUFSZ);
|
||||
b->esc_buflen = INITIAL_BUFSZ;
|
||||
return (b);
|
||||
}
|
||||
|
||||
/* ================================================ */
|
||||
@ -141,10 +144,11 @@ void
|
||||
sqlEscape_destroy (sqlEscape *b)
|
||||
{
|
||||
ENTER(" ");
|
||||
if (!b) { LEAVE("b is (null)"); return; }
|
||||
g_free (b->escape); b->escape = NULL;
|
||||
g_free (b);
|
||||
LEAVE(" ");
|
||||
if (!b) { LEAVE("b is (null)"); return; }
|
||||
g_free (b->escape);
|
||||
b->escape = NULL;
|
||||
g_free (b);
|
||||
LEAVE(" ");
|
||||
}
|
||||
|
||||
/* ================ END OF FILE ==================== */
|
||||
|
@ -62,33 +62,36 @@ static void set_parent_guid( gpointer pObject, /*@ null @*/ gpointer pValue );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
/*@ -full_init_block @*/
|
||||
{ "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_ },
|
||||
{ "commodity_guid", CT_COMMODITYREF, 0, 0, "commodity" },
|
||||
{ "commodity_scu", CT_INT, 0, COL_NNUL, "commodity-scu" },
|
||||
{ "non_std_scu", CT_BOOLEAN, 0, COL_NNUL, "non-std-scu" },
|
||||
{ "parent_guid", CT_GUID, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_parent, set_parent },
|
||||
{ "commodity_scu", CT_INT, 0, COL_NNUL, "commodity-scu" },
|
||||
{ "non_std_scu", CT_BOOLEAN, 0, COL_NNUL, "non-std-scu" },
|
||||
{
|
||||
"parent_guid", CT_GUID, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_parent, set_parent
|
||||
},
|
||||
{ "code", CT_STRING, ACCOUNT_MAX_CODE_LEN, 0, "code" },
|
||||
{ "description", CT_STRING, ACCOUNT_MAX_DESCRIPTION_LEN, 0, "description" },
|
||||
{ "hidden", CT_BOOLEAN, 0, 0, "hidden" },
|
||||
{ "placeholder", CT_BOOLEAN, 0, 0, "placeholder" },
|
||||
{ "hidden", CT_BOOLEAN, 0, 0, "hidden" },
|
||||
{ "placeholder", CT_BOOLEAN, 0, 0, "placeholder" },
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
static GncSqlColumnTableEntry parent_col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
/*@ -full_init_block @*/
|
||||
{ "parent_guid", CT_GUID, 0, 0, NULL, NULL, NULL, set_parent_guid },
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
/*@ dependent @*/ Account* pAccount;
|
||||
GncGUID guid;
|
||||
typedef struct
|
||||
{
|
||||
/*@ dependent @*/ Account* pAccount;
|
||||
GncGUID guid;
|
||||
} account_parent_guid_struct;
|
||||
|
||||
/* ================================================================= */
|
||||
@ -100,14 +103,17 @@ get_parent( gpointer pObject )
|
||||
const Account* pParent;
|
||||
const GncGUID* parent_guid;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_ACCOUNT(pObject), NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_ACCOUNT(pObject), NULL );
|
||||
|
||||
pAccount = GNC_ACCOUNT(pObject);
|
||||
pParent = gnc_account_get_parent( pAccount );
|
||||
if( pParent == NULL ) {
|
||||
if ( pParent == NULL )
|
||||
{
|
||||
parent_guid = NULL;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
|
||||
}
|
||||
|
||||
@ -122,14 +128,16 @@ set_parent( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
GncGUID* guid = (GncGUID*)pValue;
|
||||
Account* pParent;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_ACCOUNT(pObject) );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_ACCOUNT(pObject) );
|
||||
|
||||
pAccount = GNC_ACCOUNT(pObject);
|
||||
pBook = qof_instance_get_book( QOF_INSTANCE(pAccount) );
|
||||
if( guid != NULL ) {
|
||||
if ( guid != NULL )
|
||||
{
|
||||
pParent = xaccAccountLookup( guid, pBook );
|
||||
if( pParent != NULL ) {
|
||||
if ( pParent != NULL )
|
||||
{
|
||||
gnc_account_append_child( pParent, pAccount );
|
||||
}
|
||||
}
|
||||
@ -138,50 +146,53 @@ set_parent( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
static void
|
||||
set_parent_guid( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
{
|
||||
account_parent_guid_struct* s = (account_parent_guid_struct*)pObject;
|
||||
account_parent_guid_struct* s = (account_parent_guid_struct*)pObject;
|
||||
GncGUID* guid = (GncGUID*)pValue;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
s->guid = *guid;
|
||||
s->guid = *guid;
|
||||
}
|
||||
|
||||
static /*@ dependent @*//*@ null @*/ Account*
|
||||
load_single_account( GncSqlBackend* be, GncSqlRow* row,
|
||||
GList** l_accounts_needing_parents )
|
||||
GList** l_accounts_needing_parents )
|
||||
{
|
||||
const GncGUID* guid;
|
||||
Account* pAccount = NULL;
|
||||
Account* pAccount = NULL;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
g_return_val_if_fail( l_accounts_needing_parents != NULL, NULL );
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
g_return_val_if_fail( l_accounts_needing_parents != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
if( guid != NULL ) {
|
||||
pAccount = xaccAccountLookup( guid, be->primary_book );
|
||||
}
|
||||
if( pAccount == NULL ) {
|
||||
if ( guid != NULL )
|
||||
{
|
||||
pAccount = xaccAccountLookup( guid, be->primary_book );
|
||||
}
|
||||
if ( pAccount == NULL )
|
||||
{
|
||||
pAccount = xaccMallocAccount( be->primary_book );
|
||||
}
|
||||
xaccAccountBeginEdit( pAccount );
|
||||
xaccAccountBeginEdit( pAccount );
|
||||
gnc_sql_load_object( be, row, GNC_ID_ACCOUNT, pAccount, col_table );
|
||||
xaccAccountCommitEdit( pAccount );
|
||||
xaccAccountCommitEdit( pAccount );
|
||||
|
||||
/* If we don't have a parent and this isn't the root account, 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
|
||||
&& pAccount != gnc_book_get_root_account( be->primary_book ) ) {
|
||||
account_parent_guid_struct* s = g_malloc( (gsize)sizeof(account_parent_guid_struct) );
|
||||
g_assert( s != NULL );
|
||||
/* If we don't have a parent and this isn't the root account, 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
|
||||
&& pAccount != gnc_book_get_root_account( be->primary_book ) )
|
||||
{
|
||||
account_parent_guid_struct* s = g_malloc( (gsize)sizeof(account_parent_guid_struct) );
|
||||
g_assert( s != NULL );
|
||||
|
||||
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 );
|
||||
}
|
||||
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 );
|
||||
}
|
||||
|
||||
return pAccount;
|
||||
return pAccount;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -191,103 +202,115 @@ load_all_accounts( GncSqlBackend* be )
|
||||
GncSqlResult* result;
|
||||
QofBook* pBook;
|
||||
gnc_commodity_table* pTable;
|
||||
GList* l_accounts_needing_parents = NULL;
|
||||
GSList* bal_slist;
|
||||
GSList* bal;
|
||||
GList* l_accounts_needing_parents = NULL;
|
||||
GSList* bal_slist;
|
||||
GSList* bal;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
ENTER( "" );
|
||||
ENTER( "" );
|
||||
|
||||
pBook = be->primary_book;
|
||||
pTable = gnc_commodity_table_get_table( pBook );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
if( stmt == NULL ) {
|
||||
LEAVE( "stmt == NULL" );
|
||||
return;
|
||||
}
|
||||
if ( stmt == NULL )
|
||||
{
|
||||
LEAVE( "stmt == NULL" );
|
||||
return;
|
||||
}
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
Account* acc;
|
||||
gchar* sql;
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
Account* acc;
|
||||
gchar* sql;
|
||||
|
||||
while( row != NULL ) {
|
||||
acc = load_single_account( be, row, &l_accounts_needing_parents );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
while ( row != NULL )
|
||||
{
|
||||
acc = load_single_account( be, row, &l_accounts_needing_parents );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
sql = g_strdup_printf( "SELECT DISTINCT guid FROM %s", TABLE_NAME );
|
||||
gnc_sql_slots_load_for_sql_subquery( be, sql, (BookLookupFn)xaccAccountLookup );
|
||||
g_free( sql );
|
||||
sql = g_strdup_printf( "SELECT DISTINCT guid FROM %s", TABLE_NAME );
|
||||
gnc_sql_slots_load_for_sql_subquery( be, sql, (BookLookupFn)xaccAccountLookup );
|
||||
g_free( sql );
|
||||
|
||||
/* While there are items on the list of accounts needing parents,
|
||||
try to see if the parent has now been loaded. Theory says that if
|
||||
items are removed from the front and added to the back if the
|
||||
parent is still not available, then eventually, the list will
|
||||
shrink to size 0. */
|
||||
if( l_accounts_needing_parents != NULL ) {
|
||||
gboolean progress_made = TRUE;
|
||||
/* While there are items on the list of accounts needing parents,
|
||||
try to see if the parent has now been loaded. Theory says that if
|
||||
items are removed from the front and added to the back if the
|
||||
parent is still not available, then eventually, the list will
|
||||
shrink to size 0. */
|
||||
if ( l_accounts_needing_parents != NULL )
|
||||
{
|
||||
gboolean progress_made = TRUE;
|
||||
Account* root;
|
||||
Account* pParent;
|
||||
GList* elem;
|
||||
Account* pParent;
|
||||
GList* elem;
|
||||
|
||||
while( progress_made ) {
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
while ( progress_made )
|
||||
{
|
||||
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;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Any non-ROOT accounts left over must be parented by the root account */
|
||||
root = gnc_book_get_root_account( pBook );
|
||||
for( elem = l_accounts_needing_parents; elem != NULL; elem = g_list_next( elem ) ) {
|
||||
account_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
|
||||
if( xaccAccountGetType( s->pAccount ) != ACCT_TYPE_ROOT ) {
|
||||
gnc_account_append_child( root, s->pAccount );
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Any non-ROOT accounts left over must be parented by the root account */
|
||||
root = gnc_book_get_root_account( pBook );
|
||||
for ( elem = l_accounts_needing_parents; elem != NULL; elem = g_list_next( elem ) )
|
||||
{
|
||||
account_parent_guid_struct* s = (account_parent_guid_struct*)elem->data;
|
||||
if ( xaccAccountGetType( s->pAccount ) != ACCT_TYPE_ROOT )
|
||||
{
|
||||
gnc_account_append_child( root, s->pAccount );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Load starting balances */
|
||||
bal_slist = gnc_sql_get_account_balances_slist( be );
|
||||
for( bal = bal_slist; bal != NULL; bal = bal->next ) {
|
||||
acct_balances_t* balances = (acct_balances_t*)bal->data;
|
||||
/* Load starting balances */
|
||||
bal_slist = gnc_sql_get_account_balances_slist( be );
|
||||
for ( bal = bal_slist; bal != NULL; bal = bal->next )
|
||||
{
|
||||
acct_balances_t* balances = (acct_balances_t*)bal->data;
|
||||
|
||||
g_object_set( balances->acct,
|
||||
"start-balance", &balances->balance,
|
||||
"start-cleared-balance", &balances->cleared_balance,
|
||||
"start-reconciled-balance", &balances->reconciled_balance,
|
||||
NULL);
|
||||
g_object_set( balances->acct,
|
||||
"start-balance", &balances->balance,
|
||||
"start-cleared-balance", &balances->cleared_balance,
|
||||
"start-reconciled-balance", &balances->reconciled_balance,
|
||||
NULL);
|
||||
|
||||
}
|
||||
if( bal_slist != NULL ) {
|
||||
g_slist_free( bal_slist );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( bal_slist != NULL )
|
||||
{
|
||||
g_slist_free( bal_slist );
|
||||
}
|
||||
}
|
||||
|
||||
LEAVE( "" );
|
||||
LEAVE( "" );
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_account_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if ( version == 0 )
|
||||
{
|
||||
(void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
@ -298,95 +321,114 @@ gnc_sql_save_account( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
Account* pAcc = GNC_ACCOUNT(inst);
|
||||
const GncGUID* guid;
|
||||
gboolean is_infant;
|
||||
gboolean is_ok = FALSE;
|
||||
gnc_commodity* commodity;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
gboolean is_ok = FALSE;
|
||||
gnc_commodity* commodity;
|
||||
gint op;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_ACCOUNT(inst), FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_ACCOUNT(inst), FALSE );
|
||||
|
||||
ENTER( "inst=%p", inst );
|
||||
ENTER( "inst=%p", inst );
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
|
||||
// If there is no commodity yet, this might be because a new account name
|
||||
// has been entered directly into the register and an account window will
|
||||
// be opened. The account info is not complete yet, but the name has been
|
||||
// set, triggering this commit
|
||||
// has been entered directly into the register and an account window will
|
||||
// be opened. The account info is not complete yet, but the name has been
|
||||
// set, triggering this commit
|
||||
commodity = xaccAccountGetCommodity( pAcc );
|
||||
|
||||
is_ok = TRUE;
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
is_ok = TRUE;
|
||||
if ( qof_instance_get_destroying( inst ) )
|
||||
{
|
||||
op = OP_DB_DELETE;
|
||||
}
|
||||
else if ( be->is_pristine_db || is_infant )
|
||||
{
|
||||
op = OP_DB_INSERT;
|
||||
}
|
||||
else
|
||||
{
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
|
||||
// If not deleting the account, ensure the commodity is in the db
|
||||
if( op != OP_DB_DELETE && commodity != NULL ) {
|
||||
is_ok = gnc_sql_save_commodity( be, commodity );
|
||||
}
|
||||
if ( op != OP_DB_DELETE && commodity != NULL )
|
||||
{
|
||||
is_ok = gnc_sql_save_commodity( be, commodity );
|
||||
}
|
||||
|
||||
if( is_ok ) {
|
||||
is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_ACCOUNT, pAcc, col_table );
|
||||
}
|
||||
if ( is_ok )
|
||||
{
|
||||
is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_ACCOUNT, pAcc, col_table );
|
||||
}
|
||||
|
||||
if( is_ok ) {
|
||||
// Now, commit or delete any slots
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if( !qof_instance_get_destroying(inst) ) {
|
||||
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
} else {
|
||||
is_ok = gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
if ( is_ok )
|
||||
{
|
||||
// Now, commit or delete any slots
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if ( !qof_instance_get_destroying(inst) )
|
||||
{
|
||||
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
is_ok = gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
|
||||
LEAVE( "is_ok=%d", is_ok );
|
||||
LEAVE( "is_ok=%d", is_ok );
|
||||
|
||||
return is_ok;
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
load_account_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
/*@ null @*/ QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
/*@ null @*/ QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GncGUID guid;
|
||||
Account* account = NULL;
|
||||
Account* account = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
|
||||
if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
|
||||
{
|
||||
(void)string_to_guid( g_value_get_string( val ), &guid );
|
||||
account = xaccAccountLookup( &guid, be->primary_book );
|
||||
if( account != NULL ) {
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, account, NULL );
|
||||
} else {
|
||||
g_return_if_fail( setter != NULL );
|
||||
(*setter)( pObject, (const gpointer)account );
|
||||
}
|
||||
} else {
|
||||
PWARN( "Account ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
account = xaccAccountLookup( &guid, be->primary_book );
|
||||
if ( account != NULL )
|
||||
{
|
||||
if ( table_row->gobj_param_name != NULL )
|
||||
{
|
||||
g_object_set( pObject, table_row->gobj_param_name, account, NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
g_return_if_fail( setter != NULL );
|
||||
(*setter)( pObject, (const gpointer)account );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PWARN( "Account ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static GncSqlColumnTypeHandler account_guid_handler
|
||||
= { load_account_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist };
|
||||
= { load_account_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist
|
||||
};
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_account_handler( void )
|
||||
@ -398,14 +440,14 @@ gnc_sql_init_account_handler( void )
|
||||
gnc_sql_save_account, /* commit */
|
||||
load_all_accounts, /* initial_load */
|
||||
create_account_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
(void)qof_object_register_backend( GNC_ID_ACCOUNT, GNC_SQL_BACKEND, &be_data );
|
||||
|
||||
gnc_sql_register_col_type_handler( CT_ACCOUNTREF, &account_guid_handler );
|
||||
gnc_sql_register_col_type_handler( CT_ACCOUNTREF, &account_guid_handler );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -57,14 +57,18 @@ static void set_root_template_guid( gpointer pObject, /*@ null @*/ gpointer pVal
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "root_account_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_root_account_guid, set_root_account_guid },
|
||||
{ "root_template_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_root_template_guid, set_root_template_guid },
|
||||
/*@ -full_init_block @*/
|
||||
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
|
||||
{
|
||||
"root_account_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_root_account_guid, set_root_account_guid
|
||||
},
|
||||
{
|
||||
"root_template_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_root_template_guid, set_root_template_guid
|
||||
},
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -74,8 +78,8 @@ get_root_account_guid( gpointer pObject )
|
||||
QofBook* book = QOF_BOOK(pObject);
|
||||
const Account* root;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( QOF_IS_BOOK(pObject), NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( QOF_IS_BOOK(pObject), NULL );
|
||||
|
||||
root = gnc_book_get_root_account( book );
|
||||
return (gpointer)qof_instance_get_guid( QOF_INSTANCE(root) );
|
||||
@ -88,9 +92,9 @@ set_root_account_guid( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
const Account* root;
|
||||
GncGUID* guid = (GncGUID*)pValue;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( QOF_IS_BOOK(pObject) );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( QOF_IS_BOOK(pObject) );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
root = gnc_book_get_root_account( book );
|
||||
qof_instance_set_guid( QOF_INSTANCE(root), guid );
|
||||
@ -102,8 +106,8 @@ get_root_template_guid( gpointer pObject )
|
||||
const QofBook* book = QOF_BOOK(pObject);
|
||||
const Account* root;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( QOF_IS_BOOK(pObject), NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( QOF_IS_BOOK(pObject), NULL );
|
||||
|
||||
root = gnc_book_get_template_root( book );
|
||||
return (gpointer)qof_instance_get_guid( QOF_INSTANCE(root) );
|
||||
@ -116,12 +120,13 @@ set_root_template_guid( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
GncGUID* guid = (GncGUID*)pValue;
|
||||
Account* root;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( QOF_IS_BOOK(pObject) );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( QOF_IS_BOOK(pObject) );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
root = gnc_book_get_template_root( book );
|
||||
if( root == NULL ) {
|
||||
if ( root == NULL )
|
||||
{
|
||||
root = xaccMallocAccount( book );
|
||||
xaccAccountBeginEdit( root );
|
||||
xaccAccountSetType( root, ACCT_TYPE_ROOT );
|
||||
@ -136,22 +141,23 @@ static void
|
||||
load_single_book( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GncGUID* guid;
|
||||
QofBook* pBook;
|
||||
QofBook* pBook;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
|
||||
pBook = be->primary_book;
|
||||
if( pBook == NULL ) {
|
||||
pBook = qof_book_new();
|
||||
}
|
||||
pBook = be->primary_book;
|
||||
if ( pBook == NULL )
|
||||
{
|
||||
pBook = qof_book_new();
|
||||
}
|
||||
|
||||
qof_book_begin_edit( pBook );
|
||||
qof_book_begin_edit( pBook );
|
||||
gnc_sql_load_object( be, row, GNC_ID_BOOK, pBook, col_table );
|
||||
gnc_sql_slots_load( be, QOF_INSTANCE(pBook) );
|
||||
qof_book_commit_edit( pBook );
|
||||
qof_book_commit_edit( pBook );
|
||||
|
||||
qof_instance_mark_clean( QOF_INSTANCE(pBook) );
|
||||
}
|
||||
@ -162,25 +168,30 @@ load_all_books( GncSqlBackend* be )
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, BOOK_TABLE );
|
||||
if( stmt != NULL ) {
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
if ( stmt != NULL )
|
||||
{
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
// If there are no rows, try committing the book
|
||||
if( row == NULL ) {
|
||||
(void)gnc_sql_save_book( be, QOF_INSTANCE(be->primary_book) );
|
||||
} else {
|
||||
// Otherwise, load the 1st book.
|
||||
load_single_book( be, row );
|
||||
}
|
||||
// If there are no rows, try committing the book
|
||||
if ( row == NULL )
|
||||
{
|
||||
(void)gnc_sql_save_book( be, QOF_INSTANCE(be->primary_book) );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Otherwise, load the 1st book.
|
||||
load_single_book( be, row );
|
||||
}
|
||||
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -188,12 +199,13 @@ load_all_books( GncSqlBackend* be )
|
||||
static void
|
||||
create_book_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, BOOK_TABLE );
|
||||
if( version == 0 ) {
|
||||
version = gnc_sql_get_table_version( be, BOOK_TABLE );
|
||||
if ( version == 0 )
|
||||
{
|
||||
(void)gnc_sql_create_table( be, BOOK_TABLE, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
@ -202,17 +214,17 @@ create_book_tables( GncSqlBackend* be )
|
||||
gboolean
|
||||
gnc_sql_save_book( GncSqlBackend* be, QofInstance* inst)
|
||||
{
|
||||
gboolean status;
|
||||
gboolean status;
|
||||
|
||||
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 );
|
||||
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 );
|
||||
|
||||
status = gnc_sql_commit_standard_item( be, inst, BOOK_TABLE, GNC_ID_BOOK, col_table );
|
||||
status = gnc_sql_commit_standard_item( be, inst, BOOK_TABLE, GNC_ID_BOOK, col_table );
|
||||
|
||||
qof_book_mark_saved( QOF_BOOK(inst) );
|
||||
qof_book_mark_saved( QOF_BOOK(inst) );
|
||||
|
||||
return status;
|
||||
return status;
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
@ -226,10 +238,10 @@ gnc_sql_init_book_handler( void )
|
||||
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 */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
(void)qof_object_register_backend( GNC_ID_BOOK, GNC_SQL_BACKEND, &be_data );
|
||||
|
@ -58,13 +58,13 @@
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
/*@ -full_init_block @*/
|
||||
{ "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 }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
static /*@ dependent @*//*@ null @*/ QofInstance* get_budget( gpointer pObj );
|
||||
@ -76,26 +76,35 @@ static void set_period_num( gpointer pObj, gpointer val );
|
||||
static gnc_numeric get_amount( gpointer pObj );
|
||||
static void set_amount( gpointer pObj, gnc_numeric value );
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
GncBudget* budget;
|
||||
Account* account;
|
||||
guint period_num;
|
||||
Account* account;
|
||||
guint period_num;
|
||||
} budget_amount_info_t;
|
||||
|
||||
static const GncSqlColumnTableEntry budget_amounts_col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "id", CT_INT, 0, COL_NNUL|COL_PKEY|COL_AUTOINC },
|
||||
{ "budget_guid", CT_BUDGETREF, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_budget, (QofSetterFunc)set_budget },
|
||||
{ "account_guid", CT_ACCOUNTREF, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_account, (QofSetterFunc)set_account },
|
||||
{ "period_num", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_period_num, (QofSetterFunc)set_period_num },
|
||||
{ "amount", CT_NUMERIC, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_amount, (QofSetterFunc)set_amount },
|
||||
/*@ -full_init_block @*/
|
||||
{ "id", CT_INT, 0, COL_NNUL | COL_PKEY | COL_AUTOINC },
|
||||
{
|
||||
"budget_guid", CT_BUDGETREF, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_budget, (QofSetterFunc)set_budget
|
||||
},
|
||||
{
|
||||
"account_guid", CT_ACCOUNTREF, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_account, (QofSetterFunc)set_account
|
||||
},
|
||||
{
|
||||
"period_num", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_period_num, (QofSetterFunc)set_period_num
|
||||
},
|
||||
{
|
||||
"amount", CT_NUMERIC, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_amount, (QofSetterFunc)set_amount
|
||||
},
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -104,9 +113,9 @@ get_budget( gpointer pObj )
|
||||
{
|
||||
budget_amount_info_t* info = (budget_amount_info_t*)pObj;
|
||||
|
||||
g_return_val_if_fail( pObj != NULL, NULL );
|
||||
g_return_val_if_fail( pObj != NULL, NULL );
|
||||
|
||||
return QOF_INSTANCE(info->budget);
|
||||
return QOF_INSTANCE(info->budget);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -119,9 +128,9 @@ get_account( gpointer pObj )
|
||||
{
|
||||
budget_amount_info_t* info = (budget_amount_info_t*)pObj;
|
||||
|
||||
g_return_val_if_fail( pObj != NULL, NULL );
|
||||
g_return_val_if_fail( pObj != NULL, NULL );
|
||||
|
||||
return QOF_INSTANCE(info->account);
|
||||
return QOF_INSTANCE(info->account);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -129,11 +138,11 @@ set_account( gpointer pObj, gpointer val )
|
||||
{
|
||||
budget_amount_info_t* info = (budget_amount_info_t*)pObj;
|
||||
|
||||
g_return_if_fail( pObj != NULL );
|
||||
g_return_if_fail( val != NULL );
|
||||
g_return_if_fail( GNC_IS_ACCOUNT(val) );
|
||||
g_return_if_fail( pObj != NULL );
|
||||
g_return_if_fail( val != NULL );
|
||||
g_return_if_fail( GNC_IS_ACCOUNT(val) );
|
||||
|
||||
info->account = GNC_ACCOUNT(val);
|
||||
info->account = GNC_ACCOUNT(val);
|
||||
}
|
||||
|
||||
static gint
|
||||
@ -141,9 +150,9 @@ get_period_num( gpointer pObj )
|
||||
{
|
||||
budget_amount_info_t* info = (budget_amount_info_t*)pObj;
|
||||
|
||||
g_return_val_if_fail( pObj != NULL, 0 );
|
||||
g_return_val_if_fail( pObj != NULL, 0 );
|
||||
|
||||
return info->period_num;
|
||||
return info->period_num;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -151,9 +160,9 @@ set_period_num( gpointer pObj, gpointer val )
|
||||
{
|
||||
budget_amount_info_t* info = (budget_amount_info_t*)pObj;
|
||||
|
||||
g_return_if_fail( pObj != NULL );
|
||||
g_return_if_fail( pObj != NULL );
|
||||
|
||||
info->period_num = GPOINTER_TO_UINT(val);
|
||||
info->period_num = GPOINTER_TO_UINT(val);
|
||||
}
|
||||
|
||||
static gnc_numeric
|
||||
@ -161,9 +170,9 @@ get_amount( gpointer pObj )
|
||||
{
|
||||
budget_amount_info_t* info = (budget_amount_info_t*)pObj;
|
||||
|
||||
g_return_val_if_fail( pObj != NULL, gnc_numeric_zero() );
|
||||
g_return_val_if_fail( pObj != NULL, gnc_numeric_zero() );
|
||||
|
||||
return gnc_budget_get_account_period_value( info->budget, info->account, info->period_num );
|
||||
return gnc_budget_get_account_period_value( info->budget, info->account, info->period_num );
|
||||
}
|
||||
|
||||
static void
|
||||
@ -171,9 +180,9 @@ set_amount( gpointer pObj, gnc_numeric value )
|
||||
{
|
||||
budget_amount_info_t* info = (budget_amount_info_t*)pObj;
|
||||
|
||||
g_return_if_fail( pObj != NULL );
|
||||
g_return_if_fail( pObj != NULL );
|
||||
|
||||
gnc_budget_set_account_period_value( info->budget, info->account, info->period_num, value );
|
||||
gnc_budget_set_account_period_value( info->budget, info->account, info->period_num, value );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------*/
|
||||
@ -187,33 +196,36 @@ static void
|
||||
load_budget_amounts( GncSqlBackend* be, GncBudget* budget )
|
||||
{
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
gchar* sql;
|
||||
gchar* sql;
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( budget != NULL );
|
||||
g_return_if_fail( budget != NULL );
|
||||
|
||||
(void)guid_to_string_buff( qof_instance_get_guid( QOF_INSTANCE(budget) ), guid_buf );
|
||||
sql = g_strdup_printf( "SELECT * FROM %s WHERE budget_guid='%s'", AMOUNTS_TABLE, guid_buf );
|
||||
stmt = gnc_sql_create_statement_from_sql( be, sql );
|
||||
g_free( sql );
|
||||
if( stmt != NULL ) {
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
budget_amount_info_t info;
|
||||
(void)guid_to_string_buff( qof_instance_get_guid( QOF_INSTANCE(budget) ), guid_buf );
|
||||
sql = g_strdup_printf( "SELECT * FROM %s WHERE budget_guid='%s'", AMOUNTS_TABLE, guid_buf );
|
||||
stmt = gnc_sql_create_statement_from_sql( be, sql );
|
||||
g_free( sql );
|
||||
if ( stmt != NULL )
|
||||
{
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
budget_amount_info_t info;
|
||||
|
||||
info.budget = budget;
|
||||
info.budget = budget;
|
||||
|
||||
while( row != NULL ) {
|
||||
gnc_sql_load_object( be, row, NULL, &info, budget_amounts_col_table );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
while ( row != NULL )
|
||||
{
|
||||
gnc_sql_load_object( be, row, NULL, &info, budget_amounts_col_table );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -226,17 +238,17 @@ static gboolean
|
||||
delete_budget_amounts( GncSqlBackend* be, GncBudget* budget )
|
||||
{
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
gchar* sql;
|
||||
gchar* sql;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( budget != NULL, FALSE );
|
||||
g_return_val_if_fail( budget != NULL, FALSE );
|
||||
|
||||
(void)guid_to_string_buff( qof_instance_get_guid( QOF_INSTANCE(budget) ), guid_buf );
|
||||
sql = g_strdup_printf( "DELETE FROM %s WHERE budget_guid='%s'", AMOUNTS_TABLE, guid_buf );
|
||||
(void)gnc_sql_execute_nonselect_sql( be, sql );
|
||||
g_free( sql );
|
||||
(void)guid_to_string_buff( qof_instance_get_guid( QOF_INSTANCE(budget) ), guid_buf );
|
||||
sql = g_strdup_printf( "DELETE FROM %s WHERE budget_guid='%s'", AMOUNTS_TABLE, guid_buf );
|
||||
(void)gnc_sql_execute_nonselect_sql( be, sql );
|
||||
g_free( sql );
|
||||
|
||||
return TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -249,66 +261,73 @@ static gboolean
|
||||
save_budget_amounts( GncSqlBackend* be, GncBudget* budget )
|
||||
{
|
||||
GList* descendants;
|
||||
/*@ dependent @*/ GList* node;
|
||||
budget_amount_info_t info;
|
||||
guint num_periods;
|
||||
gboolean is_ok = TRUE;;
|
||||
/*@ dependent @*/
|
||||
GList* node;
|
||||
budget_amount_info_t info;
|
||||
guint num_periods;
|
||||
gboolean is_ok = TRUE;;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( budget != NULL, FALSE );
|
||||
g_return_val_if_fail( budget != NULL, FALSE );
|
||||
|
||||
// Delete the amounts, then save
|
||||
delete_budget_amounts( be, budget );
|
||||
// Delete the amounts, then save
|
||||
delete_budget_amounts( be, budget );
|
||||
|
||||
info.budget = budget;
|
||||
num_periods = gnc_budget_get_num_periods( budget );
|
||||
info.budget = budget;
|
||||
num_periods = gnc_budget_get_num_periods( budget );
|
||||
descendants = gnc_account_get_descendants( gnc_book_get_root_account( be->primary_book ) );
|
||||
for( node = descendants; node != NULL && is_ok; node = g_list_next(node) ) {
|
||||
guint i;
|
||||
for ( node = descendants; node != NULL && is_ok; node = g_list_next(node) )
|
||||
{
|
||||
guint i;
|
||||
|
||||
info.account = GNC_ACCOUNT(node->data);
|
||||
for( i = 0; i < num_periods && is_ok; i++ ) {
|
||||
if( gnc_budget_is_account_period_value_set( budget, info.account, i ) ) {
|
||||
info.period_num = i;
|
||||
is_ok = gnc_sql_do_db_operation( be, OP_DB_INSERT, AMOUNTS_TABLE, "", &info,
|
||||
budget_amounts_col_table );
|
||||
}
|
||||
}
|
||||
info.account = GNC_ACCOUNT(node->data);
|
||||
for ( i = 0; i < num_periods && is_ok; i++ )
|
||||
{
|
||||
if ( gnc_budget_is_account_period_value_set( budget, info.account, i ) )
|
||||
{
|
||||
info.period_num = i;
|
||||
is_ok = gnc_sql_do_db_operation( be, OP_DB_INSERT, AMOUNTS_TABLE, "", &info,
|
||||
budget_amounts_col_table );
|
||||
}
|
||||
}
|
||||
}
|
||||
g_list_free( descendants );
|
||||
|
||||
return is_ok;
|
||||
return is_ok;
|
||||
}
|
||||
/*----------------------------------------------------------------*/
|
||||
static /*@ dependent @*//*@ null @*/ GncBudget*
|
||||
load_single_budget( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GncGUID* guid;
|
||||
GncBudget* pBudget = NULL;
|
||||
Recurrence* r;
|
||||
GncBudget* pBudget = NULL;
|
||||
Recurrence* r;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
if( guid != NULL ) {
|
||||
pBudget = gnc_budget_lookup( guid, be->primary_book );
|
||||
}
|
||||
if( pBudget == NULL ) {
|
||||
if ( guid != NULL )
|
||||
{
|
||||
pBudget = gnc_budget_lookup( guid, be->primary_book );
|
||||
}
|
||||
if ( pBudget == NULL )
|
||||
{
|
||||
pBudget = gnc_budget_new( be->primary_book );
|
||||
}
|
||||
|
||||
gnc_budget_begin_edit( pBudget );
|
||||
gnc_budget_begin_edit( pBudget );
|
||||
gnc_sql_load_object( be, row, GNC_ID_BUDGET, pBudget, col_table );
|
||||
load_budget_amounts( be, pBudget );
|
||||
r = gnc_sql_recurrence_load( be, gnc_budget_get_guid( pBudget ) );
|
||||
if( r != NULL ) {
|
||||
gnc_budget_set_recurrence( pBudget, r );
|
||||
g_free( r );
|
||||
}
|
||||
gnc_budget_commit_edit( pBudget );
|
||||
load_budget_amounts( be, pBudget );
|
||||
r = gnc_sql_recurrence_load( be, gnc_budget_get_guid( pBudget ) );
|
||||
if ( r != NULL )
|
||||
{
|
||||
gnc_budget_set_recurrence( pBudget, r );
|
||||
g_free( r );
|
||||
}
|
||||
gnc_budget_commit_edit( pBudget );
|
||||
|
||||
return pBudget;
|
||||
return pBudget;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -316,32 +335,37 @@ load_all_budgets( GncSqlBackend* be )
|
||||
{
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
GList* list = NULL;
|
||||
GList* list = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, BUDGET_TABLE );
|
||||
if( stmt != NULL ) {
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
GncBudget* b;
|
||||
if ( stmt != NULL )
|
||||
{
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
GncBudget* b;
|
||||
|
||||
while( row != NULL ) {
|
||||
b = load_single_budget( be, row );
|
||||
if( b != NULL ) {
|
||||
list = g_list_prepend( list, b );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
while ( row != NULL )
|
||||
{
|
||||
b = load_single_budget( be, row );
|
||||
if ( b != NULL )
|
||||
{
|
||||
list = g_list_prepend( list, b );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
g_list_free( list );
|
||||
}
|
||||
}
|
||||
if ( list != NULL )
|
||||
{
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
g_list_free( list );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -349,17 +373,19 @@ load_all_budgets( GncSqlBackend* be )
|
||||
static void
|
||||
create_budget_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, BUDGET_TABLE );
|
||||
if( version == 0 ) {
|
||||
version = gnc_sql_get_table_version( be, BUDGET_TABLE );
|
||||
if ( version == 0 )
|
||||
{
|
||||
(void)gnc_sql_create_table( be, BUDGET_TABLE, TABLE_VERSION, col_table );
|
||||
}
|
||||
|
||||
version = gnc_sql_get_table_version( be, AMOUNTS_TABLE );
|
||||
if( version == 0 ) {
|
||||
version = gnc_sql_get_table_version( be, AMOUNTS_TABLE );
|
||||
if ( version == 0 )
|
||||
{
|
||||
(void)gnc_sql_create_table( be, AMOUNTS_TABLE, AMOUNTS_TABLE_VERSION, budget_amounts_col_table );
|
||||
}
|
||||
}
|
||||
@ -370,111 +396,133 @@ save_budget( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
GncBudget* pBudget = GNC_BUDGET(inst);
|
||||
const GncGUID* guid;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
gboolean is_ok;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
gboolean is_ok;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_BUDGET(inst), FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_BUDGET(inst), FALSE );
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if ( qof_instance_get_destroying( inst ) )
|
||||
{
|
||||
op = OP_DB_DELETE;
|
||||
}
|
||||
else if ( be->is_pristine_db || is_infant )
|
||||
{
|
||||
op = OP_DB_INSERT;
|
||||
}
|
||||
else
|
||||
{
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
is_ok = gnc_sql_do_db_operation( be, op, BUDGET_TABLE, GNC_ID_BUDGET, pBudget, col_table );
|
||||
|
||||
// Now, commit any slots and recurrence
|
||||
if( is_ok ) {
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if( !qof_instance_get_destroying(inst) ) {
|
||||
is_ok = save_budget_amounts( be, pBudget );
|
||||
if( is_ok ) {
|
||||
is_ok = gnc_sql_recurrence_save( be, guid, gnc_budget_get_recurrence( pBudget ) );
|
||||
}
|
||||
if( is_ok ) {
|
||||
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
}
|
||||
} else {
|
||||
is_ok = delete_budget_amounts( be, pBudget );
|
||||
if( is_ok ) {
|
||||
is_ok = gnc_sql_recurrence_delete( be, guid );
|
||||
}
|
||||
if( is_ok ) {
|
||||
(void)gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( is_ok )
|
||||
{
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if ( !qof_instance_get_destroying(inst) )
|
||||
{
|
||||
is_ok = save_budget_amounts( be, pBudget );
|
||||
if ( is_ok )
|
||||
{
|
||||
is_ok = gnc_sql_recurrence_save( be, guid, gnc_budget_get_recurrence( pBudget ) );
|
||||
}
|
||||
if ( is_ok )
|
||||
{
|
||||
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
is_ok = delete_budget_amounts( be, pBudget );
|
||||
if ( is_ok )
|
||||
{
|
||||
is_ok = gnc_sql_recurrence_delete( be, guid );
|
||||
}
|
||||
if ( is_ok )
|
||||
{
|
||||
(void)gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return is_ok;
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
static void
|
||||
do_save_budget( QofInstance* inst, gpointer data )
|
||||
{
|
||||
write_objects_t* s = (write_objects_t*)data;
|
||||
write_objects_t* s = (write_objects_t*)data;
|
||||
|
||||
if( s->is_ok ) {
|
||||
s->is_ok = save_budget( s->be, inst );
|
||||
}
|
||||
if ( s->is_ok )
|
||||
{
|
||||
s->is_ok = save_budget( s->be, inst );
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
write_budgets( GncSqlBackend* be )
|
||||
{
|
||||
write_objects_t data;
|
||||
write_objects_t data;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
|
||||
data.be = be;
|
||||
data.is_ok = TRUE;
|
||||
data.be = be;
|
||||
data.is_ok = TRUE;
|
||||
qof_collection_foreach( qof_book_get_collection( be->primary_book, GNC_ID_BUDGET ),
|
||||
(QofInstanceForeachCB)do_save_budget, &data );
|
||||
|
||||
return data.is_ok;
|
||||
return data.is_ok;
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
load_budget_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
/*@ null @*/ QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
/*@ null @*/ QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GncGUID guid;
|
||||
GncBudget* budget = NULL;
|
||||
GncBudget* budget = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
|
||||
if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
|
||||
{
|
||||
(void)string_to_guid( g_value_get_string( val ), &guid );
|
||||
budget = gnc_budget_lookup( &guid, be->primary_book );
|
||||
if( budget != NULL ) {
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, budget, NULL );
|
||||
} else {
|
||||
g_return_if_fail( setter != NULL );
|
||||
(*setter)( pObject, (const gpointer)budget );
|
||||
}
|
||||
} else {
|
||||
PWARN( "Budget ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
budget = gnc_budget_lookup( &guid, be->primary_book );
|
||||
if ( budget != NULL )
|
||||
{
|
||||
if ( table_row->gobj_param_name != NULL )
|
||||
{
|
||||
g_object_set( pObject, table_row->gobj_param_name, budget, NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
g_return_if_fail( setter != NULL );
|
||||
(*setter)( pObject, (const gpointer)budget );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PWARN( "Budget ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static GncSqlColumnTypeHandler budget_guid_handler
|
||||
= { load_budget_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist };
|
||||
= { load_budget_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist
|
||||
};
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_budget_handler( void )
|
||||
@ -486,14 +534,14 @@ gnc_sql_init_budget_handler( void )
|
||||
save_budget, /* commit */
|
||||
load_all_budgets, /* initial_load */
|
||||
create_budget_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
write_budgets /* write */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
write_budgets /* write */
|
||||
};
|
||||
|
||||
(void)qof_object_register_backend( GNC_ID_BUDGET, GNC_SQL_BACKEND, &be_data );
|
||||
|
||||
gnc_sql_register_col_type_handler( CT_BUDGETREF, &budget_guid_handler );
|
||||
gnc_sql_register_col_type_handler( CT_BUDGETREF, &budget_guid_handler );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
||||
|
@ -57,22 +57,27 @@ static void set_quote_source_name( gpointer pObject, /*@ null @*/ gpointer pValu
|
||||
#define COMMODITY_MAX_QUOTESOURCE_LEN 2048
|
||||
#define COMMODITY_MAX_QUOTE_TZ_LEN 2048
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] = {
|
||||
/*@ -full_init_block @*/
|
||||
{ "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,
|
||||
(QofSetterFunc)gnc_commodity_set_namespace },
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "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,
|
||||
(QofSetterFunc)gnc_commodity_set_namespace
|
||||
},
|
||||
{ "mnemonic", CT_STRING, COMMODITY_MAX_MNEMONIC_LEN, COL_NNUL, "mnemonic" },
|
||||
{ "fullname", CT_STRING, COMMODITY_MAX_FULLNAME_LEN, 0, "fullname" },
|
||||
{ "cusip", CT_STRING, COMMODITY_MAX_CUSIP_LEN, 0, "cusip" },
|
||||
{ "fraction", CT_INT, 0, COL_NNUL, "fraction" },
|
||||
{ "quote_flag", CT_BOOLEAN, 0, COL_NNUL, "quote_flag" },
|
||||
{ "quote_source", CT_STRING, COMMODITY_MAX_QUOTESOURCE_LEN, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_quote_source_name, set_quote_source_name },
|
||||
{
|
||||
"quote_source", CT_STRING, COMMODITY_MAX_QUOTESOURCE_LEN, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_quote_source_name, set_quote_source_name
|
||||
},
|
||||
{ "quote_tz", CT_STRING, COMMODITY_MAX_QUOTE_TZ_LEN, 0, "quote-tz" },
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -82,12 +87,12 @@ get_quote_source_name( gpointer pObject )
|
||||
{
|
||||
const gnc_commodity* pCommodity;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_COMMODITY(pObject), NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_COMMODITY(pObject), NULL );
|
||||
|
||||
pCommodity = GNC_COMMODITY(pObject);
|
||||
return (gpointer)gnc_quote_source_get_internal_name(
|
||||
gnc_commodity_get_quote_source(pCommodity));
|
||||
gnc_commodity_get_quote_source(pCommodity));
|
||||
}
|
||||
|
||||
static void
|
||||
@ -97,10 +102,10 @@ set_quote_source_name( gpointer pObject, gpointer pValue )
|
||||
const gchar* quote_source_name = (const gchar*)pValue;
|
||||
gnc_quote_source* quote_source;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_COMMODITY(pObject) );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( GNC_IS_COMMODITY(pObject) );
|
||||
|
||||
if( pValue == NULL ) return;
|
||||
if ( pValue == NULL ) return;
|
||||
|
||||
pCommodity = GNC_COMMODITY(pObject);
|
||||
quote_source = gnc_quote_source_lookup_by_internal( quote_source_name );
|
||||
@ -114,9 +119,9 @@ load_single_commodity( GncSqlBackend* be, GncSqlRow* row )
|
||||
gnc_commodity* pCommodity;
|
||||
|
||||
pCommodity = gnc_commodity_new( pBook, NULL, NULL, NULL, NULL, 100 );
|
||||
gnc_commodity_begin_edit( pCommodity );
|
||||
gnc_commodity_begin_edit( pCommodity );
|
||||
gnc_sql_load_object( be, row, GNC_ID_COMMODITY, pCommodity, col_table );
|
||||
gnc_commodity_commit_edit( pCommodity );
|
||||
gnc_commodity_commit_edit( pCommodity );
|
||||
|
||||
return pCommodity;
|
||||
}
|
||||
@ -130,44 +135,48 @@ load_all_commodities( GncSqlBackend* be )
|
||||
|
||||
pTable = gnc_commodity_table_get_table( be->primary_book );
|
||||
stmt = gnc_sql_create_select_statement( be, COMMODITIES_TABLE );
|
||||
if( stmt == NULL ) return;
|
||||
if ( stmt == NULL ) return;
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
gnc_commodity* pCommodity;
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
gchar* sql;
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
gchar* sql;
|
||||
|
||||
while( row != NULL ) {
|
||||
while ( row != NULL )
|
||||
{
|
||||
pCommodity = load_single_commodity( be, row );
|
||||
|
||||
if( pCommodity != NULL ) {
|
||||
if ( pCommodity != NULL )
|
||||
{
|
||||
GncGUID guid;
|
||||
|
||||
guid = *qof_instance_get_guid( QOF_INSTANCE(pCommodity) );
|
||||
pCommodity = gnc_commodity_table_insert( pTable, pCommodity );
|
||||
qof_instance_set_guid( QOF_INSTANCE(pCommodity), &guid );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
sql = g_strdup_printf( "SELECT DISTINCT guid FROM %s", COMMODITIES_TABLE );
|
||||
gnc_sql_slots_load_for_sql_subquery( be, sql,
|
||||
(BookLookupFn)gnc_commodity_find_commodity_by_guid );
|
||||
g_free( sql );
|
||||
sql = g_strdup_printf( "SELECT DISTINCT guid FROM %s", COMMODITIES_TABLE );
|
||||
gnc_sql_slots_load_for_sql_subquery( be, sql,
|
||||
(BookLookupFn)gnc_commodity_find_commodity_by_guid );
|
||||
g_free( sql );
|
||||
}
|
||||
}
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_commodities_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, COMMODITIES_TABLE );
|
||||
if( version == 0 ) {
|
||||
version = gnc_sql_get_table_version( be, COMMODITIES_TABLE );
|
||||
if ( version == 0 )
|
||||
{
|
||||
(void)gnc_sql_create_table( be, COMMODITIES_TABLE, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
@ -176,40 +185,49 @@ create_commodities_tables( GncSqlBackend* be )
|
||||
static gboolean
|
||||
do_commit_commodity( GncSqlBackend* be, QofInstance* inst, gboolean force_insert )
|
||||
{
|
||||
const GncGUID* guid;
|
||||
gboolean is_infant;
|
||||
gint op;
|
||||
gboolean is_ok;
|
||||
const GncGUID* guid;
|
||||
gboolean is_infant;
|
||||
gint op;
|
||||
gboolean is_ok;
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant || force_insert ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if ( qof_instance_get_destroying( inst ) )
|
||||
{
|
||||
op = OP_DB_DELETE;
|
||||
}
|
||||
else if ( be->is_pristine_db || is_infant || force_insert )
|
||||
{
|
||||
op = OP_DB_INSERT;
|
||||
}
|
||||
else
|
||||
{
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
is_ok = gnc_sql_do_db_operation( be, op, COMMODITIES_TABLE, GNC_ID_COMMODITY, inst, col_table );
|
||||
|
||||
if( is_ok ) {
|
||||
// Now, commit any slots
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if( !qof_instance_get_destroying(inst) ) {
|
||||
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
} else {
|
||||
is_ok = gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
if ( is_ok )
|
||||
{
|
||||
// Now, commit any slots
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if ( !qof_instance_get_destroying(inst) )
|
||||
{
|
||||
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
is_ok = gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
|
||||
return is_ok;
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
commit_commodity( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
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 );
|
||||
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 );
|
||||
|
||||
return do_commit_commodity( be, inst, FALSE );
|
||||
}
|
||||
@ -217,65 +235,74 @@ commit_commodity( GncSqlBackend* be, QofInstance* inst )
|
||||
static gboolean
|
||||
is_commodity_in_db( GncSqlBackend* be, gnc_commodity* pCommodity )
|
||||
{
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( pCommodity != NULL, FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( pCommodity != NULL, FALSE );
|
||||
|
||||
return gnc_sql_object_is_it_in_db( be, COMMODITIES_TABLE, GNC_ID_COMMODITY,
|
||||
pCommodity, col_table );
|
||||
pCommodity, col_table );
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnc_sql_save_commodity( GncSqlBackend* be, gnc_commodity* pCommodity )
|
||||
{
|
||||
gboolean is_ok = TRUE;
|
||||
gboolean is_ok = TRUE;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( pCommodity != NULL, FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( pCommodity != NULL, FALSE );
|
||||
|
||||
if( !is_commodity_in_db( be, pCommodity ) ) {
|
||||
if ( !is_commodity_in_db( be, pCommodity ) )
|
||||
{
|
||||
is_ok = do_commit_commodity( be, QOF_INSTANCE(pCommodity), TRUE );
|
||||
}
|
||||
|
||||
return is_ok;
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
static void
|
||||
load_commodity_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
/*@ null @*/ QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
/*@ null @*/ QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GncGUID guid;
|
||||
gnc_commodity* commodity = NULL;
|
||||
gnc_commodity* commodity = NULL;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
|
||||
(void)string_to_guid( g_value_get_string( val ), &guid );
|
||||
commodity = gnc_commodity_find_commodity_by_guid( &guid, be->primary_book );
|
||||
if( commodity != NULL ) {
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, commodity, NULL );
|
||||
} else if( setter != NULL ) {
|
||||
(*setter)( pObject, (const gpointer)commodity );
|
||||
}
|
||||
} else {
|
||||
PWARN( "Commodity ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
|
||||
{
|
||||
(void)string_to_guid( g_value_get_string( val ), &guid );
|
||||
commodity = gnc_commodity_find_commodity_by_guid( &guid, be->primary_book );
|
||||
if ( commodity != NULL )
|
||||
{
|
||||
if ( table_row->gobj_param_name != NULL )
|
||||
{
|
||||
g_object_set( pObject, table_row->gobj_param_name, commodity, NULL );
|
||||
}
|
||||
else if ( setter != NULL )
|
||||
{
|
||||
(*setter)( pObject, (const gpointer)commodity );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PWARN( "Commodity ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static GncSqlColumnTypeHandler commodity_guid_handler
|
||||
= { load_commodity_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist };
|
||||
= { load_commodity_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist
|
||||
};
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_commodity_handler( void )
|
||||
@ -287,14 +314,14 @@ gnc_sql_init_commodity_handler( void )
|
||||
commit_commodity, /* commit */
|
||||
load_all_commodities, /* initial_load */
|
||||
create_commodities_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
(void)qof_object_register_backend( GNC_ID_COMMODITY, GNC_SQL_BACKEND, &be_data );
|
||||
|
||||
gnc_sql_register_col_type_handler( CT_COMMODITYREF, &commodity_guid_handler );
|
||||
gnc_sql_register_col_type_handler( CT_COMMODITYREF, &commodity_guid_handler );
|
||||
}
|
||||
/* ========================== END OF FILE ===================== */
|
||||
|
@ -53,13 +53,15 @@ static void set_lot_account( gpointer pObject, /*@ null @*/ gpointer pValue );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
{ "account_guid", CT_ACCOUNTREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_lot_account, set_lot_account },
|
||||
/*@ -full_init_block @*/
|
||||
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
|
||||
{
|
||||
"account_guid", CT_ACCOUNTREF, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_lot_account, set_lot_account
|
||||
},
|
||||
{ "is_closed", CT_BOOLEAN, 0, COL_NNUL, "is-closed" },
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -69,8 +71,8 @@ get_lot_account( gpointer pObject )
|
||||
const GNCLot* lot;
|
||||
Account* pAccount;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_LOT(pObject), NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_LOT(pObject), NULL );
|
||||
|
||||
lot = GNC_LOT(pObject);
|
||||
pAccount = gnc_lot_get_account( lot );
|
||||
@ -83,31 +85,32 @@ set_lot_account( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
GNCLot* lot;
|
||||
Account* pAccount;
|
||||
|
||||
g_return_if_fail( pObject != NULL && GNC_IS_LOT(pObject) );
|
||||
g_return_if_fail( pValue == NULL || GNC_IS_ACCOUNT(pValue) );
|
||||
g_return_if_fail( pObject != NULL && GNC_IS_LOT(pObject) );
|
||||
g_return_if_fail( pValue == NULL || GNC_IS_ACCOUNT(pValue) );
|
||||
|
||||
lot = GNC_LOT(pObject);
|
||||
pAccount = GNC_ACCOUNT(pValue);
|
||||
if( pAccount != NULL ) {
|
||||
xaccAccountInsertLot( pAccount, lot );
|
||||
}
|
||||
if ( pAccount != NULL )
|
||||
{
|
||||
xaccAccountInsertLot( pAccount, lot );
|
||||
}
|
||||
}
|
||||
|
||||
static /*@ dependent @*//*@ null @*/ GNCLot*
|
||||
load_single_lot( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
GNCLot* lot;
|
||||
GNCLot* lot;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
lot = gnc_lot_new( be->primary_book );
|
||||
|
||||
gnc_lot_begin_edit( lot );
|
||||
gnc_lot_begin_edit( lot );
|
||||
gnc_sql_load_object( be, row, GNC_ID_LOT, lot, col_table );
|
||||
gnc_lot_commit_edit( lot );
|
||||
gnc_lot_commit_edit( lot );
|
||||
|
||||
return lot;
|
||||
return lot;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -116,51 +119,57 @@ load_all_lots( GncSqlBackend* be )
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
if( stmt != NULL ) {
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
GNCLot* lot;
|
||||
gchar* sql;
|
||||
if ( stmt != NULL )
|
||||
{
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
GNCLot* lot;
|
||||
gchar* sql;
|
||||
|
||||
while( row != NULL ) {
|
||||
lot = load_single_lot( be, row );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
while ( row != NULL )
|
||||
{
|
||||
lot = load_single_lot( be, row );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
sql = g_strdup_printf( "SELECT DISTINCT guid FROM %s", TABLE_NAME );
|
||||
gnc_sql_slots_load_for_sql_subquery( be, sql, (BookLookupFn)gnc_lot_lookup );
|
||||
g_free( sql );
|
||||
}
|
||||
}
|
||||
sql = g_strdup_printf( "SELECT DISTINCT guid FROM %s", TABLE_NAME );
|
||||
gnc_sql_slots_load_for_sql_subquery( be, sql, (BookLookupFn)gnc_lot_lookup );
|
||||
g_free( sql );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_lots_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
/* The table doesn't exist, so create it */
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if ( version == 0 )
|
||||
{
|
||||
/* The table doesn't exist, so create it */
|
||||
(void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
} else if( version == 1 ) {
|
||||
/* Version 1 -> 2 removes the 'NOT NULL' constraint on the account_guid
|
||||
field.
|
||||
}
|
||||
else if ( version == 1 )
|
||||
{
|
||||
/* Version 1 -> 2 removes the 'NOT NULL' constraint on the account_guid
|
||||
field.
|
||||
|
||||
Create a temporary table, copy the data from the old table, delete the
|
||||
old table, then rename the new one. */
|
||||
Create a temporary table, copy the data from the old table, delete the
|
||||
old table, then rename the new one. */
|
||||
|
||||
gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
|
||||
(void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
|
||||
gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
|
||||
(void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,9 +178,9 @@ create_lots_tables( GncSqlBackend* be )
|
||||
static gboolean
|
||||
commit_lot( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_LOT(inst), FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_LOT(inst), FALSE );
|
||||
|
||||
return gnc_sql_commit_standard_item( be, inst, TABLE_NAME, GNC_ID_LOT, col_table );
|
||||
}
|
||||
@ -179,64 +188,73 @@ commit_lot( GncSqlBackend* be, QofInstance* inst )
|
||||
static void
|
||||
do_save_lot( QofInstance* inst, gpointer data )
|
||||
{
|
||||
write_objects_t* s = (write_objects_t*)data;
|
||||
write_objects_t* s = (write_objects_t*)data;
|
||||
|
||||
if( s->is_ok ) {
|
||||
s->is_ok = commit_lot( s->be, inst );
|
||||
}
|
||||
if ( s->is_ok )
|
||||
{
|
||||
s->is_ok = commit_lot( s->be, inst );
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
write_lots( GncSqlBackend* be )
|
||||
{
|
||||
write_objects_t data;
|
||||
write_objects_t data;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
|
||||
data.be = be;
|
||||
data.is_ok = TRUE;
|
||||
data.be = be;
|
||||
data.is_ok = TRUE;
|
||||
qof_collection_foreach( qof_book_get_collection( be->primary_book, GNC_ID_LOT ),
|
||||
(QofInstanceForeachCB)do_save_lot, &data );
|
||||
return data.is_ok;
|
||||
return data.is_ok;
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
load_lot_guid( const GncSqlBackend* be, GncSqlRow* row,
|
||||
/*@ null @*/ QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
/*@ null @*/ QofSetterFunc setter, gpointer pObject,
|
||||
const GncSqlColumnTableEntry* table_row )
|
||||
{
|
||||
const GValue* val;
|
||||
GncGUID guid;
|
||||
GNCLot* lot;
|
||||
GNCLot* lot;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( table_row != NULL );
|
||||
|
||||
val = gnc_sql_row_get_value_at_col_name( row, table_row->col_name );
|
||||
if( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL ) {
|
||||
(void)string_to_guid( g_value_get_string( val ), &guid );
|
||||
lot = gnc_lot_lookup( &guid, be->primary_book );
|
||||
if( lot != NULL ) {
|
||||
if( table_row->gobj_param_name != NULL ) {
|
||||
g_object_set( pObject, table_row->gobj_param_name, lot, NULL );
|
||||
} else {
|
||||
g_return_if_fail( setter != NULL );
|
||||
(*setter)( pObject, (const gpointer)lot );
|
||||
}
|
||||
} else {
|
||||
PWARN( "Lot ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
if ( val != NULL && G_VALUE_HOLDS_STRING( val ) && g_value_get_string( val ) != NULL )
|
||||
{
|
||||
(void)string_to_guid( g_value_get_string( val ), &guid );
|
||||
lot = gnc_lot_lookup( &guid, be->primary_book );
|
||||
if ( lot != NULL )
|
||||
{
|
||||
if ( table_row->gobj_param_name != NULL )
|
||||
{
|
||||
g_object_set( pObject, table_row->gobj_param_name, lot, NULL );
|
||||
}
|
||||
else
|
||||
{
|
||||
g_return_if_fail( setter != NULL );
|
||||
(*setter)( pObject, (const gpointer)lot );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PWARN( "Lot ref '%s' not found", g_value_get_string( val ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static GncSqlColumnTypeHandler lot_guid_handler
|
||||
= { load_lot_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist };
|
||||
= { load_lot_guid,
|
||||
gnc_sql_add_objectref_guid_col_info_to_list,
|
||||
gnc_sql_add_colname_to_list,
|
||||
gnc_sql_add_gvalue_objectref_guid_to_slist
|
||||
};
|
||||
/* ================================================================= */
|
||||
void
|
||||
gnc_sql_init_lot_handler( void )
|
||||
@ -248,13 +266,13 @@ gnc_sql_init_lot_handler( void )
|
||||
commit_lot, /* commit */
|
||||
load_all_lots, /* initial_load */
|
||||
create_lots_tables, /* create tables */
|
||||
NULL, NULL, NULL,
|
||||
write_lots /* save all */
|
||||
NULL, NULL, NULL,
|
||||
write_lots /* save all */
|
||||
};
|
||||
|
||||
(void)qof_object_register_backend( GNC_ID_LOT, GNC_SQL_BACKEND, &be_data );
|
||||
|
||||
gnc_sql_register_col_type_handler( CT_LOTREF, &lot_guid_handler );
|
||||
gnc_sql_register_col_type_handler( CT_LOTREF, &lot_guid_handler );
|
||||
}
|
||||
|
||||
/* ========================== END OF FILE ===================== */
|
||||
|
@ -53,8 +53,8 @@
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
/*@ -full_init_block @*/
|
||||
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
|
||||
{ "commodity_guid", CT_COMMODITYREF, 0, COL_NNUL, "commodity" },
|
||||
{ "currency_guid", CT_COMMODITYREF, 0, COL_NNUL, "currency" },
|
||||
{ "date", CT_TIMESPEC, 0, COL_NNUL, "date" },
|
||||
@ -62,7 +62,7 @@ static const GncSqlColumnTableEntry col_table[] =
|
||||
{ "type", CT_STRING, PRICE_MAX_TYPE_LEN, 0, "type" },
|
||||
{ "value", CT_NUMERIC, 0, COL_NNUL, "value" },
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -70,16 +70,16 @@ static const GncSqlColumnTableEntry col_table[] =
|
||||
static /*@ null @*//*@ dependent @*/ GNCPrice*
|
||||
load_single_price( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
GNCPrice* pPrice;
|
||||
GNCPrice* pPrice;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
pPrice = gnc_price_create( be->primary_book );
|
||||
|
||||
gnc_price_begin_edit( pPrice );
|
||||
gnc_price_begin_edit( pPrice );
|
||||
gnc_sql_load_object( be, row, GNC_ID_PRICE, pPrice, col_table );
|
||||
gnc_price_commit_edit( pPrice );
|
||||
gnc_price_commit_edit( pPrice );
|
||||
|
||||
return pPrice;
|
||||
}
|
||||
@ -92,36 +92,40 @@ load_all_prices( GncSqlBackend* be )
|
||||
QofBook* pBook;
|
||||
GNCPriceDB* pPriceDB;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
pBook = be->primary_book;
|
||||
pPriceDB = gnc_book_get_pricedb( pBook );
|
||||
stmt = gnc_sql_create_select_statement( be, TABLE_NAME );
|
||||
if( stmt != NULL ) {
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GNCPrice* pPrice;
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
gchar* sql;
|
||||
if ( stmt != NULL )
|
||||
{
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GNCPrice* pPrice;
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
gchar* sql;
|
||||
|
||||
gnc_pricedb_set_bulk_update( pPriceDB, TRUE );
|
||||
while( row != NULL ) {
|
||||
pPrice = load_single_price( be, row );
|
||||
gnc_pricedb_set_bulk_update( pPriceDB, TRUE );
|
||||
while ( row != NULL )
|
||||
{
|
||||
pPrice = load_single_price( be, row );
|
||||
|
||||
if( pPrice != NULL ) {
|
||||
(void)gnc_pricedb_add_price( pPriceDB, pPrice );
|
||||
gnc_price_unref( pPrice );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
gnc_pricedb_set_bulk_update( pPriceDB, FALSE );
|
||||
if ( pPrice != NULL )
|
||||
{
|
||||
(void)gnc_pricedb_add_price( pPriceDB, pPrice );
|
||||
gnc_price_unref( pPrice );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
gnc_pricedb_set_bulk_update( pPriceDB, FALSE );
|
||||
|
||||
sql = g_strdup_printf( "SELECT DISTINCT guid FROM %s", TABLE_NAME );
|
||||
gnc_sql_slots_load_for_sql_subquery( be, sql, (BookLookupFn)gnc_price_lookup );
|
||||
g_free( sql );
|
||||
}
|
||||
sql = g_strdup_printf( "SELECT DISTINCT guid FROM %s", TABLE_NAME );
|
||||
gnc_sql_slots_load_for_sql_subquery( be, sql, (BookLookupFn)gnc_price_lookup );
|
||||
g_free( sql );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -129,17 +133,20 @@ load_all_prices( GncSqlBackend* be )
|
||||
static void
|
||||
create_prices_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if ( version == 0 )
|
||||
{
|
||||
(void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
} else if( version == 1 ) {
|
||||
/* Upgrade 64 bit int handling */
|
||||
gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
|
||||
(void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
|
||||
}
|
||||
else if ( version == 1 )
|
||||
{
|
||||
/* Upgrade 64 bit int handling */
|
||||
gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
|
||||
(void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,34 +156,41 @@ static gboolean
|
||||
save_price( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
GNCPrice* pPrice = GNC_PRICE(inst);
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
gboolean is_ok = TRUE;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
gboolean is_ok = TRUE;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_PRICE(inst), FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_PRICE(inst), FALSE );
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if ( qof_instance_get_destroying( inst ) )
|
||||
{
|
||||
op = OP_DB_DELETE;
|
||||
}
|
||||
else if ( be->is_pristine_db || is_infant )
|
||||
{
|
||||
op = OP_DB_INSERT;
|
||||
}
|
||||
else
|
||||
{
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
|
||||
if( op != OP_DB_DELETE ) {
|
||||
/* Ensure commodity and currency are in the db */
|
||||
(void)gnc_sql_save_commodity( be, gnc_price_get_commodity( pPrice ) );
|
||||
is_ok = gnc_sql_save_commodity( be, gnc_price_get_currency( pPrice ) );
|
||||
}
|
||||
if ( op != OP_DB_DELETE )
|
||||
{
|
||||
/* Ensure commodity and currency are in the db */
|
||||
(void)gnc_sql_save_commodity( be, gnc_price_get_commodity( pPrice ) );
|
||||
is_ok = gnc_sql_save_commodity( be, gnc_price_get_currency( pPrice ) );
|
||||
}
|
||||
|
||||
if( is_ok ) {
|
||||
is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_PRICE, pPrice, col_table );
|
||||
}
|
||||
if ( is_ok )
|
||||
{
|
||||
is_ok = gnc_sql_do_db_operation( be, op, TABLE_NAME, GNC_ID_PRICE, pPrice, col_table );
|
||||
}
|
||||
|
||||
return is_ok;
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -184,12 +198,13 @@ write_price( GNCPrice* p, gpointer data )
|
||||
{
|
||||
write_objects_t* s = (write_objects_t*)data;
|
||||
|
||||
g_return_val_if_fail( p != NULL, FALSE );
|
||||
g_return_val_if_fail( data != NULL, FALSE );
|
||||
g_return_val_if_fail( p != NULL, FALSE );
|
||||
g_return_val_if_fail( data != NULL, FALSE );
|
||||
|
||||
if( s->is_ok ) {
|
||||
s->is_ok = save_price( s->be, QOF_INSTANCE(p) );
|
||||
}
|
||||
if ( s->is_ok )
|
||||
{
|
||||
s->is_ok = save_price( s->be, QOF_INSTANCE(p) );
|
||||
}
|
||||
|
||||
return s->is_ok;
|
||||
}
|
||||
@ -198,14 +213,14 @@ static gboolean
|
||||
write_prices( GncSqlBackend* be )
|
||||
{
|
||||
GNCPriceDB* priceDB;
|
||||
write_objects_t data;
|
||||
write_objects_t data;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
|
||||
priceDB = gnc_book_get_pricedb( be->primary_book );
|
||||
|
||||
data.be = be;
|
||||
data.is_ok = TRUE;
|
||||
data.be = be;
|
||||
data.is_ok = TRUE;
|
||||
return gnc_pricedb_foreach_price( priceDB, write_price, &data, TRUE );
|
||||
}
|
||||
|
||||
@ -220,8 +235,8 @@ gnc_sql_init_price_handler( void )
|
||||
save_price, /* commit */
|
||||
load_all_prices, /* initial_load */
|
||||
create_prices_tables, /* create tables */
|
||||
NULL, NULL, NULL,
|
||||
write_prices /* write */
|
||||
NULL, NULL, NULL,
|
||||
write_prices /* write */
|
||||
};
|
||||
|
||||
(void)qof_object_register_backend( GNC_ID_PRICE, GNC_SQL_BACKEND, &be_data );
|
||||
|
@ -49,10 +49,13 @@
|
||||
|
||||
#define BUDGET_MAX_RECURRENCE_PERIOD_TYPE_LEN 2048
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
/*@ dependent @*/ GncSqlBackend* be;
|
||||
/*@ dependent @*/ const GncGUID* guid;
|
||||
/*@ dependent @*/ Recurrence* pRecurrence;
|
||||
/*@ dependent @*/
|
||||
const GncGUID* guid;
|
||||
/*@ dependent @*/
|
||||
Recurrence* pRecurrence;
|
||||
} recurrence_info_t;
|
||||
|
||||
static /*@ null @*/ gpointer get_obj_guid( gpointer pObject );
|
||||
@ -66,29 +69,39 @@ static void set_recurrence_period_start( gpointer pObject, /*@ null @*/ gpointer
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "id", CT_INT, 0, COL_PKEY|COL_NNUL|COL_AUTOINC },
|
||||
{ "obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_obj_guid, (QofSetterFunc)set_obj_guid },
|
||||
{ "recurrence_mult", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_recurrence_mult, (QofSetterFunc)set_recurrence_mult },
|
||||
{ "recurrence_period_type", CT_STRING, BUDGET_MAX_RECURRENCE_PERIOD_TYPE_LEN, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_recurrence_period_type, set_recurrence_period_type },
|
||||
{ "recurrence_period_start", CT_GDATE, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_recurrence_period_start, set_recurrence_period_start },
|
||||
/*@ -full_init_block @*/
|
||||
{ "id", CT_INT, 0, COL_PKEY | COL_NNUL | COL_AUTOINC },
|
||||
{
|
||||
"obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_obj_guid, (QofSetterFunc)set_obj_guid
|
||||
},
|
||||
{
|
||||
"recurrence_mult", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_recurrence_mult, (QofSetterFunc)set_recurrence_mult
|
||||
},
|
||||
{
|
||||
"recurrence_period_type", CT_STRING, BUDGET_MAX_RECURRENCE_PERIOD_TYPE_LEN, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_recurrence_period_type, set_recurrence_period_type
|
||||
},
|
||||
{
|
||||
"recurrence_period_start", CT_GDATE, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_recurrence_period_start, set_recurrence_period_start
|
||||
},
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
/* 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[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "obj_guid", CT_GUID, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_obj_guid, (QofSetterFunc)set_obj_guid },
|
||||
/*@ -full_init_block @*/
|
||||
{
|
||||
"obj_guid", CT_GUID, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_obj_guid, (QofSetterFunc)set_obj_guid
|
||||
},
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -98,7 +111,7 @@ get_obj_guid( gpointer pObject )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
return (gpointer)pInfo->guid;
|
||||
}
|
||||
@ -114,10 +127,10 @@ get_recurrence_mult( gpointer pObject )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, 0 );
|
||||
g_return_val_if_fail( pInfo->pRecurrence != NULL, 0 );
|
||||
g_return_val_if_fail( pObject != NULL, 0 );
|
||||
g_return_val_if_fail( pInfo->pRecurrence != NULL, 0 );
|
||||
|
||||
return (gint)pInfo->pRecurrence->mult;
|
||||
return (gint)pInfo->pRecurrence->mult;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -125,8 +138,8 @@ set_recurrence_mult( gpointer pObject, gint value )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pInfo->pRecurrence != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pInfo->pRecurrence != NULL );
|
||||
|
||||
pInfo->pRecurrence->mult = (guint16)value;
|
||||
}
|
||||
@ -136,11 +149,11 @@ get_recurrence_period_type( gpointer pObject )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pInfo->pRecurrence != NULL, NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pInfo->pRecurrence != NULL, NULL );
|
||||
|
||||
return (gpointer)recurrencePeriodTypeToString(
|
||||
recurrenceGetPeriodType( pInfo->pRecurrence ) );
|
||||
recurrenceGetPeriodType( pInfo->pRecurrence ) );
|
||||
}
|
||||
|
||||
static void
|
||||
@ -148,9 +161,9 @@ set_recurrence_period_type( gpointer pObject, gpointer pValue )
|
||||
{
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pInfo->pRecurrence != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pInfo->pRecurrence != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
pInfo->pRecurrence->ptype = recurrencePeriodTypeFromString( (gchar*)pValue );
|
||||
}
|
||||
@ -161,8 +174,8 @@ get_recurrence_period_start( gpointer pObject )
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
static GDate date;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pInfo->pRecurrence != NULL, NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pInfo->pRecurrence != NULL, NULL );
|
||||
|
||||
date = recurrenceGetDate( pInfo->pRecurrence );
|
||||
return (gpointer)&date;
|
||||
@ -174,9 +187,9 @@ set_recurrence_period_start( gpointer pObject, gpointer pValue )
|
||||
recurrence_info_t* pInfo = (recurrence_info_t*)pObject;
|
||||
GDate* date = (GDate*)pValue;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pInfo->pRecurrence != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pInfo->pRecurrence != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
pInfo->pRecurrence->start = *date;
|
||||
}
|
||||
@ -188,37 +201,38 @@ gnc_sql_recurrence_save( GncSqlBackend* be, const GncGUID* guid, const Recurrenc
|
||||
{
|
||||
recurrence_info_t recurrence_info;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( guid != NULL, FALSE );
|
||||
g_return_val_if_fail( r != NULL, FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( guid != NULL, FALSE );
|
||||
g_return_val_if_fail( r != NULL, FALSE );
|
||||
|
||||
(void)gnc_sql_recurrence_delete( be, guid );
|
||||
(void)gnc_sql_recurrence_delete( be, guid );
|
||||
|
||||
recurrence_info.be = be;
|
||||
recurrence_info.guid = guid;
|
||||
recurrence_info.pRecurrence = (Recurrence*)r;
|
||||
recurrence_info.pRecurrence = (Recurrence*)r;
|
||||
return gnc_sql_do_db_operation( be, OP_DB_INSERT, TABLE_NAME,
|
||||
TABLE_NAME, &recurrence_info, col_table );
|
||||
TABLE_NAME, &recurrence_info, col_table );
|
||||
}
|
||||
|
||||
void
|
||||
gnc_sql_recurrence_save_list( GncSqlBackend* be, const GncGUID* guid, GList* schedule )
|
||||
{
|
||||
recurrence_info_t recurrence_info;
|
||||
GList* l;
|
||||
GList* l;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( guid != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( guid != NULL );
|
||||
|
||||
(void)gnc_sql_recurrence_delete( be, guid );
|
||||
(void)gnc_sql_recurrence_delete( be, guid );
|
||||
|
||||
recurrence_info.be = be;
|
||||
recurrence_info.guid = guid;
|
||||
for( l = schedule; l != NULL; l = g_list_next( l ) ) {
|
||||
recurrence_info.pRecurrence = (Recurrence*)l->data;
|
||||
(void)gnc_sql_do_db_operation( be, OP_DB_INSERT, TABLE_NAME,
|
||||
TABLE_NAME, &recurrence_info, col_table );
|
||||
}
|
||||
for ( l = schedule; l != NULL; l = g_list_next( l ) )
|
||||
{
|
||||
recurrence_info.pRecurrence = (Recurrence*)l->data;
|
||||
(void)gnc_sql_do_db_operation( be, OP_DB_INSERT, TABLE_NAME,
|
||||
TABLE_NAME, &recurrence_info, col_table );
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -226,13 +240,13 @@ gnc_sql_recurrence_delete( GncSqlBackend* be, const GncGUID* guid )
|
||||
{
|
||||
recurrence_info_t recurrence_info;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( guid != NULL, FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( guid != NULL, FALSE );
|
||||
|
||||
recurrence_info.be = be;
|
||||
recurrence_info.guid = guid;
|
||||
return gnc_sql_do_db_operation( be, OP_DB_DELETE, TABLE_NAME,
|
||||
TABLE_NAME, &recurrence_info, guid_col_table );
|
||||
TABLE_NAME, &recurrence_info, guid_col_table );
|
||||
}
|
||||
|
||||
static void
|
||||
@ -240,12 +254,12 @@ load_recurrence( GncSqlBackend* be, GncSqlRow* row, /*@ out @*/ Recurrence* r )
|
||||
{
|
||||
recurrence_info_t recurrence_info;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( r != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( r != NULL );
|
||||
|
||||
recurrence_info.be = be;
|
||||
recurrence_info.pRecurrence = r;
|
||||
recurrence_info.pRecurrence = r;
|
||||
|
||||
gnc_sql_load_object( be, row, TABLE_NAME, &recurrence_info, col_table );
|
||||
}
|
||||
@ -256,85 +270,93 @@ gnc_sql_set_recurrences_from_db( GncSqlBackend* be, const GncGUID* guid )
|
||||
gchar* buf;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( guid != NULL, NULL );
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( guid != NULL, NULL );
|
||||
|
||||
(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 );
|
||||
g_free( 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 );
|
||||
g_free( buf );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
return result;
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
return result;
|
||||
}
|
||||
|
||||
/*@ null @*/ Recurrence*
|
||||
gnc_sql_recurrence_load( GncSqlBackend* be, const GncGUID* guid )
|
||||
{
|
||||
GncSqlResult* result;
|
||||
Recurrence* r = NULL;
|
||||
GncSqlResult* result;
|
||||
Recurrence* r = NULL;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( guid != NULL, NULL );
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( guid != NULL, NULL );
|
||||
|
||||
result = gnc_sql_set_recurrences_from_db( be, guid );
|
||||
if( result != NULL ) {
|
||||
result = gnc_sql_set_recurrences_from_db( be, guid );
|
||||
if ( result != NULL )
|
||||
{
|
||||
guint numRows = gnc_sql_result_get_num_rows( result );
|
||||
|
||||
if( numRows > 0 ) {
|
||||
if( numRows > 1 ) {
|
||||
g_warning( "More than 1 recurrence found: first one used" );
|
||||
}
|
||||
r = g_new0( Recurrence, 1 );
|
||||
g_assert( r != NULL );
|
||||
load_recurrence( be, gnc_sql_result_get_first_row( result ), r );
|
||||
} else {
|
||||
g_warning( "No recurrences found" );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
if ( numRows > 0 )
|
||||
{
|
||||
if ( numRows > 1 )
|
||||
{
|
||||
g_warning( "More than 1 recurrence found: first one used" );
|
||||
}
|
||||
r = g_new0( Recurrence, 1 );
|
||||
g_assert( r != NULL );
|
||||
load_recurrence( be, gnc_sql_result_get_first_row( result ), r );
|
||||
}
|
||||
else
|
||||
{
|
||||
g_warning( "No recurrences found" );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
|
||||
return r;
|
||||
return r;
|
||||
}
|
||||
|
||||
/*@ null @*/ GList*
|
||||
gnc_sql_recurrence_load_list( GncSqlBackend* be, const GncGUID* guid )
|
||||
{
|
||||
GncSqlResult* result;
|
||||
GList* list = NULL;
|
||||
GncSqlResult* result;
|
||||
GList* list = NULL;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( guid != NULL, NULL );
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( guid != NULL, NULL );
|
||||
|
||||
result = gnc_sql_set_recurrences_from_db( be, guid );
|
||||
if( result != NULL ) {
|
||||
result = gnc_sql_set_recurrences_from_db( be, guid );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
while( row != NULL ) {
|
||||
Recurrence* pRecurrence = g_new0( Recurrence, 1 );
|
||||
g_assert( pRecurrence != NULL );
|
||||
load_recurrence( be, row, pRecurrence );
|
||||
list = g_list_append( list, pRecurrence );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
while ( row != NULL )
|
||||
{
|
||||
Recurrence* pRecurrence = g_new0( Recurrence, 1 );
|
||||
g_assert( pRecurrence != NULL );
|
||||
load_recurrence( be, row, pRecurrence );
|
||||
list = g_list_append( list, pRecurrence );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
|
||||
return list;
|
||||
return list;
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
static void
|
||||
create_recurrence_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if ( version == 0 )
|
||||
{
|
||||
(void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
@ -350,10 +372,10 @@ gnc_sql_init_recurrence_handler( void )
|
||||
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 */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
(void)qof_object_register_backend( TABLE_NAME, GNC_SQL_BACKEND, &be_data );
|
||||
|
@ -57,10 +57,10 @@
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "guid", CT_GUID, 0, COL_NNUL|COL_PKEY, "guid" },
|
||||
/*@ -full_init_block @*/
|
||||
{ "guid", CT_GUID, 0, COL_NNUL | COL_PKEY, "guid" },
|
||||
{ "name", CT_STRING, SX_MAX_NAME_LEN, 0, "name" },
|
||||
{ "enabled", CT_BOOLEAN, 0, COL_NNUL, "enabled" },
|
||||
{ "enabled", CT_BOOLEAN, 0, COL_NNUL, "enabled" },
|
||||
{ "start_date", CT_GDATE, 0, 0, "start-date" },
|
||||
{ "end_date", CT_GDATE, 0, 0, "end-date" },
|
||||
{ "last_occur", CT_GDATE, 0, 0, "last-occurance-date" },
|
||||
@ -70,10 +70,10 @@ static const GncSqlColumnTableEntry col_table[] =
|
||||
{ "auto_notify", CT_BOOLEAN, 0, COL_NNUL, "auto-create-notify" },
|
||||
{ "adv_creation", CT_INT, 0, COL_NNUL, "advance-creation-days" },
|
||||
{ "adv_notify", CT_INT, 0, COL_NNUL, "advance-reminder-days" },
|
||||
{ "instance_count", CT_INT, 0, COL_NNUL, "instance-count" },
|
||||
{ "instance_count", CT_INT, 0, COL_NNUL, "instance-count" },
|
||||
{ "template_act_guid", CT_ACCOUNTREF, 0, COL_NNUL, "template-account" },
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -81,23 +81,23 @@ static /*@ null @*/ SchedXaction*
|
||||
load_single_sx( GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
const GncGUID* guid;
|
||||
SchedXaction* pSx;
|
||||
GList* schedule;
|
||||
GDate start_date;
|
||||
SchedXaction* pSx;
|
||||
GList* schedule;
|
||||
GDate start_date;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
guid = gnc_sql_load_guid( be, row );
|
||||
g_assert( guid != NULL );
|
||||
g_assert( guid != NULL );
|
||||
pSx = xaccSchedXactionMalloc( be->primary_book );
|
||||
|
||||
gnc_sx_begin_edit( pSx );
|
||||
gnc_sx_begin_edit( pSx );
|
||||
gnc_sql_load_object( be, row, GNC_SX_ID, pSx, col_table );
|
||||
schedule = gnc_sql_recurrence_load_list( be, guid );
|
||||
gnc_sx_set_schedule( pSx, schedule );
|
||||
gnc_sx_commit_edit( pSx );
|
||||
gnc_sql_transaction_load_tx_for_account( be, pSx->template_acct );
|
||||
schedule = gnc_sql_recurrence_load_list( be, guid );
|
||||
gnc_sx_set_schedule( pSx, schedule );
|
||||
gnc_sx_commit_edit( pSx );
|
||||
gnc_sql_transaction_load_tx_for_account( be, pSx->template_acct );
|
||||
|
||||
g_object_get(pSx, "start-date", &start_date, NULL);
|
||||
|
||||
@ -110,35 +110,39 @@ load_all_sxes( GncSqlBackend* be )
|
||||
GncSqlStatement* stmt = NULL;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
stmt = gnc_sql_create_select_statement( be, SCHEDXACTION_TABLE );
|
||||
if( stmt == NULL ) return;
|
||||
if ( stmt == NULL ) return;
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row;
|
||||
SchedXactions *sxes;
|
||||
GList* list = NULL;
|
||||
sxes = gnc_book_get_schedxactions( be->primary_book );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GncSqlRow* row;
|
||||
SchedXactions *sxes;
|
||||
GList* list = NULL;
|
||||
sxes = gnc_book_get_schedxactions( be->primary_book );
|
||||
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while( row != NULL ) {
|
||||
row = gnc_sql_result_get_first_row( result );
|
||||
while ( row != NULL )
|
||||
{
|
||||
SchedXaction* sx;
|
||||
|
||||
sx = load_single_sx( be, row );
|
||||
if( sx != NULL ) {
|
||||
gnc_sxes_add_sx( sxes, sx );
|
||||
list = g_list_prepend( list, sx );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
sx = load_single_sx( be, row );
|
||||
if ( sx != NULL )
|
||||
{
|
||||
gnc_sxes_add_sx( sxes, sx );
|
||||
list = g_list_prepend( list, sx );
|
||||
}
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
if( list != NULL ) {
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
g_list_free( list );
|
||||
}
|
||||
if ( list != NULL )
|
||||
{
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
g_list_free( list );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,12 +150,13 @@ load_all_sxes( GncSqlBackend* be )
|
||||
static void
|
||||
create_sx_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
gint version;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, SCHEDXACTION_TABLE );
|
||||
if( version == 0 ) {
|
||||
version = gnc_sql_get_table_version( be, SCHEDXACTION_TABLE );
|
||||
if ( version == 0 )
|
||||
{
|
||||
(void)gnc_sql_create_table( be, SCHEDXACTION_TABLE, TABLE_VERSION, col_table );
|
||||
}
|
||||
}
|
||||
@ -162,42 +167,54 @@ gnc_sql_save_schedxaction( GncSqlBackend* be, QofInstance* inst )
|
||||
{
|
||||
SchedXaction* pSx;
|
||||
const GncGUID* guid;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
gboolean is_ok;
|
||||
gint op;
|
||||
gboolean is_infant;
|
||||
gboolean is_ok;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_SX(inst), FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( inst != NULL, FALSE );
|
||||
g_return_val_if_fail( GNC_IS_SX(inst), FALSE );
|
||||
|
||||
pSx = GNC_SX(inst);
|
||||
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if( qof_instance_get_destroying( inst ) ) {
|
||||
op = OP_DB_DELETE;
|
||||
} else if( be->is_pristine_db || is_infant ) {
|
||||
op = OP_DB_INSERT;
|
||||
} else {
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
is_infant = qof_instance_get_infant( inst );
|
||||
if ( qof_instance_get_destroying( inst ) )
|
||||
{
|
||||
op = OP_DB_DELETE;
|
||||
}
|
||||
else if ( be->is_pristine_db || is_infant )
|
||||
{
|
||||
op = OP_DB_INSERT;
|
||||
}
|
||||
else
|
||||
{
|
||||
op = OP_DB_UPDATE;
|
||||
}
|
||||
is_ok = gnc_sql_do_db_operation( be, op, SCHEDXACTION_TABLE, GNC_SX_ID, pSx, col_table );
|
||||
guid = qof_instance_get_guid( inst );
|
||||
if( op == OP_DB_INSERT || op == OP_DB_UPDATE ) {
|
||||
gnc_sql_recurrence_save_list( be, guid, gnc_sx_get_schedule( pSx ) );
|
||||
} else {
|
||||
gnc_sql_recurrence_delete( be, guid );
|
||||
}
|
||||
if ( op == OP_DB_INSERT || op == OP_DB_UPDATE )
|
||||
{
|
||||
gnc_sql_recurrence_save_list( be, guid, gnc_sx_get_schedule( pSx ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
gnc_sql_recurrence_delete( be, guid );
|
||||
}
|
||||
|
||||
if( is_ok ) {
|
||||
// Now, commit any slots
|
||||
if( op == OP_DB_INSERT || op == OP_DB_UPDATE ) {
|
||||
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
} else {
|
||||
is_ok = gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
if ( is_ok )
|
||||
{
|
||||
// Now, commit any slots
|
||||
if ( op == OP_DB_INSERT || op == OP_DB_UPDATE )
|
||||
{
|
||||
is_ok = gnc_sql_slots_save( be, guid, is_infant, qof_instance_get_slots( inst ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
is_ok = gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
}
|
||||
|
||||
return is_ok;
|
||||
return is_ok;
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
@ -211,10 +228,10 @@ gnc_sql_init_schedxaction_handler( void )
|
||||
gnc_sql_save_schedxaction, /* commit */
|
||||
load_all_sxes, /* initial_load */
|
||||
create_sx_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
(void)qof_object_register_backend( GNC_ID_SCHEDXACTION, GNC_SQL_BACKEND, &be_data );
|
||||
|
@ -46,13 +46,17 @@
|
||||
#define TABLE_NAME "slots"
|
||||
#define TABLE_VERSION 2
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
/*@ dependent @*/ GncSqlBackend* be;
|
||||
/*@ dependent @*/ const GncGUID* guid;
|
||||
gboolean is_ok;
|
||||
/*@ dependent @*/ KvpFrame* pKvpFrame;
|
||||
/*@ dependent @*/
|
||||
const GncGUID* guid;
|
||||
gboolean is_ok;
|
||||
/*@ dependent @*/
|
||||
KvpFrame* pKvpFrame;
|
||||
KvpValueType value_type;
|
||||
/*@ dependent @*/ KvpValue* pKvpValue;
|
||||
/*@ dependent @*/
|
||||
KvpValue* pKvpValue;
|
||||
GString* path;
|
||||
} slot_info_t;
|
||||
|
||||
@ -80,38 +84,56 @@ static void set_numeric_val( gpointer pObject, gnc_numeric value );
|
||||
|
||||
static const GncSqlColumnTableEntry col_table[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
{ "id", CT_INT, 0, COL_PKEY|COL_NNUL|COL_AUTOINC },
|
||||
{ "obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_obj_guid, (QofSetterFunc)set_obj_guid },
|
||||
{ "name", CT_STRING, SLOT_MAX_PATHNAME_LEN, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_path, set_path },
|
||||
{ "slot_type", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_slot_type, set_slot_type, },
|
||||
{ "int64_val", CT_INT64, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_int64_val, (QofSetterFunc)set_int64_val },
|
||||
{ "string_val", CT_STRING, SLOT_MAX_PATHNAME_LEN, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_string_val, set_string_val },
|
||||
{ "double_val", CT_DOUBLE, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_double_val, set_double_val },
|
||||
{ "timespec_val", CT_TIMESPEC, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_timespec_val, (QofSetterFunc)set_timespec_val },
|
||||
{ "guid_val", CT_GUID, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_guid_val, set_guid_val },
|
||||
{ "numeric_val", CT_NUMERIC, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_numeric_val, (QofSetterFunc)set_numeric_val },
|
||||
/*@ -full_init_block @*/
|
||||
{ "id", CT_INT, 0, COL_PKEY | COL_NNUL | COL_AUTOINC },
|
||||
{
|
||||
"obj_guid", CT_GUID, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_obj_guid, (QofSetterFunc)set_obj_guid
|
||||
},
|
||||
{
|
||||
"name", CT_STRING, SLOT_MAX_PATHNAME_LEN, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_path, set_path
|
||||
},
|
||||
{
|
||||
"slot_type", CT_INT, 0, COL_NNUL, NULL, NULL,
|
||||
(QofAccessFunc)get_slot_type, set_slot_type,
|
||||
},
|
||||
{
|
||||
"int64_val", CT_INT64, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_int64_val, (QofSetterFunc)set_int64_val
|
||||
},
|
||||
{
|
||||
"string_val", CT_STRING, SLOT_MAX_PATHNAME_LEN, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_string_val, set_string_val
|
||||
},
|
||||
{
|
||||
"double_val", CT_DOUBLE, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_double_val, set_double_val
|
||||
},
|
||||
{
|
||||
"timespec_val", CT_TIMESPEC, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_timespec_val, (QofSetterFunc)set_timespec_val
|
||||
},
|
||||
{
|
||||
"guid_val", CT_GUID, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_guid_val, set_guid_val
|
||||
},
|
||||
{
|
||||
"numeric_val", CT_NUMERIC, 0, 0, NULL, NULL,
|
||||
(QofAccessFunc)get_numeric_val, (QofSetterFunc)set_numeric_val
|
||||
},
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
/* 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[] =
|
||||
{
|
||||
/*@ -full_init_block @*/
|
||||
/*@ -full_init_block @*/
|
||||
{ "obj_guid", CT_GUID, 0, 0, NULL, NULL, (QofAccessFunc)get_obj_guid, _retrieve_guid_ },
|
||||
{ NULL }
|
||||
/*@ +full_init_block @*/
|
||||
/*@ +full_init_block @*/
|
||||
};
|
||||
|
||||
/* ================================================================= */
|
||||
@ -121,7 +143,7 @@ get_obj_guid( gpointer pObject )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
return (gpointer)pInfo->guid;
|
||||
}
|
||||
@ -137,7 +159,7 @@ get_path( gpointer pObject )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
return (gpointer)pInfo->path->str;
|
||||
}
|
||||
@ -147,12 +169,13 @@ set_path( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
if( pInfo->path != NULL ) {
|
||||
(void)g_string_free( pInfo->path, TRUE );
|
||||
}
|
||||
if ( pInfo->path != NULL )
|
||||
{
|
||||
(void)g_string_free( pInfo->path, TRUE );
|
||||
}
|
||||
pInfo->path = g_string_new( (gchar*)pValue );
|
||||
}
|
||||
|
||||
@ -161,7 +184,7 @@ get_slot_type( gpointer pObject )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
return (gpointer)kvp_value_get_type( pInfo->pKvpValue );
|
||||
}
|
||||
@ -171,8 +194,8 @@ set_slot_type( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
pInfo->value_type = (KvpValueType)pValue;
|
||||
}
|
||||
@ -182,11 +205,14 @@ get_int64_val( gpointer pObject )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, 0 );
|
||||
g_return_val_if_fail( pObject != NULL, 0 );
|
||||
|
||||
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_GINT64 ) {
|
||||
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_GINT64 )
|
||||
{
|
||||
return kvp_value_get_gint64( pInfo->pKvpValue );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@ -196,9 +222,10 @@ set_int64_val( gpointer pObject, gint64 value )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_GINT64 ) {
|
||||
if ( pInfo->value_type == KVP_TYPE_GINT64 )
|
||||
{
|
||||
kvp_frame_set_gint64( pInfo->pKvpFrame, pInfo->path->str, value );
|
||||
}
|
||||
}
|
||||
@ -208,11 +235,14 @@ get_string_val( gpointer pObject )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_STRING ) {
|
||||
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_STRING )
|
||||
{
|
||||
return (gpointer)kvp_value_get_string( pInfo->pKvpValue );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -222,9 +252,10 @@ set_string_val( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_STRING && pValue != NULL ) {
|
||||
if ( pInfo->value_type == KVP_TYPE_STRING && pValue != NULL )
|
||||
{
|
||||
kvp_frame_set_string( pInfo->pKvpFrame, pInfo->path->str, (const gchar*)pValue );
|
||||
}
|
||||
}
|
||||
@ -235,12 +266,15 @@ get_double_val( gpointer pObject )
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
static double d_val;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_DOUBLE ) {
|
||||
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_DOUBLE )
|
||||
{
|
||||
d_val = kvp_value_get_double( pInfo->pKvpValue );
|
||||
return (gpointer)&d_val;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -250,9 +284,10 @@ set_double_val( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_DOUBLE && pValue != NULL ) {
|
||||
if ( pInfo->value_type == KVP_TYPE_DOUBLE && pValue != NULL )
|
||||
{
|
||||
kvp_frame_set_double( pInfo->pKvpFrame, pInfo->path->str, *(double*)pValue );
|
||||
}
|
||||
}
|
||||
@ -262,7 +297,7 @@ get_timespec_val( gpointer pObject )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, gnc_dmy2timespec( 1, 1, 1970 ) );
|
||||
g_return_val_if_fail( pObject != NULL, gnc_dmy2timespec( 1, 1, 1970 ) );
|
||||
|
||||
//if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_TIMESPEC ) {
|
||||
return kvp_value_get_timespec( pInfo->pKvpValue );
|
||||
@ -273,9 +308,10 @@ set_timespec_val( gpointer pObject, Timespec ts )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_TIMESPEC ) {
|
||||
if ( pInfo->value_type == KVP_TYPE_TIMESPEC )
|
||||
{
|
||||
kvp_frame_set_timespec( pInfo->pKvpFrame, pInfo->path->str, ts );
|
||||
}
|
||||
}
|
||||
@ -285,11 +321,14 @@ get_guid_val( gpointer pObject )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
|
||||
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_GUID ) {
|
||||
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_GUID )
|
||||
{
|
||||
return (gpointer)kvp_value_get_guid( pInfo->pKvpValue );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -299,9 +338,10 @@ set_guid_val( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_GUID && pValue != NULL ) {
|
||||
if ( pInfo->value_type == KVP_TYPE_GUID && pValue != NULL )
|
||||
{
|
||||
kvp_frame_set_guid( pInfo->pKvpFrame, pInfo->path->str, (GncGUID*)pValue );
|
||||
}
|
||||
}
|
||||
@ -311,11 +351,14 @@ get_numeric_val( gpointer pObject )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, gnc_numeric_zero() );
|
||||
g_return_val_if_fail( pObject != NULL, gnc_numeric_zero() );
|
||||
|
||||
if( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_NUMERIC ) {
|
||||
if ( kvp_value_get_type( pInfo->pKvpValue ) == KVP_TYPE_NUMERIC )
|
||||
{
|
||||
return kvp_value_get_numeric( pInfo->pKvpValue );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return gnc_numeric_zero();
|
||||
}
|
||||
}
|
||||
@ -325,9 +368,10 @@ set_numeric_val( gpointer pObject, gnc_numeric value )
|
||||
{
|
||||
slot_info_t* pInfo = (slot_info_t*)pObject;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
|
||||
if( pInfo->value_type == KVP_TYPE_NUMERIC ) {
|
||||
if ( pInfo->value_type == KVP_TYPE_NUMERIC )
|
||||
{
|
||||
kvp_frame_set_numeric( pInfo->pKvpFrame, pInfo->path->str, value );
|
||||
}
|
||||
}
|
||||
@ -338,30 +382,35 @@ save_slot( const gchar* key, KvpValue* value, gpointer data )
|
||||
slot_info_t* pSlot_info = (slot_info_t*)data;
|
||||
gsize curlen;
|
||||
|
||||
g_return_if_fail( key != NULL );
|
||||
g_return_if_fail( value != NULL );
|
||||
g_return_if_fail( data != NULL );
|
||||
g_return_if_fail( key != NULL );
|
||||
g_return_if_fail( value != NULL );
|
||||
g_return_if_fail( data != NULL );
|
||||
|
||||
// Ignore if we've already run into a failure
|
||||
if( !pSlot_info->is_ok ) {
|
||||
return;
|
||||
}
|
||||
// Ignore if we've already run into a failure
|
||||
if ( !pSlot_info->is_ok )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
curlen = pSlot_info->path->len;
|
||||
pSlot_info->pKvpValue = value;
|
||||
if( curlen != 0 ) {
|
||||
if ( curlen != 0 )
|
||||
{
|
||||
(void)g_string_append( pSlot_info->path, "/" );
|
||||
}
|
||||
(void)g_string_append( pSlot_info->path, key );
|
||||
|
||||
if( kvp_value_get_type( value ) == KVP_TYPE_FRAME ) {
|
||||
if ( kvp_value_get_type( value ) == KVP_TYPE_FRAME )
|
||||
{
|
||||
KvpFrame* pKvpFrame = kvp_value_get_frame( value );
|
||||
kvp_frame_for_each_slot( pKvpFrame, save_slot, pSlot_info );
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
|
||||
OP_DB_INSERT, TABLE_NAME,
|
||||
TABLE_NAME, pSlot_info,
|
||||
col_table );
|
||||
OP_DB_INSERT, TABLE_NAME,
|
||||
TABLE_NAME, pSlot_info,
|
||||
col_table );
|
||||
}
|
||||
|
||||
(void)g_string_truncate( pSlot_info->path, curlen );
|
||||
@ -372,23 +421,24 @@ gnc_sql_slots_save( GncSqlBackend* be, const GncGUID* guid, gboolean is_infant,
|
||||
{
|
||||
slot_info_t slot_info;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( guid != NULL, FALSE );
|
||||
g_return_val_if_fail( pFrame != NULL, FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( guid != NULL, FALSE );
|
||||
g_return_val_if_fail( pFrame != NULL, FALSE );
|
||||
|
||||
// If this is not saving into a new db, clear out the old saved slots first
|
||||
if( !be->is_pristine_db && !is_infant ) {
|
||||
(void)gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
if ( !be->is_pristine_db && !is_infant )
|
||||
{
|
||||
(void)gnc_sql_slots_delete( be, guid );
|
||||
}
|
||||
|
||||
slot_info.be = be;
|
||||
slot_info.guid = guid;
|
||||
slot_info.path = g_string_new( "" );
|
||||
slot_info.is_ok = TRUE;
|
||||
slot_info.is_ok = TRUE;
|
||||
kvp_frame_for_each_slot( pFrame, save_slot, &slot_info );
|
||||
(void)g_string_free( slot_info.path, TRUE );
|
||||
|
||||
return slot_info.is_ok;
|
||||
return slot_info.is_ok;
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -396,16 +446,16 @@ gnc_sql_slots_delete( GncSqlBackend* be, const GncGUID* guid )
|
||||
{
|
||||
slot_info_t slot_info;
|
||||
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( guid != NULL, FALSE );
|
||||
g_return_val_if_fail( be != NULL, FALSE );
|
||||
g_return_val_if_fail( guid != NULL, FALSE );
|
||||
|
||||
slot_info.be = be;
|
||||
slot_info.guid = guid;
|
||||
slot_info.is_ok = TRUE;
|
||||
slot_info.is_ok = TRUE;
|
||||
slot_info.is_ok = gnc_sql_do_db_operation( be, OP_DB_DELETE, TABLE_NAME,
|
||||
TABLE_NAME, &slot_info, obj_guid_col_table );
|
||||
TABLE_NAME, &slot_info, obj_guid_col_table );
|
||||
|
||||
return slot_info.is_ok;
|
||||
return slot_info.is_ok;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -413,9 +463,9 @@ load_slot( GncSqlBackend* be, GncSqlRow* row, KvpFrame* pFrame )
|
||||
{
|
||||
slot_info_t slot_info;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pFrame != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( pFrame != NULL );
|
||||
|
||||
slot_info.be = be;
|
||||
slot_info.pKvpFrame = pFrame;
|
||||
@ -423,7 +473,8 @@ 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 ) {
|
||||
if ( slot_info.path != NULL )
|
||||
{
|
||||
(void)g_string_free( slot_info.path, TRUE );
|
||||
}
|
||||
}
|
||||
@ -435,32 +486,35 @@ gnc_sql_slots_load( GncSqlBackend* be, QofInstance* inst )
|
||||
GncSqlResult* result;
|
||||
gchar guid_buf[GUID_ENCODING_LENGTH+1];
|
||||
GncSqlStatement* stmt;
|
||||
const GncGUID* guid;
|
||||
KvpFrame* pFrame;
|
||||
const GncGUID* guid;
|
||||
KvpFrame* pFrame;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( inst != 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 = qof_instance_get_guid( inst );
|
||||
pFrame = qof_instance_get_slots( inst );
|
||||
(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_create_statement_from_sql( be, buf );
|
||||
g_free( buf );
|
||||
if( stmt != NULL ) {
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
buf = g_strdup_printf( "SELECT * FROM %s WHERE obj_guid='%s'", TABLE_NAME, guid_buf );
|
||||
stmt = gnc_sql_create_statement_from_sql( be, buf );
|
||||
g_free( buf );
|
||||
if ( stmt != NULL )
|
||||
{
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
while( row != NULL ) {
|
||||
load_slot( be, row, pFrame );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
while ( row != NULL )
|
||||
{
|
||||
load_slot( be, row, pFrame );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static /*@ dependent @*//*@ null @*/ const GncGUID*
|
||||
@ -468,8 +522,8 @@ load_obj_guid( const GncSqlBackend* be, GncSqlRow* row )
|
||||
{
|
||||
static GncGUID guid;
|
||||
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
g_return_val_if_fail( be != NULL, NULL );
|
||||
g_return_val_if_fail( row != NULL, NULL );
|
||||
|
||||
gnc_sql_load_object( be, row, NULL, &guid, obj_guid_col_table );
|
||||
|
||||
@ -480,16 +534,16 @@ static void
|
||||
load_slot_for_list_item( GncSqlBackend* be, GncSqlRow* row, QofCollection* coll )
|
||||
{
|
||||
slot_info_t slot_info;
|
||||
const GncGUID* guid;
|
||||
QofInstance* inst;
|
||||
const GncGUID* guid;
|
||||
QofInstance* inst;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( coll != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( coll != NULL );
|
||||
|
||||
guid = load_obj_guid( be, row );
|
||||
g_assert( guid != NULL );
|
||||
inst = qof_collection_lookup_entity( coll, guid );
|
||||
guid = load_obj_guid( be, row );
|
||||
g_assert( guid != NULL );
|
||||
inst = qof_collection_lookup_entity( coll, guid );
|
||||
|
||||
slot_info.be = be;
|
||||
slot_info.pKvpFrame = qof_instance_get_slots( inst );
|
||||
@ -497,7 +551,8 @@ 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 ) {
|
||||
if ( slot_info.path != NULL )
|
||||
{
|
||||
(void)g_string_free( slot_info.path, TRUE );
|
||||
}
|
||||
}
|
||||
@ -505,52 +560,59 @@ load_slot_for_list_item( GncSqlBackend* be, GncSqlRow* row, QofCollection* coll
|
||||
void
|
||||
gnc_sql_slots_load_for_list( GncSqlBackend* be, GList* list )
|
||||
{
|
||||
QofCollection* coll;
|
||||
GncSqlStatement* stmt;
|
||||
GString* sql;
|
||||
GncSqlResult* result;
|
||||
gboolean single_item;
|
||||
QofCollection* coll;
|
||||
GncSqlStatement* stmt;
|
||||
GString* sql;
|
||||
GncSqlResult* result;
|
||||
gboolean single_item;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
// Ignore empty list
|
||||
if( list == NULL ) return;
|
||||
// Ignore empty list
|
||||
if ( list == NULL ) return;
|
||||
|
||||
coll = qof_instance_get_collection( QOF_INSTANCE(list->data) );
|
||||
coll = qof_instance_get_collection( QOF_INSTANCE(list->data) );
|
||||
|
||||
// Create the query for all slots for all items on the 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 ) {
|
||||
(void)g_string_append( sql, "IN (" );
|
||||
single_item = FALSE;
|
||||
} else {
|
||||
(void)g_string_append( sql, "= " );
|
||||
single_item = TRUE;
|
||||
}
|
||||
(void)gnc_sql_append_guid_list_to_sql( sql, list, G_MAXUINT );
|
||||
if( !single_item ) {
|
||||
(void)g_string_append( sql, ")" );
|
||||
}
|
||||
// Create the query for all slots for all items on the 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 )
|
||||
{
|
||||
(void)g_string_append( sql, "IN (" );
|
||||
single_item = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)g_string_append( sql, "= " );
|
||||
single_item = TRUE;
|
||||
}
|
||||
(void)gnc_sql_append_guid_list_to_sql( sql, list, G_MAXUINT );
|
||||
if ( !single_item )
|
||||
{
|
||||
(void)g_string_append( sql, ")" );
|
||||
}
|
||||
|
||||
// Execute the query and load the slots
|
||||
stmt = gnc_sql_create_statement_from_sql( be, sql->str );
|
||||
if( stmt == NULL ) {
|
||||
PERR( "stmt == NULL, SQL = '%s'\n", sql->str );
|
||||
(void)g_string_free( sql, TRUE );
|
||||
return;
|
||||
}
|
||||
(void)g_string_free( sql, TRUE );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
// Execute the query and load the slots
|
||||
stmt = gnc_sql_create_statement_from_sql( be, sql->str );
|
||||
if ( stmt == NULL )
|
||||
{
|
||||
PERR( "stmt == NULL, SQL = '%s'\n", sql->str );
|
||||
(void)g_string_free( sql, TRUE );
|
||||
return;
|
||||
}
|
||||
(void)g_string_free( sql, TRUE );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
while( row != NULL ) {
|
||||
while ( row != NULL )
|
||||
{
|
||||
load_slot_for_list_item( be, row, coll );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
|
||||
@ -558,17 +620,17 @@ static void
|
||||
load_slot_for_book_object( GncSqlBackend* be, GncSqlRow* row, BookLookupFn lookup_fn )
|
||||
{
|
||||
slot_info_t slot_info;
|
||||
const GncGUID* guid;
|
||||
QofInstance* inst;
|
||||
const GncGUID* guid;
|
||||
QofInstance* inst;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( lookup_fn != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( row != NULL );
|
||||
g_return_if_fail( lookup_fn != NULL );
|
||||
|
||||
guid = load_obj_guid( be, row );
|
||||
g_return_if_fail( guid != NULL );
|
||||
inst = lookup_fn( guid, be->primary_book );
|
||||
g_return_if_fail( inst != NULL );
|
||||
guid = load_obj_guid( be, row );
|
||||
g_return_if_fail( guid != NULL );
|
||||
inst = lookup_fn( guid, be->primary_book );
|
||||
g_return_if_fail( inst != NULL );
|
||||
|
||||
slot_info.be = be;
|
||||
slot_info.pKvpFrame = qof_instance_get_slots( inst );
|
||||
@ -576,7 +638,8 @@ load_slot_for_book_object( GncSqlBackend* be, GncSqlRow* row, BookLookupFn looku
|
||||
|
||||
gnc_sql_load_object( be, row, TABLE_NAME, &slot_info, col_table );
|
||||
|
||||
if( slot_info.path != NULL ) {
|
||||
if ( slot_info.path != NULL )
|
||||
{
|
||||
(void)g_string_free( slot_info.path, TRUE );
|
||||
}
|
||||
}
|
||||
@ -591,39 +654,42 @@ load_slot_for_book_object( GncSqlBackend* be, GncSqlRow* row, BookLookupFn looku
|
||||
* @param lookup_fn Lookup function
|
||||
*/
|
||||
void gnc_sql_slots_load_for_sql_subquery( GncSqlBackend* be, const gchar* subquery,
|
||||
BookLookupFn lookup_fn )
|
||||
BookLookupFn lookup_fn )
|
||||
{
|
||||
gchar* sql;
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
gchar* sql;
|
||||
GncSqlStatement* stmt;
|
||||
GncSqlResult* result;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
// Ignore empty subquery
|
||||
if( subquery == NULL ) return;
|
||||
// Ignore empty subquery
|
||||
if ( subquery == NULL ) return;
|
||||
|
||||
sql = g_strdup_printf( "SELECT * FROM %s WHERE %s IN (%s)",
|
||||
TABLE_NAME, obj_guid_col_table[0].col_name,
|
||||
subquery );
|
||||
sql = g_strdup_printf( "SELECT * FROM %s WHERE %s IN (%s)",
|
||||
TABLE_NAME, obj_guid_col_table[0].col_name,
|
||||
subquery );
|
||||
|
||||
// Execute the query and load the slots
|
||||
stmt = gnc_sql_create_statement_from_sql( be, sql );
|
||||
if( stmt == NULL ) {
|
||||
PERR( "stmt == NULL, SQL = '%s'\n", sql );
|
||||
g_free( sql );
|
||||
return;
|
||||
}
|
||||
g_free( sql );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if( result != NULL ) {
|
||||
// Execute the query and load the slots
|
||||
stmt = gnc_sql_create_statement_from_sql( be, sql );
|
||||
if ( stmt == NULL )
|
||||
{
|
||||
PERR( "stmt == NULL, SQL = '%s'\n", sql );
|
||||
g_free( sql );
|
||||
return;
|
||||
}
|
||||
g_free( sql );
|
||||
result = gnc_sql_execute_select_statement( be, stmt );
|
||||
gnc_sql_statement_dispose( stmt );
|
||||
if ( result != NULL )
|
||||
{
|
||||
GncSqlRow* row = gnc_sql_result_get_first_row( result );
|
||||
|
||||
while( row != NULL ) {
|
||||
while ( row != NULL )
|
||||
{
|
||||
load_slot_for_book_object( be, row, lookup_fn );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
row = gnc_sql_result_get_next_row( result );
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
gnc_sql_result_dispose( result );
|
||||
}
|
||||
}
|
||||
|
||||
@ -631,28 +697,33 @@ void gnc_sql_slots_load_for_sql_subquery( GncSqlBackend* be, const gchar* subque
|
||||
static void
|
||||
create_slots_tables( GncSqlBackend* be )
|
||||
{
|
||||
gint version;
|
||||
gboolean ok;
|
||||
gint version;
|
||||
gboolean ok;
|
||||
|
||||
g_return_if_fail( be != NULL );
|
||||
g_return_if_fail( be != NULL );
|
||||
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if( version == 0 ) {
|
||||
(void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
version = gnc_sql_get_table_version( be, TABLE_NAME );
|
||||
if ( version == 0 )
|
||||
{
|
||||
(void)gnc_sql_create_table( be, TABLE_NAME, TABLE_VERSION, col_table );
|
||||
|
||||
ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table );
|
||||
if( !ok ) {
|
||||
PERR( "Unable to create index\n" );
|
||||
}
|
||||
} else if( version == 1 ) {
|
||||
/* Upgrade 64-bit int values to proper definition */
|
||||
gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
|
||||
ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table );
|
||||
if( !ok ) {
|
||||
PERR( "Unable to create index\n" );
|
||||
}
|
||||
(void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
|
||||
}
|
||||
ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table );
|
||||
if ( !ok )
|
||||
{
|
||||
PERR( "Unable to create index\n" );
|
||||
}
|
||||
}
|
||||
else if ( version == 1 )
|
||||
{
|
||||
/* Upgrade 64-bit int values to proper definition */
|
||||
gnc_sql_upgrade_table( be, TABLE_NAME, col_table );
|
||||
ok = gnc_sql_create_index( be, "slots_guid_index", TABLE_NAME, obj_guid_col_table );
|
||||
if ( !ok )
|
||||
{
|
||||
PERR( "Unable to create index\n" );
|
||||
}
|
||||
(void)gnc_sql_set_table_version( be, TABLE_NAME, TABLE_VERSION );
|
||||
}
|
||||
}
|
||||
|
||||
/* ================================================================= */
|
||||
@ -666,10 +737,10 @@ gnc_sql_init_slots_handler( void )
|
||||
NULL, /* commit - cannot occur */
|
||||
NULL, /* initial_load - cannot occur */
|
||||
create_slots_tables, /* create_tables */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
NULL, /* compile_query */
|
||||
NULL, /* run_query */
|
||||
NULL, /* free_query */
|
||||
NULL /* write */
|
||||
};
|
||||
|
||||
(void)qof_object_register_backend( TABLE_NAME, GNC_SQL_BACKEND, &be_data );
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -95,9 +95,10 @@ static GncSqlColumnTableEntry billterm_parent_col_table[] =
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
/*@ dependent @*/ GncBillTerm* billterm;
|
||||
GncGUID guid;
|
||||
typedef struct
|
||||
{
|
||||
/*@ dependent @*/ GncBillTerm* billterm;
|
||||
GncGUID guid;
|
||||
gboolean have_guid;
|
||||
} billterm_parent_guid_struct;
|
||||
|
||||
@ -121,14 +122,17 @@ bt_get_parent( gpointer pObject )
|
||||
const GncBillTerm* pParent;
|
||||
const GncGUID* parent_guid;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_BILLTERM(pObject), NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_BILLTERM(pObject), NULL );
|
||||
|
||||
billterm = GNC_BILLTERM(pObject);
|
||||
pParent = gncBillTermGetParent( billterm );
|
||||
if( pParent == NULL ) {
|
||||
if ( pParent == NULL )
|
||||
{
|
||||
parent_guid = NULL;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
|
||||
}
|
||||
|
||||
@ -151,7 +155,8 @@ bt_set_parent( gpointer data, gpointer value )
|
||||
if ( guid != NULL )
|
||||
{
|
||||
parent = gncBillTermLookup( pBook, guid );
|
||||
if( parent != NULL ) {
|
||||
if ( parent != NULL )
|
||||
{
|
||||
gncBillTermSetParent( billterm, parent );
|
||||
gncBillTermSetChild( parent, billterm );
|
||||
}
|
||||
@ -161,19 +166,19 @@ bt_set_parent( gpointer data, gpointer value )
|
||||
static void
|
||||
bt_set_parent_guid( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
{
|
||||
billterm_parent_guid_struct* s = (billterm_parent_guid_struct*)pObject;
|
||||
billterm_parent_guid_struct* s = (billterm_parent_guid_struct*)pObject;
|
||||
GncGUID* guid = (GncGUID*)pValue;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
s->guid = *guid;
|
||||
s->guid = *guid;
|
||||
s->have_guid = TRUE;
|
||||
}
|
||||
|
||||
static GncBillTerm*
|
||||
load_single_billterm( GncSqlBackend* be, GncSqlRow* row,
|
||||
GList** l_billterms_needing_parents )
|
||||
GList** l_billterms_needing_parents )
|
||||
{
|
||||
const GncGUID* guid;
|
||||
GncBillTerm* pBillTerm;
|
||||
@ -194,15 +199,15 @@ load_single_billterm( GncSqlBackend* be, GncSqlRow* row,
|
||||
GncGUID so that after they are all loaded, the parents can be fixed up. */
|
||||
if ( gncBillTermGetParent( pBillTerm ) == NULL )
|
||||
{
|
||||
billterm_parent_guid_struct* s = g_malloc( (gsize)sizeof(billterm_parent_guid_struct) );
|
||||
g_assert( s != NULL );
|
||||
billterm_parent_guid_struct* s = g_malloc( (gsize)sizeof(billterm_parent_guid_struct) );
|
||||
g_assert( s != NULL );
|
||||
|
||||
s->billterm = pBillTerm;
|
||||
s->billterm = pBillTerm;
|
||||
s->have_guid = FALSE;
|
||||
gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, s, billterm_parent_col_table );
|
||||
gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, s, billterm_parent_col_table );
|
||||
if ( s->have_guid )
|
||||
{
|
||||
*l_billterms_needing_parents = g_list_prepend( *l_billterms_needing_parents, s );
|
||||
*l_billterms_needing_parents = g_list_prepend( *l_billterms_needing_parents, s );
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -252,26 +257,29 @@ load_all_billterms( GncSqlBackend* be )
|
||||
gnc_sql_slots_load_for_list( be, list );
|
||||
}
|
||||
|
||||
/* While there are items on the list of billterms needing parents,
|
||||
try to see if the parent has now been loaded. Theory says that if
|
||||
items are removed from the front and added to the back if the
|
||||
parent is still not available, then eventually, the list will
|
||||
shrink to size 0. */
|
||||
if( l_billterms_needing_parents != NULL ) {
|
||||
gboolean progress_made = TRUE;
|
||||
/* While there are items on the list of billterms needing parents,
|
||||
try to see if the parent has now been loaded. Theory says that if
|
||||
items are removed from the front and added to the back if the
|
||||
parent is still not available, then eventually, the list will
|
||||
shrink to size 0. */
|
||||
if ( l_billterms_needing_parents != NULL )
|
||||
{
|
||||
gboolean progress_made = TRUE;
|
||||
GncTaxTable* root;
|
||||
Account* pParent;
|
||||
GList* elem;
|
||||
Account* pParent;
|
||||
GList* elem;
|
||||
|
||||
while( progress_made ) {
|
||||
progress_made = FALSE;
|
||||
for( elem = l_billterms_needing_parents; elem != NULL; elem = g_list_next( elem ) ) {
|
||||
billterm_parent_guid_struct* s = (billterm_parent_guid_struct*)elem->data;
|
||||
while ( progress_made )
|
||||
{
|
||||
progress_made = FALSE;
|
||||
for ( elem = l_billterms_needing_parents; elem != NULL; elem = g_list_next( elem ) )
|
||||
{
|
||||
billterm_parent_guid_struct* s = (billterm_parent_guid_struct*)elem->data;
|
||||
bt_set_parent( s->billterm, &s->guid );
|
||||
l_billterms_needing_parents = g_list_delete_link( l_billterms_needing_parents, elem );
|
||||
progress_made = TRUE;
|
||||
}
|
||||
}
|
||||
l_billterms_needing_parents = g_list_delete_link( l_billterms_needing_parents, elem );
|
||||
progress_made = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,9 +121,10 @@ static GncSqlColumnTableEntry guid_col_table[] =
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
/*@ dependent @*/ GncTaxTable* tt;
|
||||
GncGUID guid;
|
||||
typedef struct
|
||||
{
|
||||
/*@ dependent @*/ GncTaxTable* tt;
|
||||
GncGUID guid;
|
||||
gboolean have_guid;
|
||||
} taxtable_parent_guid_struct;
|
||||
|
||||
@ -175,14 +176,17 @@ bt_get_parent( gpointer pObject )
|
||||
const GncTaxTable* pParent;
|
||||
const GncGUID* parent_guid;
|
||||
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );
|
||||
g_return_val_if_fail( pObject != NULL, NULL );
|
||||
g_return_val_if_fail( GNC_IS_TAXTABLE(pObject), NULL );
|
||||
|
||||
tt = GNC_TAXTABLE(pObject);
|
||||
pParent = gncTaxTableGetParent( tt );
|
||||
if( pParent == NULL ) {
|
||||
if ( pParent == NULL )
|
||||
{
|
||||
parent_guid = NULL;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
parent_guid = qof_instance_get_guid( QOF_INSTANCE(pParent) );
|
||||
}
|
||||
|
||||
@ -205,7 +209,8 @@ tt_set_parent( gpointer data, gpointer value )
|
||||
if ( guid != NULL )
|
||||
{
|
||||
parent = gncTaxTableLookup( pBook, guid );
|
||||
if( parent != NULL ) {
|
||||
if ( parent != NULL )
|
||||
{
|
||||
gncTaxTableSetParent( tt, parent );
|
||||
gncTaxTableSetChild( parent, tt );
|
||||
}
|
||||
@ -215,13 +220,13 @@ tt_set_parent( gpointer data, gpointer value )
|
||||
static void
|
||||
tt_set_parent_guid( gpointer pObject, /*@ null @*/ gpointer pValue )
|
||||
{
|
||||
taxtable_parent_guid_struct* s = (taxtable_parent_guid_struct*)pObject;
|
||||
taxtable_parent_guid_struct* s = (taxtable_parent_guid_struct*)pObject;
|
||||
GncGUID* guid = (GncGUID*)pValue;
|
||||
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
g_return_if_fail( pObject != NULL );
|
||||
g_return_if_fail( pValue != NULL );
|
||||
|
||||
s->guid = *guid;
|
||||
s->guid = *guid;
|
||||
s->have_guid = TRUE;
|
||||
}
|
||||
|
||||
@ -276,7 +281,7 @@ load_taxtable_entries( GncSqlBackend* be, GncTaxTable* tt )
|
||||
|
||||
static void
|
||||
load_single_taxtable( GncSqlBackend* be, GncSqlRow* row,
|
||||
GList** l_tt_needing_parents )
|
||||
GList** l_tt_needing_parents )
|
||||
{
|
||||
const GncGUID* guid;
|
||||
GncTaxTable* tt;
|
||||
@ -297,16 +302,20 @@ load_single_taxtable( GncSqlBackend* be, GncSqlRow* row,
|
||||
/* If the tax table doesn't have a parent, it might be because it hasn't been loaded yet.
|
||||
If so, add this tax table to the list of tax tables with no parent, along with the parent
|
||||
GncGUID so that after they are all loaded, the parents can be fixed up. */
|
||||
if( gncTaxTableGetParent( tt ) == NULL ) {
|
||||
taxtable_parent_guid_struct* s = g_malloc( (gsize)sizeof(taxtable_parent_guid_struct) );
|
||||
g_assert( s != NULL );
|
||||
if ( gncTaxTableGetParent( tt ) == NULL )
|
||||
{
|
||||
taxtable_parent_guid_struct* s = g_malloc( (gsize)sizeof(taxtable_parent_guid_struct) );
|
||||
g_assert( s != NULL );
|
||||
|
||||
s->tt = tt;
|
||||
s->tt = tt;
|
||||
s->have_guid = FALSE;
|
||||
gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, s, tt_parent_col_table );
|
||||
if( s->have_guid ) {
|
||||
*l_tt_needing_parents = g_list_prepend( *l_tt_needing_parents, s );
|
||||
} else {
|
||||
gnc_sql_load_object( be, row, GNC_ID_TAXTABLE, s, tt_parent_col_table );
|
||||
if ( s->have_guid )
|
||||
{
|
||||
*l_tt_needing_parents = g_list_prepend( *l_tt_needing_parents, s );
|
||||
}
|
||||
else
|
||||
{
|
||||
g_free( s );
|
||||
}
|
||||
}
|
||||
@ -339,26 +348,29 @@ load_all_taxtables( GncSqlBackend* be )
|
||||
}
|
||||
gnc_sql_result_dispose( result );
|
||||
|
||||
/* While there are items on the list of taxtables needing parents,
|
||||
try to see if the parent has now been loaded. Theory says that if
|
||||
items are removed from the front and added to the back if the
|
||||
parent is still not available, then eventually, the list will
|
||||
shrink to size 0. */
|
||||
if( tt_needing_parents != NULL ) {
|
||||
gboolean progress_made = TRUE;
|
||||
/* While there are items on the list of taxtables needing parents,
|
||||
try to see if the parent has now been loaded. Theory says that if
|
||||
items are removed from the front and added to the back if the
|
||||
parent is still not available, then eventually, the list will
|
||||
shrink to size 0. */
|
||||
if ( tt_needing_parents != NULL )
|
||||
{
|
||||
gboolean progress_made = TRUE;
|
||||
GncTaxTable* root;
|
||||
Account* pParent;
|
||||
GList* elem;
|
||||
Account* pParent;
|
||||
GList* elem;
|
||||
|
||||
while( progress_made ) {
|
||||
progress_made = FALSE;
|
||||
for( elem = tt_needing_parents; elem != NULL; elem = g_list_next( elem ) ) {
|
||||
taxtable_parent_guid_struct* s = (taxtable_parent_guid_struct*)elem->data;
|
||||
while ( progress_made )
|
||||
{
|
||||
progress_made = FALSE;
|
||||
for ( elem = tt_needing_parents; elem != NULL; elem = g_list_next( elem ) )
|
||||
{
|
||||
taxtable_parent_guid_struct* s = (taxtable_parent_guid_struct*)elem->data;
|
||||
tt_set_parent( s->tt, &s->guid );
|
||||
tt_needing_parents = g_list_delete_link( tt_needing_parents, elem );
|
||||
progress_made = TRUE;
|
||||
}
|
||||
}
|
||||
tt_needing_parents = g_list_delete_link( tt_needing_parents, elem );
|
||||
progress_made = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,20 +106,20 @@ static const gchar* fixed_load_order[] =
|
||||
static void
|
||||
init_business_sql(void)
|
||||
{
|
||||
/* Initialize our pointers into the backend subsystem */
|
||||
gnc_address_sql_initialize();
|
||||
gnc_billterm_sql_initialize();
|
||||
gnc_customer_sql_initialize();
|
||||
gnc_employee_sql_initialize();
|
||||
gnc_entry_sql_initialize();
|
||||
gnc_invoice_sql_initialize();
|
||||
gnc_job_sql_initialize();
|
||||
gnc_order_sql_initialize();
|
||||
gnc_owner_sql_initialize();
|
||||
gnc_taxtable_sql_initialize();
|
||||
gnc_vendor_sql_initialize();
|
||||
/* Initialize our pointers into the backend subsystem */
|
||||
gnc_address_sql_initialize();
|
||||
gnc_billterm_sql_initialize();
|
||||
gnc_customer_sql_initialize();
|
||||
gnc_employee_sql_initialize();
|
||||
gnc_entry_sql_initialize();
|
||||
gnc_invoice_sql_initialize();
|
||||
gnc_job_sql_initialize();
|
||||
gnc_order_sql_initialize();
|
||||
gnc_owner_sql_initialize();
|
||||
gnc_taxtable_sql_initialize();
|
||||
gnc_vendor_sql_initialize();
|
||||
|
||||
gnc_sql_set_load_order( fixed_load_order );
|
||||
gnc_sql_set_load_order( fixed_load_order );
|
||||
}
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
@ -138,7 +138,7 @@ int main (int argc, char ** argv)
|
||||
filename = tempnam( "/tmp", "test-sqlite3-" );
|
||||
printf( "Using filename: %s\n", filename );
|
||||
test_dbi_business_store_and_reload( "sqlite3", session_1, filename );
|
||||
#if 0
|
||||
#if 0
|
||||
printf( "TEST_MYSQL_URL='%s'\n", TEST_MYSQL_URL );
|
||||
if ( strlen( TEST_MYSQL_URL ) > 0 )
|
||||
{
|
||||
@ -151,7 +151,7 @@ int main (int argc, char ** argv)
|
||||
session_1 = create_session();
|
||||
test_dbi_store_and_reload( "pgsql", session_1, TEST_PGSQL_URL );
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
print_test_results();
|
||||
qof_close();
|
||||
exit(get_rv());
|
||||
|
Loading…
Reference in New Issue
Block a user