mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Matthew Vanecek's PG patches...
* src/backend/postgres/Makefile.am: Changed the .sql.c target to not echo the beginning and ending quotes. This is part of the gcc 3.x compatibility changes. * src/backend/postgres/PostgresBackend.c: Made some whitespace changes for readability. - (pgend_book_load_poll): Commented out a PWARN about the old book list not being empty. See added comments for why. - (pgend_book_load_poll): added a gnc_session_set_book() call so that the session would have the correct book loaded (i.e., the book that's stored in the DB). * src/backend/postgres/*.sql: Enclosed each line in a set of quotes "..". The "multi-line literals" were causing compile errors for gcc 3.x. * src/backend/postgres/gncquery.c: ran indent on the file. - (STRING_TERM): Changed the comparison on STRING_MATCH_NORMAL to STRING_MATCH_CASEINSENSITIVE for purposes of adding a '*' to the comparison operator "~". The code was writing a "=*" which is invalid, but "~*" is valid for case-insensitive regex searches. - (sqlQuery_build): Added a "more_and = 0" to the final if statement of the "for (il = qterms; il; il = il->next)" loop. This will prevent a stray "AND" being appended to the end of the "WHERE" clause of a dynamic query. * src/backend/postgres/kvp-sql (store_cb): In "case KVP_TYPE_TIMESPEC", changed the 'cb_data->stype = "timespec"' to 'cb_data->stype = "time"'. The destination field in the database is defined as 4 characters, and the extra chars in stype were causing an insertion error. * src/backend/postgres/putil.h (FINISH_QUERY): Changed the error to use PQresultErrorMessage() instead of PQerrorMessage(). * src/backend/postgres/test/db-control.sh (our_pg_ctl): Changed the script to return -1 if pg_ctl was not found in PATH. * src/backend/postgres/test/run-tests.sh: If db-control.sh returns failure, the attempt to connect to $PGHOST on $PGPORT. * src/backend/postgres/test/test-db.c: Included QueryNew.h. Added the _dbinfo struct to pass host, port, dbname, and mode information around. Everywhere that used db_name/mode is now using DbInfor->*. - Ran indent on the file. - Added a drop_database function to call dropdb on the database used for the tests. This eventually needs to be changed so that every "return FALSE" first calls gnc_session_destroy(session), before this new function is called. - (db_file_url): Changed the function to handle TCP connections as well as socket connections. - (load_db_file): Added a PGBackend object from which to get a PGconn connection to store in DbInfo. - (test_raw_query): Added a call to gncQueryPrint() if gnc_should_log(MOD_TEST, GNC_LOG_DETAIL) git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@7894 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
bd57bf6706
commit
eb3c5eb238
57
ChangeLog
57
ChangeLog
@ -1,3 +1,60 @@
|
|||||||
|
2003-01-29 Matthew Vanecek <mevanecek@yahoo.com>
|
||||||
|
|
||||||
|
* src/backend/postgres/Makefile.am: Changed the .sql.c target to
|
||||||
|
not echo the beginning and ending quotes. This is part of the
|
||||||
|
gcc 3.x compatibility changes.
|
||||||
|
|
||||||
|
* src/backend/postgres/PostgresBackend.c: Made some whitespace changes
|
||||||
|
for readability.
|
||||||
|
- (pgend_book_load_poll): Commented out a PWARN about the old book
|
||||||
|
list not being empty. See added comments for why.
|
||||||
|
- (pgend_book_load_poll): added a gnc_session_set_book() call so that
|
||||||
|
the session would have the correct book loaded (i.e., the book
|
||||||
|
that's stored in the DB).
|
||||||
|
|
||||||
|
* src/backend/postgres/*.sql: Enclosed each line in a set of
|
||||||
|
quotes "..". The "multi-line literals" were causing compile errors
|
||||||
|
for gcc 3.x.
|
||||||
|
|
||||||
|
* src/backend/postgres/gncquery.c: ran indent on the file.
|
||||||
|
- (STRING_TERM): Changed the comparison on STRING_MATCH_NORMAL to
|
||||||
|
STRING_MATCH_CASEINSENSITIVE for purposes of adding a '*' to the
|
||||||
|
comparison operator "~". The code was writing a "=*" which is
|
||||||
|
invalid, but "~*" is valid for case-insensitive regex searches.
|
||||||
|
- (sqlQuery_build): Added a "more_and = 0" to the final if statement
|
||||||
|
of the "for (il = qterms; il; il = il->next)" loop. This will
|
||||||
|
prevent a stray "AND" being appended to the end of the "WHERE" clause
|
||||||
|
of a dynamic query.
|
||||||
|
|
||||||
|
* src/backend/postgres/kvp-sql (store_cb): In "case KVP_TYPE_TIMESPEC",
|
||||||
|
changed the 'cb_data->stype = "timespec"' to 'cb_data->stype = "time"'.
|
||||||
|
The destination field in the database is defined as 4 characters, and
|
||||||
|
the extra chars in stype were causing an insertion error.
|
||||||
|
|
||||||
|
* src/backend/postgres/putil.h (FINISH_QUERY): Changed the error to use
|
||||||
|
PQresultErrorMessage() instead of PQerrorMessage().
|
||||||
|
|
||||||
|
* src/backend/postgres/test/db-control.sh (our_pg_ctl): Changed the
|
||||||
|
script to return -1 if pg_ctl was not found in PATH.
|
||||||
|
|
||||||
|
* src/backend/postgres/test/run-tests.sh: If db-control.sh returns
|
||||||
|
failure, the attempt to connect to $PGHOST on $PGPORT.
|
||||||
|
|
||||||
|
* src/backend/postgres/test/test-db.c: Included QueryNew.h. Added the
|
||||||
|
_dbinfo struct to pass host, port, dbname, and mode information
|
||||||
|
around. Everywhere that used db_name/mode is now using DbInfor->*.
|
||||||
|
- Ran indent on the file.
|
||||||
|
- Added a drop_database function to call dropdb on the database used
|
||||||
|
for the tests. This eventually needs to be changed so that every
|
||||||
|
"return FALSE" first calls gnc_session_destroy(session), before this
|
||||||
|
new function is called.
|
||||||
|
- (db_file_url): Changed the function to handle TCP connections as well
|
||||||
|
as socket connections.
|
||||||
|
- (load_db_file): Added a PGBackend object from which to get a PGconn
|
||||||
|
connection to store in DbInfo.
|
||||||
|
- (test_raw_query): Added a call to gncQueryPrint() if
|
||||||
|
gnc_should_log(MOD_TEST, GNC_LOG_DETAIL)
|
||||||
|
|
||||||
2003-01-29 Herbert Thoma <herbie@hthoma.de>
|
2003-01-29 Herbert Thoma <herbie@hthoma.de>
|
||||||
|
|
||||||
* src/report/standard-reports/cash-flow.scm: only asset accounts
|
* src/report/standard-reports/cash-flow.scm: only asset accounts
|
||||||
|
@ -108,8 +108,6 @@ $(M4_SRC): table.m4
|
|||||||
m4 -I ${srcdir} $< > $@
|
m4 -I ${srcdir} $< > $@
|
||||||
|
|
||||||
.sql.c:
|
.sql.c:
|
||||||
echo \" > $@
|
echo "\"-- DO NOT EDIT THIS FILE. IT IS AUTOGENERATED.\"" > $@
|
||||||
echo "-- DO NOT EDIT THIS FILE. IT IS AUTOGENERATED." >> $@
|
|
||||||
cat $< >> $@
|
cat $< >> $@
|
||||||
echo \" >> $@
|
|
||||||
|
|
||||||
|
@ -1473,7 +1473,6 @@ pgend_session_end (Backend *bend)
|
|||||||
* the poll & event style load, where only the accounts,
|
* the poll & event style load, where only the accounts,
|
||||||
* and never the transactions, need to be loaded.
|
* and never the transactions, need to be loaded.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
pgend_book_load_poll (Backend *bend, GNCBook *book)
|
pgend_book_load_poll (Backend *bend, GNCBook *book)
|
||||||
{
|
{
|
||||||
@ -1493,12 +1492,20 @@ pgend_book_load_poll (Backend *bend, GNCBook *book)
|
|||||||
if (be->blist)
|
if (be->blist)
|
||||||
{
|
{
|
||||||
/* XXX not clear what this means ... should we free old books ?? */
|
/* XXX not clear what this means ... should we free old books ?? */
|
||||||
PWARN ("old book list not empty ");
|
/* The old book list is set by the session when the session is
|
||||||
|
* created. It is an empty book, and should be discarded in favor
|
||||||
|
* of the Book retrieved from the database.
|
||||||
|
* PWARN ("old book list not empty ");
|
||||||
|
*/
|
||||||
g_list_free (be->blist);
|
g_list_free (be->blist);
|
||||||
be->blist = NULL;
|
be->blist = NULL;
|
||||||
}
|
}
|
||||||
pgend_set_book (be, book);
|
pgend_set_book (be, book);
|
||||||
pgendGetBook (be, book);
|
pgendGetBook (be, book);
|
||||||
|
gnc_session_set_book(be->session, book);
|
||||||
|
|
||||||
|
PINFO("Book GUID = %s\n",
|
||||||
|
guid_to_string(gnc_book_get_guid(book)));
|
||||||
|
|
||||||
pgendGetAllAccountsInBook (be, book);
|
pgendGetAllAccountsInBook (be, book);
|
||||||
|
|
||||||
@ -2272,7 +2279,6 @@ pgend_session_begin (Backend *backend,
|
|||||||
be->be.begin = pgend_do_begin;
|
be->be.begin = pgend_do_begin;
|
||||||
be->be.commit = pgend_do_commit;
|
be->be.commit = pgend_do_commit;
|
||||||
be->be.rollback = pgend_do_rollback;
|
be->be.rollback = pgend_do_rollback;
|
||||||
|
|
||||||
be->be.compile_query = NULL;
|
be->be.compile_query = NULL;
|
||||||
be->be.free_query = NULL;
|
be->be.free_query = NULL;
|
||||||
be->be.run_query = NULL;
|
be->be.run_query = NULL;
|
||||||
|
@ -1,69 +1,69 @@
|
|||||||
--
|
"-- \n"
|
||||||
-- FILE:
|
"-- FILE: \n"
|
||||||
-- functions.sql
|
"-- functions.sql \n"
|
||||||
--
|
"-- \n"
|
||||||
-- FUNCTION:
|
"-- FUNCTION: \n"
|
||||||
-- Define assorted utility functions.
|
"-- Define assorted utility functions. \n"
|
||||||
--
|
"-- \n"
|
||||||
-- HISTORY:
|
"-- HISTORY: \n"
|
||||||
-- Copyright (C) 2001 Linas Vepstas
|
"-- Copyright (C) 2001 Linas Vepstas \n"
|
||||||
--
|
"-- \n"
|
||||||
|
" \n"
|
||||||
|
" \n"
|
||||||
-- utility functions to compute checkpoint balance subtotals
|
"-- utility functions to compute checkpoint balance subtotals \n"
|
||||||
|
" \n"
|
||||||
CREATE FUNCTION gncSubtotalBalance (CHAR(32), TIMESTAMP, TIMESTAMP)
|
"CREATE FUNCTION gncSubtotalBalance (CHAR(32), TIMESTAMP, TIMESTAMP) \n"
|
||||||
RETURNS INT8
|
" RETURNS INT8 \n"
|
||||||
AS 'SELECT INT8(sum(gncEntry.amount))
|
" AS 'SELECT INT8(sum(gncEntry.amount)) \n"
|
||||||
FROM gncEntry, gncTransaction
|
" FROM gncEntry, gncTransaction \n"
|
||||||
WHERE
|
" WHERE \n"
|
||||||
gncEntry.accountGuid = $1 AND
|
" gncEntry.accountGuid = $1 AND \n"
|
||||||
gncEntry.transGuid = gncTransaction.transGuid AND
|
" gncEntry.transGuid = gncTransaction.transGuid AND \n"
|
||||||
gncTransaction.date_posted BETWEEN $2 AND $3'
|
" gncTransaction.date_posted BETWEEN $2 AND $3' \n"
|
||||||
LANGUAGE 'sql';
|
" LANGUAGE 'sql'; \n"
|
||||||
|
" \n"
|
||||||
CREATE FUNCTION gncSubtotalClearedBalance (CHAR(32), TIMESTAMP, TIMESTAMP)
|
"CREATE FUNCTION gncSubtotalClearedBalance (CHAR(32), TIMESTAMP, TIMESTAMP) \n"
|
||||||
RETURNS INT8
|
" RETURNS INT8 \n"
|
||||||
AS 'SELECT INT8(sum(gncEntry.amount))
|
" AS 'SELECT INT8(sum(gncEntry.amount)) \n"
|
||||||
FROM gncEntry, gncTransaction
|
" FROM gncEntry, gncTransaction \n"
|
||||||
WHERE
|
" WHERE \n"
|
||||||
gncEntry.accountGuid = $1 AND
|
" gncEntry.accountGuid = $1 AND \n"
|
||||||
gncEntry.transGuid = gncTransaction.transGuid AND
|
" gncEntry.transGuid = gncTransaction.transGuid AND \n"
|
||||||
gncTransaction.date_posted BETWEEN $2 AND $3 AND
|
" gncTransaction.date_posted BETWEEN $2 AND $3 AND \n"
|
||||||
gncEntry.reconciled <> \\'n\\''
|
" gncEntry.reconciled <> \\'n\\'' \n"
|
||||||
LANGUAGE 'sql';
|
" LANGUAGE 'sql'; \n"
|
||||||
|
" \n"
|
||||||
CREATE FUNCTION gncSubtotalReconedBalance (CHAR(32), TIMESTAMP, TIMESTAMP)
|
"CREATE FUNCTION gncSubtotalReconedBalance (CHAR(32), TIMESTAMP, TIMESTAMP) \n"
|
||||||
RETURNS INT8
|
" RETURNS INT8 \n"
|
||||||
AS 'SELECT INT8(sum(gncEntry.amount))
|
" AS 'SELECT INT8(sum(gncEntry.amount)) \n"
|
||||||
FROM gncEntry, gncTransaction
|
" FROM gncEntry, gncTransaction \n"
|
||||||
WHERE
|
" WHERE \n"
|
||||||
gncEntry.accountGuid = $1 AND
|
" gncEntry.accountGuid = $1 AND \n"
|
||||||
gncEntry.transGuid = gncTransaction.transGuid AND
|
" gncEntry.transGuid = gncTransaction.transGuid AND \n"
|
||||||
gncTransaction.date_posted BETWEEN $2 AND $3 AND
|
" gncTransaction.date_posted BETWEEN $2 AND $3 AND \n"
|
||||||
(gncEntry.reconciled = \\'y\\' OR
|
" (gncEntry.reconciled = \\'y\\' OR \n"
|
||||||
gncEntry.reconciled = \\'f\\')'
|
" gncEntry.reconciled = \\'f\\')' \n"
|
||||||
LANGUAGE 'sql';
|
" LANGUAGE 'sql'; \n"
|
||||||
|
" \n"
|
||||||
-- helper functions. These intentionally use the 'wrong' fraction.
|
"-- helper functions. These intentionally use the 'wrong' fraction. \n"
|
||||||
-- This is because value_frac * amount * price = value * amount_frac
|
"-- This is because value_frac * amount * price = value * amount_frac \n"
|
||||||
|
" \n"
|
||||||
CREATE FUNCTION gncHelperPrVal (gncEntry)
|
"CREATE FUNCTION gncHelperPrVal (gncEntry) \n"
|
||||||
RETURNS INT8
|
" RETURNS INT8 \n"
|
||||||
AS 'SELECT abs($1 . value * gncCommodity.fraction)
|
" AS 'SELECT abs($1 . value * gncCommodity.fraction) \n"
|
||||||
FROM gncEntry, gncAccount, gncCommodity
|
" FROM gncEntry, gncAccount, gncCommodity \n"
|
||||||
WHERE
|
" WHERE \n"
|
||||||
$1 . accountGuid = gncAccount.accountGuid AND
|
" $1 . accountGuid = gncAccount.accountGuid AND \n"
|
||||||
gncAccount.commodity = gncCommodity.commodity'
|
" gncAccount.commodity = gncCommodity.commodity' \n"
|
||||||
LANGUAGE 'sql';
|
" LANGUAGE 'sql'; \n"
|
||||||
|
" \n"
|
||||||
CREATE FUNCTION gncHelperPrAmt (gncEntry)
|
"CREATE FUNCTION gncHelperPrAmt (gncEntry) \n"
|
||||||
RETURNS INT8
|
" RETURNS INT8 \n"
|
||||||
AS 'SELECT abs($1 . amount * gncCommodity.fraction)
|
" AS 'SELECT abs($1 . amount * gncCommodity.fraction) \n"
|
||||||
FROM gncEntry, gncTransaction, gncCommodity
|
" FROM gncEntry, gncTransaction, gncCommodity \n"
|
||||||
WHERE
|
" WHERE \n"
|
||||||
$1 . transGuid = gncTransaction.transGuid AND
|
" $1 . transGuid = gncTransaction.transGuid AND \n"
|
||||||
gncTransaction.currency = gncCommodity.commodity'
|
" gncTransaction.currency = gncCommodity.commodity' \n"
|
||||||
LANGUAGE 'sql';
|
" LANGUAGE 'sql'; \n"
|
||||||
|
" \n"
|
||||||
-- end of file
|
"-- end of file";
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -286,7 +286,7 @@ store_cb (const char *key, kvp_value *val, gpointer p)
|
|||||||
case KVP_TYPE_TIMESPEC:
|
case KVP_TYPE_TIMESPEC:
|
||||||
{
|
{
|
||||||
PINFO ("path=%s type=timespec", cb_data->path);
|
PINFO ("path=%s type=timespec", cb_data->path);
|
||||||
cb_data->stype = "timespec";
|
cb_data->stype = "time";
|
||||||
cb_data->u.ts = kvp_value_get_timespec (val);
|
cb_data->u.ts = kvp_value_get_timespec (val);
|
||||||
pgendPutOneKVPtimespecOnly (be, cb_data);
|
pgendPutOneKVPtimespecOnly (be, cb_data);
|
||||||
}
|
}
|
||||||
|
@ -121,8 +121,8 @@ int finishQuery(PGBackend *be);
|
|||||||
PINFO ("clearing result %d", i); \
|
PINFO ("clearing result %d", i); \
|
||||||
status = PQresultStatus(result); \
|
status = PQresultStatus(result); \
|
||||||
if (PGRES_COMMAND_OK != status) { \
|
if (PGRES_COMMAND_OK != status) { \
|
||||||
PERR("finish query failed:\n" \
|
msg = PQresultErrorMessage(result); \
|
||||||
"\t%s", PQerrorMessage((conn))); \
|
PERR("finish query failed:\n\t%s", msg); \
|
||||||
PQclear(result); \
|
PQclear(result); \
|
||||||
xaccBackendSetMessage (&be->be, msg); \
|
xaccBackendSetMessage (&be->be, msg); \
|
||||||
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); \
|
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); \
|
||||||
@ -131,7 +131,7 @@ int finishQuery(PGBackend *be);
|
|||||||
PQclear(result); \
|
PQclear(result); \
|
||||||
i++; \
|
i++; \
|
||||||
} while (result); \
|
} while (result); \
|
||||||
}
|
} \
|
||||||
|
|
||||||
/* --------------------------------------------------------------- */
|
/* --------------------------------------------------------------- */
|
||||||
/* The GET_RESULTS macro grabs the result of an pgSQL query off the
|
/* The GET_RESULTS macro grabs the result of an pgSQL query off the
|
||||||
|
@ -1,174 +1,174 @@
|
|||||||
--
|
"-- \n"
|
||||||
-- FILE:
|
"-- FILE: \n"
|
||||||
-- table-audit.sql
|
"-- table-audit.sql \n"
|
||||||
--
|
"-- \n"
|
||||||
-- FUNCTION:
|
"-- FUNCTION: \n"
|
||||||
-- Define the audit trail tables
|
"-- Define the audit trail tables \n"
|
||||||
-- Note that these tables must be kept manually in sync with those
|
"-- Note that these tables must be kept manually in sync with those \n"
|
||||||
-- in table-create.sql
|
"-- in table-create.sql \n"
|
||||||
--
|
"-- \n"
|
||||||
-- HISTORY:
|
"-- HISTORY: \n"
|
||||||
-- Copyright (C) 2000, 2001 Linas Vepstas
|
"-- Copyright (C) 2000, 2001 Linas Vepstas \n"
|
||||||
--
|
"-- \n"
|
||||||
-- The change field may be 'a' -- add, 'd' -- delete/drop, 'm' -- modify
|
"-- The change field may be 'a' -- add, 'd' -- delete/drop, 'm' -- modify \n"
|
||||||
--
|
"-- \n"
|
||||||
-- The objtype field may be 'a' -- account, 'c' -- commodity, 'e' -- entry,
|
"-- The objtype field may be 'a' -- account, 'c' -- commodity, 'e' -- entry, \n"
|
||||||
-- 'k' -- kvp, 'p' -- price, 't' -- transaction
|
"-- 'k' -- kvp, 'p' -- price, 't' -- transaction \n"
|
||||||
--
|
"-- \n"
|
||||||
-- The objtype is the class type of the child class.
|
"-- The objtype is the class type of the child class. \n"
|
||||||
--
|
"-- \n"
|
||||||
-- Note that SQL is only partially object-oriented. Thus, we use the
|
"-- Note that SQL is only partially object-oriented. Thus, we use the \n"
|
||||||
-- gncAuditTrail table to define the parent class; the children inherit
|
"-- gncAuditTrail table to define the parent class; the children inherit \n"
|
||||||
-- from it. Since SQL doesn't tell the parent who the child was, we use
|
"-- from it. Since SQL doesn't tell the parent who the child was, we use \n"
|
||||||
-- the 'objtype' field to store the class type of the child.
|
"-- the 'objtype' field to store the class type of the child. \n"
|
||||||
--
|
"-- \n"
|
||||||
-- Thus, we should really enforce a constraint on this field:
|
"-- Thus, we should really enforce a constraint on this field: \n"
|
||||||
-- CREATE TABLE gncAccountTrail (
|
"-- CREATE TABLE gncAccountTrail ( \n"
|
||||||
-- objtype CHAR NOT NULL CHECK (objtype == 'a')
|
"-- objtype CHAR NOT NULL CHECK (objtype == 'a') \n"
|
||||||
-- and so on.
|
"-- and so on. \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncAuditTrail (
|
"CREATE TABLE gncAuditTrail ( \n"
|
||||||
sessionGuid CHAR(32) NOT NULL, -- who changed it
|
" sessionGuid CHAR(32) NOT NULL, -- who changed it \n"
|
||||||
date_changed TIMESTAMP, -- when they changed it
|
" date_changed TIMESTAMP, -- when they changed it \n"
|
||||||
change CHAR NOT NULL,
|
" change CHAR NOT NULL, \n"
|
||||||
objtype CHAR NOT NULL
|
" objtype CHAR NOT NULL \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
-- would love to inherit, but can't because this wrecks the primary key
|
"-- would love to inherit, but can't because this wrecks the primary key \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncAccountTrail (
|
"CREATE TABLE gncAccountTrail ( \n"
|
||||||
accountGuid CHAR(32) NOT NULL, -- override, not a primary key anymore
|
" accountGuid CHAR(32) NOT NULL, -- override, not a primary key anymore \n"
|
||||||
parentGuid CHAR(32) NOT NULL,
|
" parentGuid CHAR(32) NOT NULL, \n"
|
||||||
bookGuid CHAR(32) NOT NULL,
|
" bookGuid CHAR(32) NOT NULL, \n"
|
||||||
accountName TEXT NOT NULL CHECK (accountName <> ''),
|
" accountName TEXT NOT NULL CHECK (accountName <> ''), \n"
|
||||||
accountCode TEXT,
|
" accountCode TEXT, \n"
|
||||||
description TEXT,
|
" description TEXT, \n"
|
||||||
type TEXT NOT NULL,
|
" type TEXT NOT NULL, \n"
|
||||||
commodity TEXT NOT NULL CHECK (commodity <>''),
|
" commodity TEXT NOT NULL CHECK (commodity <>''), \n"
|
||||||
version INT4 NOT NULL,
|
" version INT4 NOT NULL, \n"
|
||||||
iguid INT4 DEFAULT 0
|
" iguid INT4 DEFAULT 0 \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE INDEX gncAccountTrail_account_idx ON gncAccountTrail (accountGuid);
|
"CREATE INDEX gncAccountTrail_account_idx ON gncAccountTrail (accountGuid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncBookTrail (
|
"CREATE TABLE gncBookTrail ( \n"
|
||||||
bookGuid CHAR(32) NOT NULL,
|
" bookGuid CHAR(32) NOT NULL, \n"
|
||||||
book_open CHAR DEFAULT 'n',
|
" book_open CHAR DEFAULT 'n', \n"
|
||||||
version INT4 NOT NULL,
|
" version INT4 NOT NULL, \n"
|
||||||
iguid INT4 DEFAULT 0
|
" iguid INT4 DEFAULT 0 \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE INDEX gncBookTrail_book_idx ON gncBookTrail (bookGuid);
|
"CREATE INDEX gncBookTrail_book_idx ON gncBookTrail (bookGuid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncCommodityTrail (
|
"CREATE TABLE gncCommodityTrail ( \n"
|
||||||
commodity TEXT NOT NULL, -- override, not a primary key anymore
|
" commodity TEXT NOT NULL, -- override, not a primary key anymore \n"
|
||||||
fullname TEXT,
|
" fullname TEXT, \n"
|
||||||
namespace TEXT NOT NULL,
|
" namespace TEXT NOT NULL, \n"
|
||||||
mnemonic TEXT NOT NULL,
|
" mnemonic TEXT NOT NULL, \n"
|
||||||
code TEXT,
|
" code TEXT, \n"
|
||||||
fraction INT DEFAULT '100'
|
" fraction INT DEFAULT '100' \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE INDEX gncCommodityTrail_commodity_idx ON gncCommodityTrail (commodity);
|
"CREATE INDEX gncCommodityTrail_commodity_idx ON gncCommodityTrail (commodity); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncEntryTrail (
|
"CREATE TABLE gncEntryTrail ( \n"
|
||||||
entryGuid CHAR(32) NOT NULL, -- override, not a primary key anymore
|
" entryGuid CHAR(32) NOT NULL, -- override, not a primary key anymore \n"
|
||||||
accountGuid CHAR(32) NOT NULL,
|
" accountGuid CHAR(32) NOT NULL, \n"
|
||||||
transGuid CHAR(32) NOT NULL,
|
" transGuid CHAR(32) NOT NULL, \n"
|
||||||
memo TEXT,
|
" memo TEXT, \n"
|
||||||
action TEXT,
|
" action TEXT, \n"
|
||||||
reconciled CHAR DEFAULT 'n',
|
" reconciled CHAR DEFAULT 'n', \n"
|
||||||
date_reconciled TIMESTAMP,
|
" date_reconciled TIMESTAMP, \n"
|
||||||
amount INT8 DEFAULT '0',
|
" amount INT8 DEFAULT '0', \n"
|
||||||
value INT8 DEFAULT '0',
|
" value INT8 DEFAULT '0', \n"
|
||||||
iguid INT4 DEFAULT 0
|
" iguid INT4 DEFAULT 0 \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE INDEX gncEntryTrail_entry_idx ON gncEntryTrail (entryGuid);
|
"CREATE INDEX gncEntryTrail_entry_idx ON gncEntryTrail (entryGuid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncPriceTrail (
|
"CREATE TABLE gncPriceTrail ( \n"
|
||||||
priceGuid CHAR(32) NOT NULL, -- override, not a primary key anymore
|
" priceGuid CHAR(32) NOT NULL, -- override, not a primary key anymore \n"
|
||||||
commodity TEXT NOT NULL CHECK (commodity <>''),
|
" commodity TEXT NOT NULL CHECK (commodity <>''), \n"
|
||||||
currency TEXT NOT NULL CHECK (commodity <>''),
|
" currency TEXT NOT NULL CHECK (commodity <>''), \n"
|
||||||
time TIMESTAMP,
|
" time TIMESTAMP, \n"
|
||||||
source TEXT,
|
" source TEXT, \n"
|
||||||
type TEXT,
|
" type TEXT, \n"
|
||||||
valueNum INT8 DEFAULT '0',
|
" valueNum INT8 DEFAULT '0', \n"
|
||||||
valueDenom INT4 DEFAULT '100',
|
" valueDenom INT4 DEFAULT '100', \n"
|
||||||
version INT4 NOT NULL,
|
" version INT4 NOT NULL, \n"
|
||||||
bookGuid CHAR(32) NOT NULL
|
" bookGuid CHAR(32) NOT NULL \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE INDEX gncPriceTrail_price_idx ON gncPriceTrail (priceGuid);
|
"CREATE INDEX gncPriceTrail_price_idx ON gncPriceTrail (priceGuid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncTransactionTrail (
|
"CREATE TABLE gncTransactionTrail ( \n"
|
||||||
transGuid CHAR(32) NOT NULL, -- override, not a primary key anymore
|
" transGuid CHAR(32) NOT NULL, -- override, not a primary key anymore \n"
|
||||||
last_modified TIMESTAMP DEFAULT 'NOW',
|
" last_modified TIMESTAMP DEFAULT 'NOW', \n"
|
||||||
date_entered TIMESTAMP,
|
" date_entered TIMESTAMP, \n"
|
||||||
date_posted TIMESTAMP,
|
" date_posted TIMESTAMP, \n"
|
||||||
num TEXT,
|
" num TEXT, \n"
|
||||||
description TEXT,
|
" description TEXT, \n"
|
||||||
currency TEXT NOT NULL CHECK (currency <> ''),
|
" currency TEXT NOT NULL CHECK (currency <> ''), \n"
|
||||||
version INT4 NOT NULL,
|
" version INT4 NOT NULL, \n"
|
||||||
iguid INT4 DEFAULT 0
|
" iguid INT4 DEFAULT 0 \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE INDEX gncTransactionTrail_trans_idx ON gncTransactionTrail (transGuid);
|
"CREATE INDEX gncTransactionTrail_trans_idx ON gncTransactionTrail (transGuid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalueTrail (
|
"CREATE TABLE gncKVPvalueTrail ( \n"
|
||||||
iguid INT4,
|
" iguid INT4, \n"
|
||||||
ipath INT4,
|
" ipath INT4, \n"
|
||||||
type char(4)
|
" type char(4) \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_int64Trail (
|
"CREATE TABLE gncKVPvalue_int64Trail ( \n"
|
||||||
iguid INT4,
|
" iguid INT4, \n"
|
||||||
ipath INT4,
|
" ipath INT4, \n"
|
||||||
type char(4),
|
" type char(4), \n"
|
||||||
data INT8
|
" data INT8 \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_dblTrail (
|
"CREATE TABLE gncKVPvalue_dblTrail ( \n"
|
||||||
iguid INT4,
|
" iguid INT4, \n"
|
||||||
ipath INT4,
|
" ipath INT4, \n"
|
||||||
type char(4),
|
" type char(4), \n"
|
||||||
data FLOAT8
|
" data FLOAT8 \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_numericTrail (
|
"CREATE TABLE gncKVPvalue_numericTrail ( \n"
|
||||||
iguid INT4,
|
" iguid INT4, \n"
|
||||||
ipath INT4,
|
" ipath INT4, \n"
|
||||||
type char(4),
|
" type char(4), \n"
|
||||||
num INT8,
|
" num INT8, \n"
|
||||||
denom INT8
|
" denom INT8 \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_strTrail (
|
"CREATE TABLE gncKVPvalue_strTrail ( \n"
|
||||||
iguid INT4,
|
" iguid INT4, \n"
|
||||||
ipath INT4,
|
" ipath INT4, \n"
|
||||||
type char(4),
|
" type char(4), \n"
|
||||||
data TEXT
|
" data TEXT \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_guidTrail (
|
"CREATE TABLE gncKVPvalue_guidTrail ( \n"
|
||||||
iguid INT4,
|
" iguid INT4, \n"
|
||||||
ipath INT4,
|
" ipath INT4, \n"
|
||||||
type char(4),
|
" type char(4), \n"
|
||||||
data CHAR(32)
|
" data CHAR(32) \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_timespecTrail (
|
"CREATE TABLE gncKVPvalue_timespecTrail ( \n"
|
||||||
iguid INT4,
|
" iguid INT4, \n"
|
||||||
ipath INT4,
|
" ipath INT4, \n"
|
||||||
type char(4),
|
" type char(4), \n"
|
||||||
data TIMESTAMP
|
" data TIMESTAMP \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_listTrail (
|
"CREATE TABLE gncKVPvalue_listTrail ( \n"
|
||||||
iguid INT4,
|
" iguid INT4, \n"
|
||||||
ipath INT4,
|
" ipath INT4, \n"
|
||||||
type char(4),
|
" type char(4), \n"
|
||||||
data TEXT[]
|
" data TEXT[] \n"
|
||||||
) INHERITS (gncAuditTrail);
|
") INHERITS (gncAuditTrail); \n"
|
||||||
|
" \n"
|
||||||
-- end of file
|
"-- end of file";
|
||||||
|
@ -1,246 +1,246 @@
|
|||||||
--
|
"-- \n"
|
||||||
-- FILE:
|
"-- FILE: \n"
|
||||||
-- table-create.sql
|
"-- table-create.sql \n"
|
||||||
--
|
"-- \n"
|
||||||
-- FUNCTION:
|
"-- FUNCTION: \n"
|
||||||
-- Define the tables needed to initialize a new GnuCash database
|
"-- Define the tables needed to initialize a new GnuCash database \n"
|
||||||
--
|
"-- \n"
|
||||||
-- These tables roughly mirror the c structs in
|
"-- These tables roughly mirror the c structs in \n"
|
||||||
-- TransactionP.h, AccountP.h, gnc-commodity.c
|
"-- TransactionP.h, AccountP.h, gnc-commodity.c \n"
|
||||||
-- Please refer to the C files to get the right level of documentation.
|
"-- Please refer to the C files to get the right level of documentation. \n"
|
||||||
--
|
"-- \n"
|
||||||
-- If these tables are changed or added to, a correspionding
|
"-- If these tables are changed or added to, a correspionding \n"
|
||||||
-- audit-trail table (in table-audit.sql) must be updated as well.
|
"-- audit-trail table (in table-audit.sql) must be updated as well. \n"
|
||||||
--
|
"-- \n"
|
||||||
-- These tables are specifically designed for the
|
"-- These tables are specifically designed for the \n"
|
||||||
-- postgres database server, but are hopefull relatively portable.
|
"-- postgres database server, but are hopefull relatively portable. \n"
|
||||||
--
|
"-- \n"
|
||||||
-- These tables are hand-built, but maybe they should be
|
"-- These tables are hand-built, but maybe they should be \n"
|
||||||
-- auto-built with the m4 macros ...
|
"-- auto-built with the m4 macros ... \n"
|
||||||
--
|
"-- \n"
|
||||||
-- HISTORY:
|
"-- HISTORY: \n"
|
||||||
-- Copyright (C) 2000, 2001 Linas Vepstas
|
"-- Copyright (C) 2000, 2001 Linas Vepstas \n"
|
||||||
--
|
"-- \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncVersion (
|
"CREATE TABLE gncVersion ( \n"
|
||||||
major INT NOT NULL,
|
" major INT NOT NULL, \n"
|
||||||
minor INT NOT NULL,
|
" minor INT NOT NULL, \n"
|
||||||
rev INT DEFAULT '0',
|
" rev INT DEFAULT '0', \n"
|
||||||
name TEXT UNIQUE NOT NULL CHECK (name <> ''),
|
" name TEXT UNIQUE NOT NULL CHECK (name <> ''), \n"
|
||||||
date TIMESTAMP DEFAULT 'NOW'
|
" date TIMESTAMP DEFAULT 'NOW' \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
-- Commodity structure
|
"-- Commodity structure \n"
|
||||||
-- Store currency, security types. Namespace includes
|
"-- Store currency, security types. Namespace includes \n"
|
||||||
-- ISO4217 for currencies, NASDAQ, AMEX, NYSE, EUREX for
|
"-- ISO4217 for currencies, NASDAQ, AMEX, NYSE, EUREX for \n"
|
||||||
-- stocks. See the C documentation for details.
|
"-- stocks. See the C documentation for details. \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncCommodity (
|
"CREATE TABLE gncCommodity ( \n"
|
||||||
commodity TEXT PRIMARY KEY,
|
" commodity TEXT PRIMARY KEY, \n"
|
||||||
fullname TEXT,
|
" fullname TEXT, \n"
|
||||||
namespace TEXT NOT NULL,
|
" namespace TEXT NOT NULL, \n"
|
||||||
mnemonic TEXT NOT NULL,
|
" mnemonic TEXT NOT NULL, \n"
|
||||||
code TEXT,
|
" code TEXT, \n"
|
||||||
fraction INT DEFAULT '100'
|
" fraction INT DEFAULT '100' \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncBook (
|
"CREATE TABLE gncBook ( \n"
|
||||||
bookGuid CHAR(32) PRIMARY KEY,
|
" bookGuid CHAR(32) PRIMARY KEY, \n"
|
||||||
book_open CHAR DEFAULT 'n',
|
" book_open CHAR DEFAULT 'n', \n"
|
||||||
version INT4 NOT NULL,
|
" version INT4 NOT NULL, \n"
|
||||||
iguid INT4 DEFAULT 0
|
" iguid INT4 DEFAULT 0 \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
-- Account structure -- parentGUID points to parent account
|
"-- Account structure -- parentGUID points to parent account \n"
|
||||||
-- guid. There is no supports for Groups in this schema.
|
"-- guid. There is no supports for Groups in this schema. \n"
|
||||||
-- (there seems to be no strong need to have groups in the DB.)
|
"-- (there seems to be no strong need to have groups in the DB.) \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncAccount (
|
"CREATE TABLE gncAccount ( \n"
|
||||||
accountGuid CHAR(32) PRIMARY KEY,
|
" accountGuid CHAR(32) PRIMARY KEY, \n"
|
||||||
parentGuid CHAR(32) NOT NULL,
|
" parentGuid CHAR(32) NOT NULL, \n"
|
||||||
bookGuid CHAR(32) NOT NULL,
|
" bookGuid CHAR(32) NOT NULL, \n"
|
||||||
accountName TEXT NOT NULL CHECK (accountName <> ''),
|
" accountName TEXT NOT NULL CHECK (accountName <> ''), \n"
|
||||||
accountCode TEXT,
|
" accountCode TEXT, \n"
|
||||||
description TEXT,
|
" description TEXT, \n"
|
||||||
type TEXT NOT NULL,
|
" type TEXT NOT NULL, \n"
|
||||||
commodity TEXT NOT NULL CHECK (commodity <>''),
|
" commodity TEXT NOT NULL CHECK (commodity <>''), \n"
|
||||||
version INT4 NOT NULL,
|
" version INT4 NOT NULL, \n"
|
||||||
iguid INT4 DEFAULT 0
|
" iguid INT4 DEFAULT 0 \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
-- CREATE INDEX gncAccount_pg_idx ON gncAccount (parentGuid);
|
"-- CREATE INDEX gncAccount_pg_idx ON gncAccount (parentGuid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncTransaction (
|
"CREATE TABLE gncTransaction ( \n"
|
||||||
transGuid CHAR(32) PRIMARY KEY,
|
" transGuid CHAR(32) PRIMARY KEY, \n"
|
||||||
last_modified TIMESTAMP DEFAULT 'NOW',
|
" last_modified TIMESTAMP DEFAULT 'NOW', \n"
|
||||||
date_entered TIMESTAMP,
|
" date_entered TIMESTAMP, \n"
|
||||||
date_posted TIMESTAMP,
|
" date_posted TIMESTAMP, \n"
|
||||||
num TEXT,
|
" num TEXT, \n"
|
||||||
description TEXT,
|
" description TEXT, \n"
|
||||||
currency TEXT NOT NULL CHECK (currency <> ''),
|
" currency TEXT NOT NULL CHECK (currency <> ''), \n"
|
||||||
version INT4 NOT NULL,
|
" version INT4 NOT NULL, \n"
|
||||||
iguid INT4 DEFAULT 0
|
" iguid INT4 DEFAULT 0 \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
CREATE INDEX gncTransaction_posted_idx ON gncTransaction (date_posted);
|
"CREATE INDEX gncTransaction_posted_idx ON gncTransaction (date_posted); \n"
|
||||||
|
" \n"
|
||||||
-- a gncEntry is what we call 'Split' elsewhere in the engine
|
"-- a gncEntry is what we call 'Split' elsewhere in the engine \n"
|
||||||
-- Here, we call it a 'journal entry'
|
"-- Here, we call it a 'journal entry' \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncEntry (
|
"CREATE TABLE gncEntry ( \n"
|
||||||
entryGuid CHAR(32) PRIMARY KEY,
|
" entryGuid CHAR(32) PRIMARY KEY, \n"
|
||||||
accountGuid CHAR(32) NOT NULL,
|
" accountGuid CHAR(32) NOT NULL, \n"
|
||||||
transGuid CHAR(32) NOT NULL,
|
" transGuid CHAR(32) NOT NULL, \n"
|
||||||
memo TEXT,
|
" memo TEXT, \n"
|
||||||
action TEXT,
|
" action TEXT, \n"
|
||||||
reconciled CHAR DEFAULT 'n',
|
" reconciled CHAR DEFAULT 'n', \n"
|
||||||
date_reconciled TIMESTAMP,
|
" date_reconciled TIMESTAMP, \n"
|
||||||
amount INT8 DEFAULT '0',
|
" amount INT8 DEFAULT '0', \n"
|
||||||
value INT8 DEFAULT '0',
|
" value INT8 DEFAULT '0', \n"
|
||||||
iguid INT4 DEFAULT 0
|
" iguid INT4 DEFAULT 0 \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
CREATE INDEX gncEntry_acc_idx ON gncEntry (accountGuid);
|
"CREATE INDEX gncEntry_acc_idx ON gncEntry (accountGuid); \n"
|
||||||
CREATE INDEX gncEntry_trn_idx ON gncEntry (transGuid);
|
"CREATE INDEX gncEntry_trn_idx ON gncEntry (transGuid); \n"
|
||||||
|
" \n"
|
||||||
-- The checkpoint table provides balance information
|
"-- The checkpoint table provides balance information \n"
|
||||||
-- The balance is provided in the indicated currency;
|
"-- The balance is provided in the indicated currency; \n"
|
||||||
-- this allows the potential of maintaining balance information
|
"-- this allows the potential of maintaining balance information \n"
|
||||||
-- in multiple currencies.
|
"-- in multiple currencies. \n"
|
||||||
-- (e.g. report stock account balances in shares of stock,
|
"-- (e.g. report stock account balances in shares of stock, \n"
|
||||||
-- and in dollars)
|
"-- and in dollars) \n"
|
||||||
-- the 'type' field indicates what type of balance this is
|
"-- the 'type' field indicates what type of balance this is \n"
|
||||||
-- (simple, FIFO, LIFO, or other accounting method)
|
"-- (simple, FIFO, LIFO, or other accounting method) \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncCheckpoint (
|
"CREATE TABLE gncCheckpoint ( \n"
|
||||||
accountGuid CHAR(32) NOT NULL,
|
" accountGuid CHAR(32) NOT NULL, \n"
|
||||||
date_start TIMESTAMP NOT NULL,
|
" date_start TIMESTAMP NOT NULL, \n"
|
||||||
date_end TIMESTAMP NOT NULL,
|
" date_end TIMESTAMP NOT NULL, \n"
|
||||||
commodity TEXT NOT NULL CHECK (commodity <>''),
|
" commodity TEXT NOT NULL CHECK (commodity <>''), \n"
|
||||||
type TEXT DEFAULT 'simple',
|
" type TEXT DEFAULT 'simple', \n"
|
||||||
balance INT8 DEFAULT '0',
|
" balance INT8 DEFAULT '0', \n"
|
||||||
cleared_balance INT8 DEFAULT '0',
|
" cleared_balance INT8 DEFAULT '0', \n"
|
||||||
reconciled_balance INT8 DEFAULT '0',
|
" reconciled_balance INT8 DEFAULT '0', \n"
|
||||||
|
" \n"
|
||||||
PRIMARY KEY (accountGuid, date_start, commodity)
|
" PRIMARY KEY (accountGuid, date_start, commodity) \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
-- The price table stores the price of 'commodity' valued
|
"-- The price table stores the price of 'commodity' valued \n"
|
||||||
-- in units of 'currency'
|
"-- in units of 'currency' \n"
|
||||||
CREATE TABLE gncPrice (
|
"CREATE TABLE gncPrice ( \n"
|
||||||
priceGuid CHAR(32) PRIMARY KEY,
|
" priceGuid CHAR(32) PRIMARY KEY, \n"
|
||||||
commodity TEXT NOT NULL CHECK (commodity <>''),
|
" commodity TEXT NOT NULL CHECK (commodity <>''), \n"
|
||||||
currency TEXT NOT NULL CHECK (commodity <>''),
|
" currency TEXT NOT NULL CHECK (commodity <>''), \n"
|
||||||
time TIMESTAMP,
|
" time TIMESTAMP, \n"
|
||||||
source TEXT,
|
" source TEXT, \n"
|
||||||
type TEXT,
|
" type TEXT, \n"
|
||||||
valueNum INT8 DEFAULT '0',
|
" valueNum INT8 DEFAULT '0', \n"
|
||||||
valueDenom INT4 DEFAULT '100',
|
" valueDenom INT4 DEFAULT '100', \n"
|
||||||
version INT4 NOT NULL,
|
" version INT4 NOT NULL, \n"
|
||||||
bookGuid CHAR(32) NOT NULL
|
" bookGuid CHAR(32) NOT NULL \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
|
" \n"
|
||||||
-- The session directory serves several purposes. First and formost,
|
"-- The session directory serves several purposes. First and formost, \n"
|
||||||
-- it notes the database access type. There are three modes:
|
"-- it notes the database access type. There are three modes: \n"
|
||||||
-- o 'Single User' -- Only one user can have access to the database
|
"-- o 'Single User' -- Only one user can have access to the database \n"
|
||||||
-- at a time.
|
"-- at a time. \n"
|
||||||
-- o 'Multi-User Polled' -- multiple users
|
"-- o 'Multi-User Polled' -- multiple users \n"
|
||||||
-- o 'Muilti-User Event Driven'
|
"-- o 'Muilti-User Event Driven' \n"
|
||||||
-- See Design.txt for more info.
|
"-- See Design.txt for more info. \n"
|
||||||
-- Note that a client can lie about its identity, sign-on time, etc.
|
"-- Note that a client can lie about its identity, sign-on time, etc. \n"
|
||||||
-- so these records aren't really sufficient for a true audit.
|
"-- so these records aren't really sufficient for a true audit. \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncSession (
|
"CREATE TABLE gncSession ( \n"
|
||||||
sessionGuid CHAR(32) PRIMARY KEY,
|
" sessionGuid CHAR(32) PRIMARY KEY, \n"
|
||||||
session_mode CHAR(16) NOT NULL,
|
" session_mode CHAR(16) NOT NULL, \n"
|
||||||
hostname TEXT,
|
" hostname TEXT, \n"
|
||||||
login_name TEXT,
|
" login_name TEXT, \n"
|
||||||
gecos TEXT,
|
" gecos TEXT, \n"
|
||||||
time_on TIMESTAMP NOT NULL,
|
" time_on TIMESTAMP NOT NULL, \n"
|
||||||
time_off TIMESTAMP NOT NULL DEFAULT 'INFINITY'
|
" time_off TIMESTAMP NOT NULL DEFAULT 'INFINITY' \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
|
" \n"
|
||||||
-- The kvp path-cache replaces a long path name with a single unique
|
"-- The kvp path-cache replaces a long path name with a single unique \n"
|
||||||
-- number. The guid-cache replaces a 32-byte guid with a shorter
|
"-- number. The guid-cache replaces a 32-byte guid with a shorter \n"
|
||||||
-- 4-byte identifier. The KVP Value table stores the actual values.
|
"-- 4-byte identifier. The KVP Value table stores the actual values. \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncPathCache (
|
"CREATE TABLE gncPathCache ( \n"
|
||||||
ipath SERIAL PRIMARY KEY,
|
" ipath SERIAL PRIMARY KEY, \n"
|
||||||
path TEXT
|
" path TEXT \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
CREATE SEQUENCE gnc_iguid_seq START 1;
|
"CREATE SEQUENCE gnc_iguid_seq START 1; \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue (
|
"CREATE TABLE gncKVPvalue ( \n"
|
||||||
iguid INT4,
|
" iguid INT4, \n"
|
||||||
ipath INT4,
|
" ipath INT4, \n"
|
||||||
type char(4),
|
" type char(4), \n"
|
||||||
|
" \n"
|
||||||
PRIMARY KEY (iguid, ipath)
|
" PRIMARY KEY (iguid, ipath) \n"
|
||||||
);
|
"); \n"
|
||||||
|
" \n"
|
||||||
-- CREATE INDEX gncKVPvalue_iguid_idx ON gncKVPvalue (iguid);
|
"-- CREATE INDEX gncKVPvalue_iguid_idx ON gncKVPvalue (iguid); \n"
|
||||||
|
" \n"
|
||||||
-- Add primary keys to each kvp table ... because key inheritance
|
"-- Add primary keys to each kvp table ... because key inheritance \n"
|
||||||
-- is ambiguously defined and thus not implemented in postgres.
|
"-- is ambiguously defined and thus not implemented in postgres. \n"
|
||||||
-- Note, however, adding these keys degrades performance by 20%
|
"-- Note, however, adding these keys degrades performance by 20% \n"
|
||||||
-- (even after a vacuum analyze), and adding indexes degrades
|
"-- (even after a vacuum analyze), and adding indexes degrades \n"
|
||||||
-- an additional 15% !! I find this result surprising, so I
|
"-- an additional 15% !! I find this result surprising, so I \n"
|
||||||
-- simply leave these commented out ... (as of postgres 7.1.2)
|
"-- simply leave these commented out ... (as of postgres 7.1.2) \n"
|
||||||
-- Note, indexex on the main, non-inherited tables *are* important
|
"-- Note, indexex on the main, non-inherited tables *are* important \n"
|
||||||
-- for ensuring good performance, so this effect seems to be related
|
"-- for ensuring good performance, so this effect seems to be related \n"
|
||||||
-- to inheritance
|
"-- to inheritance \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_int64 (
|
"CREATE TABLE gncKVPvalue_int64 ( \n"
|
||||||
data INT8
|
" data INT8 \n"
|
||||||
-- PRIMARY KEY (iguid, ipath)
|
"-- PRIMARY KEY (iguid, ipath) \n"
|
||||||
) INHERITS (gncKVPvalue);
|
") INHERITS (gncKVPvalue); \n"
|
||||||
|
" \n"
|
||||||
-- CREATE INDEX gncKVPvalue_int64_iguid_idx ON gncKVPvalue_int64 (iguid);
|
"-- CREATE INDEX gncKVPvalue_int64_iguid_idx ON gncKVPvalue_int64 (iguid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_dbl (
|
"CREATE TABLE gncKVPvalue_dbl ( \n"
|
||||||
data FLOAT8
|
" data FLOAT8 \n"
|
||||||
-- PRIMARY KEY (iguid, ipath)
|
"-- PRIMARY KEY (iguid, ipath) \n"
|
||||||
) INHERITS (gncKVPvalue);
|
") INHERITS (gncKVPvalue); \n"
|
||||||
|
" \n"
|
||||||
-- CREATE INDEX gncKVPvalue_dbl_iguid_idx ON gncKVPvalue_dbl (iguid);
|
"-- CREATE INDEX gncKVPvalue_dbl_iguid_idx ON gncKVPvalue_dbl (iguid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_numeric (
|
"CREATE TABLE gncKVPvalue_numeric ( \n"
|
||||||
num INT8,
|
" num INT8, \n"
|
||||||
denom INT8
|
" denom INT8 \n"
|
||||||
-- PRIMARY KEY (iguid, ipath)
|
"-- PRIMARY KEY (iguid, ipath) \n"
|
||||||
) INHERITS (gncKVPvalue);
|
") INHERITS (gncKVPvalue); \n"
|
||||||
|
" \n"
|
||||||
-- CREATE INDEX gncKVPvalue_numeric_iguid_idx ON gncKVPvalue_numeric (iguid);
|
"-- CREATE INDEX gncKVPvalue_numeric_iguid_idx ON gncKVPvalue_numeric (iguid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_str (
|
"CREATE TABLE gncKVPvalue_str ( \n"
|
||||||
data TEXT
|
" data TEXT \n"
|
||||||
-- PRIMARY KEY (iguid, ipath)
|
"-- PRIMARY KEY (iguid, ipath) \n"
|
||||||
) INHERITS (gncKVPvalue);
|
") INHERITS (gncKVPvalue); \n"
|
||||||
|
" \n"
|
||||||
-- CREATE INDEX gncKVPvalue_str_iguid_idx ON gncKVPvalue_str (iguid);
|
"-- CREATE INDEX gncKVPvalue_str_iguid_idx ON gncKVPvalue_str (iguid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_guid (
|
"CREATE TABLE gncKVPvalue_guid ( \n"
|
||||||
data CHAR(32)
|
" data CHAR(32) \n"
|
||||||
-- PRIMARY KEY (iguid, ipath)
|
"-- PRIMARY KEY (iguid, ipath) \n"
|
||||||
) INHERITS (gncKVPvalue);
|
") INHERITS (gncKVPvalue); \n"
|
||||||
|
" \n"
|
||||||
-- CREATE INDEX gncKVPvalue_guid_iguid_idx ON gncKVPvalue_guid (iguid);
|
"-- CREATE INDEX gncKVPvalue_guid_iguid_idx ON gncKVPvalue_guid (iguid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_timespec (
|
"CREATE TABLE gncKVPvalue_timespec ( \n"
|
||||||
data TIMESTAMP
|
" data TIMESTAMP \n"
|
||||||
-- PRIMARY KEY (iguid, ipath)
|
"-- PRIMARY KEY (iguid, ipath) \n"
|
||||||
) INHERITS (gncKVPvalue);
|
") INHERITS (gncKVPvalue); \n"
|
||||||
|
" \n"
|
||||||
-- CREATE INDEX gncKVPvalue_timespec_iguid_idx ON gncKVPvalue_timespec (iguid);
|
"-- CREATE INDEX gncKVPvalue_timespec_iguid_idx ON gncKVPvalue_timespec (iguid); \n"
|
||||||
|
" \n"
|
||||||
CREATE TABLE gncKVPvalue_list (
|
"CREATE TABLE gncKVPvalue_list ( \n"
|
||||||
data TEXT[]
|
" data TEXT[] \n"
|
||||||
-- PRIMARY KEY (iguid, ipath)
|
"-- PRIMARY KEY (iguid, ipath) \n"
|
||||||
) INHERITS (gncKVPvalue);
|
") INHERITS (gncKVPvalue); \n"
|
||||||
|
" \n"
|
||||||
-- CREATE INDEX gncKVPvalue_list_iguid_idx ON gncKVPvalue_list (iguid);
|
"-- CREATE INDEX gncKVPvalue_list_iguid_idx ON gncKVPvalue_list (iguid); \n"
|
||||||
|
" \n"
|
||||||
-- end of file
|
"-- end of file";
|
||||||
|
@ -1,26 +1,26 @@
|
|||||||
--
|
"-- \n"
|
||||||
-- FILE:
|
"-- FILE: \n"
|
||||||
-- table-drop.sql
|
"-- table-drop.sql \n"
|
||||||
--
|
"-- \n"
|
||||||
-- FUNCTION:
|
"-- FUNCTION: \n"
|
||||||
-- Drop the tables needed to run GnuCash database
|
"-- Drop the tables needed to run GnuCash database \n"
|
||||||
|
" \n"
|
||||||
|
" \n"
|
||||||
DROP TABLE gncCommodity;
|
"DROP TABLE gncCommodity; \n"
|
||||||
DROP TABLE gncAccount;
|
"DROP TABLE gncAccount; \n"
|
||||||
DROP TABLE gncTransaction;
|
"DROP TABLE gncTransaction; \n"
|
||||||
DROP TABLE gncEntry;
|
"DROP TABLE gncEntry; \n"
|
||||||
DROP TABLE gncCheckpoint;
|
"DROP TABLE gncCheckpoint; \n"
|
||||||
DROP TABLE gncSession;
|
"DROP TABLE gncSession; \n"
|
||||||
--
|
"-- \n"
|
||||||
DROP TABLE gncPathCache;
|
"DROP TABLE gncPathCache; \n"
|
||||||
DROP TABLE gncGUIDCache;
|
"DROP TABLE gncGUIDCache; \n"
|
||||||
DROP TABLE gncKVPvalue;
|
"DROP TABLE gncKVPvalue; \n"
|
||||||
DROP TABLE gncKVPvalue_int64;
|
"DROP TABLE gncKVPvalue_int64; \n"
|
||||||
DROP TABLE gncKVPvalue_dbl;
|
"DROP TABLE gncKVPvalue_dbl; \n"
|
||||||
DROP TABLE gncKVPvalue_numeric;
|
"DROP TABLE gncKVPvalue_numeric; \n"
|
||||||
DROP TABLE gncKVPvalue_str;
|
"DROP TABLE gncKVPvalue_str; \n"
|
||||||
DROP TABLE gncKVPvalue_guid;
|
"DROP TABLE gncKVPvalue_guid; \n"
|
||||||
DROP TABLE gncKVPvalue_timespec;
|
"DROP TABLE gncKVPvalue_timespec; \n"
|
||||||
DROP TABLE gncKVPvalue_list;
|
"DROP TABLE gncKVPvalue_list; \n"
|
||||||
DROP TABLE gncKVPvalue_frame;
|
"DROP TABLE gncKVPvalue_frame;";
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
--
|
"-- \n"
|
||||||
-- FILE:
|
"-- FILE: \n"
|
||||||
-- table-version.sql
|
"-- table-version.sql \n"
|
||||||
--
|
"-- \n"
|
||||||
-- FUNCTION:
|
"-- FUNCTION: \n"
|
||||||
-- Insert the latest version information into the gncVersion table.
|
"-- Insert the latest version information into the gncVersion table. \n"
|
||||||
--
|
"-- \n"
|
||||||
-- Inserting in the same query as creating the table does not
|
"-- Inserting in the same query as creating the table does not \n"
|
||||||
-- work under Postgres 7.0
|
"-- work under Postgres 7.0 \n"
|
||||||
--
|
"-- \n"
|
||||||
-- HISTORY:
|
"-- HISTORY: \n"
|
||||||
-- Copyright (C) 2001 Linux Developers Group
|
"-- Copyright (C) 2001 Linux Developers Group \n"
|
||||||
--
|
"-- \n"
|
||||||
|
" \n"
|
||||||
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,0,0,'Version Table');
|
"INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,0,0,'Version Table'); \n"
|
||||||
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,1,1,'iGUID in Main Tables');
|
"INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,1,1,'iGUID in Main Tables'); \n"
|
||||||
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,2,1,'Fix gncSubtotalReconedBalance');
|
"INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,2,1,'Fix gncSubtotalReconedBalance'); \n"
|
||||||
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,3,1,'Add kvp_timespec tables');
|
"INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,3,1,'Add kvp_timespec tables'); \n"
|
||||||
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,4,1,'Add support for multiple books');
|
"INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,4,1,'Add support for multiple books');";
|
||||||
|
@ -3,30 +3,35 @@
|
|||||||
EXIT_VALUE=0
|
EXIT_VALUE=0
|
||||||
|
|
||||||
PATH=/usr/lib/postgresql/bin:$PATH
|
PATH=/usr/lib/postgresql/bin:$PATH
|
||||||
|
PGCTL=`which pg_ctl 2> /dev/null`
|
||||||
|
|
||||||
DB=$PWD/gnc_test_db
|
DB=$PWD/gnc_test_db
|
||||||
SOCKDIR=$PWD/gnc_test_db_sock
|
SOCKDIR=$PWD/gnc_test_db_sock
|
||||||
SOCKNUM=7777
|
SOCKNUM=7777
|
||||||
|
|
||||||
|
|
||||||
# I couldn't get this to work -- the shell seems to think "'-k" is an
|
# I couldn't get this to work -- the shell seems to think "'-k" is an
|
||||||
# argument after it finishes expanding ${PG_CTL}...
|
# argument after it finishes expanding ${PG_CTL}...
|
||||||
# PG_CTL="pg_ctl -D "${DB}" -o '-k ${SOCKDIR} -p ${SOCKNUM}'"
|
# PG_CTL="pg_ctl -D "${DB}" -o '-k ${SOCKDIR} -p ${SOCKNUM}'"
|
||||||
|
|
||||||
our_pg_ctl ()
|
our_pg_ctl ()
|
||||||
{
|
{
|
||||||
|
if [ ${PGCTL}X == X ]; then
|
||||||
|
exit -1
|
||||||
|
fi
|
||||||
pg_ctl -D "${DB}" -o "-k ${SOCKDIR} -p ${SOCKNUM}" "$@";
|
pg_ctl -D "${DB}" -o "-k ${SOCKDIR} -p ${SOCKNUM}" "$@";
|
||||||
}
|
}
|
||||||
|
|
||||||
case $1 in
|
case $1 in
|
||||||
create)
|
create)
|
||||||
our_pg_ctl status | grep "pid" && our_pg_ctl stop && sleep 1
|
our_pg_ctl status | grep "pid" && our_pg_ctl stop && sleep 1 || exit -1
|
||||||
rm -rf ${DB}
|
rm -rf ${DB}
|
||||||
rm -rf ${SOCKDIR}
|
rm -rf ${SOCKDIR}
|
||||||
initdb ${DB} || EXIT_VALUE=1
|
initdb ${DB} || EXIT_VALUE=1
|
||||||
mkdir ${SOCKDIR} || EXIT_VALUE=1
|
mkdir ${SOCKDIR} || EXIT_VALUE=1
|
||||||
;;
|
;;
|
||||||
destroy)
|
destroy)
|
||||||
our_pg_ctl status | grep "pid" && our_pg_ctl stop && sleep 1
|
our_pg_ctl status | grep "pid" && our_pg_ctl stop && sleep 1 || exit -1
|
||||||
rm -rf ${DB}
|
rm -rf ${DB}
|
||||||
rm -rf ${SOCKDIR}
|
rm -rf ${SOCKDIR}
|
||||||
;;
|
;;
|
||||||
@ -34,13 +39,13 @@ case $1 in
|
|||||||
our_pg_ctl start
|
our_pg_ctl start
|
||||||
;;
|
;;
|
||||||
stop)
|
stop)
|
||||||
pg_ctl -D ${DB} -o '-k ${SOCKDIR} -p 7777' stop
|
pg_ctl -D ${DB} -o '-k ${SOCKDIR} -p 7777' stop || exit -1
|
||||||
;;
|
;;
|
||||||
status)
|
status)
|
||||||
our_pg_ctl status
|
our_pg_ctl status
|
||||||
;;
|
;;
|
||||||
connect)
|
connect)
|
||||||
our_pg_ctl status | grep "not running" && our_pg_ctl start && sleep 1
|
our_pg_ctl status | grep "not running" && our_pg_ctl start && sleep 1 || exit -1
|
||||||
psql -h ${SOCKDIR} -p ${SOCKNUM} $2
|
psql -h ${SOCKDIR} -p ${SOCKNUM} $2
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
|
@ -2,17 +2,25 @@
|
|||||||
|
|
||||||
EXIT_VALUE=0
|
EXIT_VALUE=0
|
||||||
|
|
||||||
rm -f test_file_*
|
|
||||||
./db-control.sh create
|
|
||||||
|
|
||||||
./db-control.sh start
|
|
||||||
# .libs/test-db || EXIT_VALUE=1
|
# .libs/test-db || EXIT_VALUE=1
|
||||||
# gdb .libs/test-db
|
# gdb .libs/test-db
|
||||||
./test-db || EXIT_VALUE=1
|
|
||||||
./db-control.sh stop
|
rm -f test_file_*
|
||||||
|
if ./db-control.sh create; then
|
||||||
|
./db-control.sh start
|
||||||
|
./test-db localhost 7777 || EXIT_VALUE=1
|
||||||
|
./db-control.sh stop
|
||||||
|
./db-control.sh destroy
|
||||||
|
elif [ "${PGHOST}X" != "X" ]; then
|
||||||
|
# This expects the logged in user to have authority
|
||||||
|
# to create databases.
|
||||||
|
if [ "${PGPORT}X" == "X" ]; then
|
||||||
|
export PGPORT=5432
|
||||||
|
fi
|
||||||
|
./test-db $PGHOST $PGPORT || EXIT_VALUE=1
|
||||||
|
fi
|
||||||
|
|
||||||
if test $EXIT_VALUE != 0; then exit $EXIT_VALUE; fi
|
if test $EXIT_VALUE != 0; then exit $EXIT_VALUE; fi
|
||||||
|
|
||||||
./db-control.sh destroy
|
|
||||||
|
|
||||||
exit $EXIT_VALUE
|
exit $EXIT_VALUE
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user