Fix gncSubtotalReconedBalance.

Fix checkpointing bug.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5783 57a11ea4-9604-0410-9ed3-97b8803252fd
zzzoldfeatures/g2-gog-integ
Dave Peticolas 25 years ago
parent 96254db7a0
commit 39be40a38a

@ -389,8 +389,7 @@ pgendFillOutToCheckpoint (PGBackend *be, const char *query_string)
pgendCopySplitsToEngine (be, trans);
}
#if 1
/* hack alert !! deal with kvp later -- huge sucking sound ! */
/* hack alert !! deal with kvp later -- huge sucking sound ! */
/* restore any kvp data associated with the transaction and splits */
for (node=xaction_list; node; node=node->next)
{
@ -408,7 +407,6 @@ pgendFillOutToCheckpoint (PGBackend *be, const char *query_string)
xaccTransCommitEdit (trans);
}
#endif
/* run the fill-out algorithm */
for (node=xaction_list; node; node=node->next)
@ -429,6 +427,35 @@ pgendFillOutToCheckpoint (PGBackend *be, const char *query_string)
int found = 0;
Split *s = (Split *) snode->data;
Account *acc = xaccSplitGetAccount (s);
GList *splits;
/* make sure the earliest split is first */
xaccAccountSortSplits (acc, TRUE);
splits = xaccAccountGetSplitList (acc);
/* See if we already have a split (acc_split)
* earlier than this transaction. Then either:
*
* 1) The acc_split was pulled in by the same
* query which brought in the current split
* and we will get to acc_split later.
* 2) The acc_split was loaded already and
* the account starting balance is correct
* up to that point.
*
* Either way, we can ignore the current split
* for the purposes of checkpointing.
*/
if (splits)
{
Split *acc_split = splits->data;
Transaction *t = xaccSplitGetParent (acc_split);
Timespec ts_2 = xaccTransRetDatePostedTS (t);
if (timespec_cmp (&ts_2, &ts) < 0)
continue;
}
/* lets see if we have a record of this account already */
for (anode = acct_list; anode; anode = anode->next)

@ -290,6 +290,11 @@ access).
(??? Maybe this has been fixed now, in the redesigned
gnc-book/gnc-session code ??? Maybe we just need to cleanup in
the postgres backend ??)
NOTE: (dave_p) In the redesigned book/session code, if
gnc_session_begin is called on a session
with a backend, the backend destroy function
is called before creating a new backend.
This seems to work ok in test-db.c.
-- allow user to enter URL in GUI dialog. User can currently type URL
into the file dialog window; it would be nice to have something

@ -41,7 +41,8 @@ CREATE FUNCTION gncSubtotalReconedBalance (CHAR(32), DATETIME, DATETIME)
gncEntry.accountGuid = $1 AND
gncEntry.transGuid = gncTransaction.transGuid AND
gncTransaction.date_posted BETWEEN $2 AND $3 AND
gncEntry.reconciled = \\'y\\''
(gncEntry.reconciled = \\'y\\' OR
gncEntry.reconciled = \\'f\\')'
LANGUAGE 'sql';
-- helper functions. These intentionally use the 'wrong' fraction.

@ -14,3 +14,4 @@
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,0,0,'Version Table');
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,1,1,'iGUID in Main Tables');
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,2,1,'Fix gncSubtotalReconedBalance');

@ -37,7 +37,7 @@ static short module = MOD_BACKEND;
/* ============================================================= */
#define PGEND_CURRENT_MAJOR_VERSION 1
#define PGEND_CURRENT_MINOR_VERSION 1
#define PGEND_CURRENT_MINOR_VERSION 2
#define PGEND_CURRENT_REV_VERSION 1
/* ============================================================= */
@ -204,14 +204,50 @@ put_iguid_in_tables (PGBackend *be)
sprintf(buff, "CREATE SEQUENCE gnc_iguid_seq START %d;", iguid);
SEND_QUERY (be,buff, );
FINISH_QUERY(be->connection);
p = "DROP TABLE gncGUIDCache;";
p = "DROP TABLE gncGUIDCache; \n"
"INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
" (1,1,1,'End Put iGUID in Main Tables');";
SEND_QUERY (be,p, );
FINISH_QUERY(be->connection);
}
static void
fix_reconciled_balance_func (PGBackend *be)
{
char *p;
p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
" (1,2,0,'Start Fix gncSubtotalReconedBalance');";
SEND_QUERY (be,p, );
FINISH_QUERY(be->connection);
p = "DROP FUNCTION "
"gncSubtotalReconedBalance (CHAR(32), DATETIME, DATETIME);";
SEND_QUERY (be,p, );
FINISH_QUERY(be->connection);
p = "CREATE FUNCTION "
"gncSubtotalReconedBalance (CHAR(32), DATETIME, DATETIME)"
"RETURNS INT8 "
"AS 'SELECT INT8(sum(gncEntry.amount)) "
"FROM gncEntry, gncTransaction "
"WHERE "
"gncEntry.accountGuid = $1 AND "
"gncEntry.transGuid = gncTransaction.transGuid AND "
"gncTransaction.date_posted BETWEEN $2 AND $3 AND "
"(gncEntry.reconciled = \\'y\\' OR "
" gncEntry.reconciled = \\'f\\')' "
"LANGUAGE 'sql';";
SEND_QUERY (be,p, );
FINISH_QUERY(be->connection);
p = "INSERT INTO gncVersion (major,minor,rev,name) VALUES \n"
" (1,2,1,'End Fix gncSubtotalReconedBalance');";
SEND_QUERY (be,p, );
FINISH_QUERY(be->connection);
}
/* ============================================================= */
/* Are we up to date ? */
/* Return 0 if we are at db version. Return +1 if we are newer.
@ -233,7 +269,7 @@ pgendDBVersionIsCurrent (PGBackend *be)
}
if ((PGEND_CURRENT_MAJOR_VERSION == vers.major) &&
(PGEND_CURRENT_MINOR_VERSION <= vers.minor)) return 0;
/* check to see if this client can connect */
if (PGEND_CURRENT_MAJOR_VERSION < vers.major)
{
@ -250,19 +286,22 @@ void
pgendUpgradeDB (PGBackend *be)
{
pgendVersion vers;
vers = pgendGetVersion(be);
/* start adding features to bring database up to date */
if (1 == vers.major)
{
/* version 1.1.0 add iguids to transaction and entry tables */
if (1> vers.minor)
if (1 > vers.minor)
{
put_iguid_in_tables(be);
}
if (2 > vers.minor)
{
fix_reconciled_balance_func (be);
}
}
}
/* ======================== END OF FILE ======================== */

Loading…
Cancel
Save