mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
split up raw sql into two files, so that the maximal query size
of 8192 bytes is not exceeded. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@4386 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
0c071e8164
commit
bf9d925cef
@ -26,6 +26,7 @@ EXTRA_DIST = \
|
||||
base-objects.m4 \
|
||||
check-objects.m4 \
|
||||
design.txt \
|
||||
functions.sql \
|
||||
kvp-objects.m4 \
|
||||
table.m4 \
|
||||
table-create.sql \
|
||||
@ -43,8 +44,8 @@ LDADD = ${GLIB_LIBS}
|
||||
# Some of the required C files are built with the m4 pre-processor
|
||||
# As a result, we need to manually specify dependencies, clean targets.
|
||||
|
||||
PostgresBackend.o: base-autogen.c table-create.c table-drop.c
|
||||
PostgresBackend.lo: base-autogen.c table-create.c table-drop.c
|
||||
PostgresBackend.o: base-autogen.c table-create.c table-drop.c functions.c
|
||||
PostgresBackend.lo: base-autogen.c table-create.c table-drop.c functions.c
|
||||
|
||||
checkpoint.o: check-autogen.c
|
||||
checkpoint.lo: check-autogen.c
|
||||
@ -61,18 +62,26 @@ check-autogen.c: table.m4 check-objects.m4
|
||||
kvp-autogen.c: table.m4 kvp-objects.m4
|
||||
m4 kvp-objects.m4 > kvp-autogen.c
|
||||
|
||||
functions.c: functions.sql
|
||||
echo \" > functions.c
|
||||
echo "-- DO NOT EDIT THIS FILE. IT IS AUTOGENERATED." >> functions.c
|
||||
cat functions.sql >> functions.c
|
||||
echo \" >> functions.c
|
||||
|
||||
table-drop.c: table-drop.sql
|
||||
echo \" > table-drop.c
|
||||
echo "-- DO NOT EDIT THIS FILE. IT IS AUTOGENERATED." >> table-drop.c
|
||||
cat table-drop.sql >> table-drop.c
|
||||
echo \" >> table-drop.c
|
||||
|
||||
table-create.c: table-create.sql
|
||||
echo \" > table-create.c
|
||||
echo "-- DO NOT EDIT THIS FILE. IT IS AUTOGENERATED." >> table-create.c
|
||||
cat table-create.sql >> table-create.c
|
||||
echo \" >> table-create.c
|
||||
|
||||
|
||||
clean:
|
||||
-rm -f base-autogen.c check-autogen.c kvp-autogen.c
|
||||
-rm -f table-drop.c table-create.c
|
||||
-rm -f table-drop.c table-create.c functions.c
|
||||
|
||||
|
@ -211,6 +211,10 @@ static const char *table_create_str =
|
||||
#include "table-create.c"
|
||||
;
|
||||
|
||||
static const char *sql_functions_str =
|
||||
#include "functions.c"
|
||||
;
|
||||
|
||||
static const char *table_drop_str =
|
||||
#include "table-drop.c"
|
||||
;
|
||||
@ -2675,9 +2679,14 @@ pgend_session_begin (GNCBook *sess, const char * sessionid,
|
||||
return;
|
||||
}
|
||||
|
||||
/* finally, create all the tables and indexes */
|
||||
/* Finally, create all the tables and indexes.
|
||||
* We do this in pieces, so as not to exceed the max length
|
||||
* for postgres queries (which is 8192).
|
||||
*/
|
||||
SEND_QUERY (be,table_create_str, );
|
||||
FINISH_QUERY(be->connection);
|
||||
SEND_QUERY (be,sql_functions_str, );
|
||||
FINISH_QUERY(be->connection);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
68
src/engine/sql/functions.sql
Normal file
68
src/engine/sql/functions.sql
Normal file
@ -0,0 +1,68 @@
|
||||
--
|
||||
-- FILE:
|
||||
-- functions.sql
|
||||
--
|
||||
-- FUNCTION:
|
||||
-- Define assorted utility functions.
|
||||
--
|
||||
-- HISTORY:
|
||||
-- Copyright (C) 2001 Linas Vepstas
|
||||
--
|
||||
|
||||
|
||||
-- utility functions to compute checkpoint balance subtotals
|
||||
|
||||
CREATE FUNCTION gncSubtotalBalance (CHAR(32), DATETIME, DATETIME)
|
||||
RETURNS NUMERIC
|
||||
AS 'SELECT sum(gncEntry.value)
|
||||
FROM gncEntry, gncTransaction
|
||||
WHERE
|
||||
gncEntry.accountGuid = $1 AND
|
||||
gncEntry.transGuid = gncTransaction.transGuid AND
|
||||
gncTransaction.date_posted BETWEEN $2 AND $3'
|
||||
LANGUAGE 'sql';
|
||||
|
||||
CREATE FUNCTION gncSubtotalClearedBalance (char(32), DATETIME, DATETIME)
|
||||
RETURNS NUMERIC
|
||||
AS 'SELECT sum(gncEntry.value)
|
||||
FROM gncEntry, gncTransaction
|
||||
WHERE
|
||||
gncEntry.accountGuid = $1 AND
|
||||
gncEntry.transGuid = gncTransaction.transGuid AND
|
||||
gncTransaction.date_posted BETWEEN $2 AND $3 AND
|
||||
gncEntry.reconciled <> \\'n\\''
|
||||
LANGUAGE 'sql';
|
||||
|
||||
CREATE FUNCTION gncSubtotalReconedBalance (CHAR(32), DATETIME, DATETIME)
|
||||
RETURNS NUMERIC
|
||||
AS 'SELECT sum(gncEntry.value)
|
||||
FROM gncEntry, gncTransaction
|
||||
WHERE
|
||||
gncEntry.accountGuid = $1 AND
|
||||
gncEntry.transGuid = gncTransaction.transGuid AND
|
||||
gncTransaction.date_posted BETWEEN $2 AND $3 AND
|
||||
gncEntry.reconciled = \\'y\\''
|
||||
LANGUAGE 'sql';
|
||||
|
||||
-- helper functions. These intentionally use the 'wrong' fraction.
|
||||
-- This is because value_frac * amount * price = value * amount_frac
|
||||
|
||||
CREATE FUNCTION gncHelperPrVal (gncEntry)
|
||||
RETURNS INT8
|
||||
AS 'SELECT abs($1 . value * gncCommodity.fraction)
|
||||
FROM gncEntry, gncAccount, gncCommodity
|
||||
WHERE
|
||||
$1 . accountGuid = gncAccount.accountGuid AND
|
||||
gncAccount.commodity = gncCommodity.commodity'
|
||||
LANGUAGE 'sql';
|
||||
|
||||
CREATE FUNCTION gncHelperPrAmt (gncEntry)
|
||||
RETURNS INT8
|
||||
AS 'SELECT abs($1 . amount * gncCommodity.fraction)
|
||||
FROM gncEntry, gncTransaction, gncCommodity
|
||||
WHERE
|
||||
$1 . transGuid = gncTransaction.transGuid AND
|
||||
gncTransaction.currency = gncCommodity.commodity'
|
||||
LANGUAGE 'sql';
|
||||
|
||||
-- end of file
|
@ -115,7 +115,8 @@ CREATE TABLE gncPrice (
|
||||
source TEXT,
|
||||
type TEXT,
|
||||
valueNum INT8 DEFAULT '0',
|
||||
valueDenom INT4 DEFAULT '100'
|
||||
valueDenom INT4 DEFAULT '100',
|
||||
version INT4 NOT NULL
|
||||
);
|
||||
|
||||
|
||||
@ -187,59 +188,4 @@ CREATE TABLE gncKVPvalue_list (
|
||||
data TEXT[]
|
||||
) INHERITS (gncKVPvalue);
|
||||
|
||||
-- utility functions to compute chackpoint balance subtotals
|
||||
|
||||
CREATE FUNCTION gncSubtotalBalance (CHAR(32), DATETIME, DATETIME)
|
||||
RETURNS NUMERIC
|
||||
AS 'SELECT sum(gncEntry.value)
|
||||
FROM gncEntry, gncTransaction
|
||||
WHERE
|
||||
gncEntry.accountGuid = $1 AND
|
||||
gncEntry.transGuid = gncTransaction.transGuid AND
|
||||
gncTransaction.date_posted BETWEEN $2 AND $3'
|
||||
LANGUAGE 'sql';
|
||||
|
||||
CREATE FUNCTION gncSubtotalClearedBalance (char(32), DATETIME, DATETIME)
|
||||
RETURNS NUMERIC
|
||||
AS 'SELECT sum(gncEntry.value)
|
||||
FROM gncEntry, gncTransaction
|
||||
WHERE
|
||||
gncEntry.accountGuid = $1 AND
|
||||
gncEntry.transGuid = gncTransaction.transGuid AND
|
||||
gncTransaction.date_posted BETWEEN $2 AND $3 AND
|
||||
gncEntry.reconciled <> \\'n\\''
|
||||
LANGUAGE 'sql';
|
||||
|
||||
CREATE FUNCTION gncSubtotalReconedBalance (CHAR(32), DATETIME, DATETIME)
|
||||
RETURNS NUMERIC
|
||||
AS 'SELECT sum(gncEntry.value)
|
||||
FROM gncEntry, gncTransaction
|
||||
WHERE
|
||||
gncEntry.accountGuid = $1 AND
|
||||
gncEntry.transGuid = gncTransaction.transGuid AND
|
||||
gncTransaction.date_posted BETWEEN $2 AND $3 AND
|
||||
gncEntry.reconciled = \\'y\\''
|
||||
LANGUAGE 'sql';
|
||||
|
||||
-- helper functions. These intentionally use the 'wrong' fraction.
|
||||
-- This is because value_frac * amount * price = value * amount_frac
|
||||
|
||||
CREATE FUNCTION gncHelperPrVal (gncEntry)
|
||||
RETURNS INT8
|
||||
AS 'SELECT abs($1 . value * gncCommodity.fraction)
|
||||
FROM gncEntry, gncAccount, gncCommodity
|
||||
WHERE
|
||||
$1 . accountGuid = gncAccount.accountGuid AND
|
||||
gncAccount.commodity = gncCommodity.commodity'
|
||||
LANGUAGE 'sql';
|
||||
|
||||
CREATE FUNCTION gncHelperPrAmt (gncEntry)
|
||||
RETURNS INT8
|
||||
AS 'SELECT abs($1 . amount * gncCommodity.fraction)
|
||||
FROM gncEntry, gncTransaction, gncCommodity
|
||||
WHERE
|
||||
$1 . transGuid = gncTransaction.transGuid AND
|
||||
gncTransaction.currency = gncCommodity.commodity'
|
||||
LANGUAGE 'sql';
|
||||
|
||||
|
||||
-- end of file
|
||||
|
Loading…
Reference in New Issue
Block a user