r17919 - gnucash/trunk/src/backend/sql - Rest of r17916 commit (sigh) - gnc_sql_transaction_load_tx_for_account() function
Phil Longstaff
plongstaff at cvs.gnucash.org
Sun Feb 15 09:11:55 EST 2009
Author: plongstaff
Date: 2009-02-15 09:11:54 -0500 (Sun, 15 Feb 2009)
New Revision: 17919
Trac: http://svn.gnucash.org/trac/changeset/17919
Modified:
gnucash/trunk/src/backend/sql/gnc-transaction-sql.c
gnucash/trunk/src/backend/sql/gnc-transaction-sql.h
Log:
Rest of r17916 commit (sigh) - gnc_sql_transaction_load_tx_for_account() function
Modified: gnucash/trunk/src/backend/sql/gnc-transaction-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-transaction-sql.c 2009-02-15 00:40:24 UTC (rev 17918)
+++ gnucash/trunk/src/backend/sql/gnc-transaction-sql.c 2009-02-15 14:11:54 UTC (rev 17919)
@@ -706,7 +706,7 @@
g_return_val_if_fail( inst != NULL, FALSE );
g_return_val_if_fail( GNC_IS_TRANS(inst), FALSE );
- return save_transaction( be, GNC_TRANS(inst), TRUE );
+ return save_transaction( be, GNC_TRANS(inst), /* do_save_splits */TRUE );
}
static gboolean
@@ -716,7 +716,7 @@
g_return_val_if_fail( inst != NULL, FALSE );
g_return_val_if_fail( GNC_IS_TRANS(inst), FALSE );
- return save_transaction( be, GNC_TRANS(inst), FALSE );
+ return save_transaction( be, GNC_TRANS(inst), /* do_save_splits */FALSE );
}
/* ================================================================= */
@@ -748,6 +748,57 @@
}
}
+/**
+ * Loads all transactions for an account.
+ *
+ * @param be SQL backend
+ * @param account Account
+ */
+void gnc_sql_transaction_load_tx_for_account( GncSqlBackend* be, Account* account )
+{
+ const GUID* guid;
+ gchar guid_buf[GUID_ENCODING_LENGTH+1];
+ gchar* subquery_sql;
+ gchar* query_sql;
+ GncSqlStatement* stmt;
+
+ g_return_if_fail( be != NULL );
+ g_return_if_fail( account != NULL );
+
+ guid = qof_instance_get_guid( QOF_INSTANCE(account) );
+ guid_to_string_buff( guid, guid_buf );
+ subquery_sql = g_strdup_printf( "SELECT DISTINCT tx_guid FROM %s WHERE account_guid='%s'", SPLIT_TABLE, guid_buf );
+ query_sql = g_strdup_printf( "SELECT * FROM %s WHERE guid IN (%s)", TRANSACTION_TABLE, subquery_sql );
+ g_free( subquery_sql );
+ stmt = gnc_sql_create_statement_from_sql( be, query_sql );
+ query_transactions( be, stmt );
+ gnc_sql_statement_dispose( stmt );
+}
+
+static void
+load_all_tx_helper( Account* a, gpointer data )
+{
+ GncSqlBackend* be = (GncSqlBackend*)data;
+
+ gnc_sql_transaction_load_tx_for_account( be, a );
+}
+
+/**
+ * Loads all transactions. This might be used during a save-as operation to ensure that
+ * all data is in memory and ready to be saved.
+ *
+ * @param be SQL backend
+ */
+void gnc_sql_transaction_load_all_tx( GncSqlBackend* be )
+{
+ Account* root;
+
+ g_return_if_fail( be != NULL );
+
+ root = gnc_book_get_root_account( be->primary_book );
+ gnc_account_foreach_descendant( root, load_all_tx_helper, be );
+}
+
typedef struct {
GncSqlStatement* stmt;
Account* acct;
Modified: gnucash/trunk/src/backend/sql/gnc-transaction-sql.h
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-transaction-sql.h 2009-02-15 00:40:24 UTC (rev 17918)
+++ gnucash/trunk/src/backend/sql/gnc-transaction-sql.h 2009-02-15 14:11:54 UTC (rev 17919)
@@ -33,9 +33,39 @@
#include <gmodule.h>
void gnc_sql_init_transaction_handler( void );
+
+/**
+ * Commits all of the splits for a transaction.
+ *
+ * @param be SQL backend
+ * @param pTx Transaction
+ */
void gnc_sql_transaction_commit_splits( GncSqlBackend* be, Transaction* pTx );
+
+/**
+ * Saves a transaction to the db.
+ *
+ * @param be SQL backend
+ * @param inst Transaction instance
+ * @return TRUE if successful, FALSE if unsuccessful
+ */
gboolean gnc_sql_save_transaction( GncSqlBackend* be, QofInstance* inst );
+/**
+ * Loads all transactions which have splits for a specific account.
+ *
+ * @param be SQL backend
+ * @param account Account
+ */
+void gnc_sql_transaction_load_tx_for_account( GncSqlBackend* be, Account* account );
+
+/**
+ * Loads all transactions.
+ *
+ * @param be SQL backend
+ */
+void gnc_sql_transaction_load_all_tx( GncSqlBackend* be );
+
typedef struct {
Account* acct;
gnc_numeric balance;
@@ -46,6 +76,9 @@
/**
* Returns a list of acct_balances_t structures, one for each account which
* has splits.
+ *
+ * @param be SQL backend
+ * @return GSList of acct_balances_t structures
*/
GSList* gnc_sql_get_account_balances_slist( GncSqlBackend* be );
More information about the gnucash-changes
mailing list