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:
Derek Atkins 2003-01-30 04:06:38 +00:00
parent bd57bf6706
commit eb3c5eb238
14 changed files with 2201 additions and 2085 deletions

View File

@ -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>
* src/report/standard-reports/cash-flow.scm: only asset accounts

View File

@ -108,8 +108,6 @@ $(M4_SRC): table.m4
m4 -I ${srcdir} $< > $@
.sql.c:
echo \" > $@
echo "-- DO NOT EDIT THIS FILE. IT IS AUTOGENERATED." >> $@
echo "\"-- DO NOT EDIT THIS FILE. IT IS AUTOGENERATED.\"" > $@
cat $< >> $@
echo \" >> $@

View File

@ -1473,7 +1473,6 @@ pgend_session_end (Backend *bend)
* the poll & event style load, where only the accounts,
* and never the transactions, need to be loaded.
*/
static void
pgend_book_load_poll (Backend *bend, GNCBook *book)
{
@ -1493,12 +1492,20 @@ pgend_book_load_poll (Backend *bend, GNCBook *book)
if (be->blist)
{
/* 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);
be->blist = NULL;
}
pgend_set_book (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);
@ -2246,13 +2253,13 @@ pgend_session_begin (Backend *backend,
{
case MODE_SINGLE_FILE:
pgendEnable(be);
be->be.load = pgend_do_load_single;
be->be.begin = pgend_do_begin;
be->be.commit = pgend_do_commit;
be->be.rollback = pgend_do_rollback;
be->be.load = pgend_do_load_single;
be->be.begin = pgend_do_begin;
be->be.commit = pgend_do_commit;
be->be.rollback = pgend_do_rollback;
be->be.compile_query = NULL;
be->be.free_query = NULL;
be->be.compile_query = NULL;
be->be.free_query = NULL;
be->be.run_query = NULL;
be->be.price_lookup = NULL;
@ -2268,15 +2275,14 @@ pgend_session_begin (Backend *backend,
case MODE_SINGLE_UPDATE:
pgendEnable(be);
be->be.load = pgend_do_load_single;
be->be.begin = pgend_do_begin;
be->be.commit = pgend_do_commit;
be->be.rollback = pgend_do_rollback;
be->be.compile_query = NULL;
be->be.free_query = NULL;
be->be.run_query = NULL;
be->be.price_lookup = NULL;
be->be.load = pgend_do_load_single;
be->be.begin = pgend_do_begin;
be->be.commit = pgend_do_commit;
be->be.rollback = pgend_do_rollback;
be->be.compile_query = NULL;
be->be.free_query = NULL;
be->be.run_query = NULL;
be->be.price_lookup = NULL;
be->be.sync = pgendDoSync;
be->be.export = NULL;
@ -2290,13 +2296,13 @@ pgend_session_begin (Backend *backend,
case MODE_POLL:
pgendEnable(be);
be->be.load = pgend_book_load_poll;
be->be.load = pgend_book_load_poll;
be->be.begin = pgend_do_begin;
be->be.commit = pgend_do_commit;
be->be.rollback = pgend_do_rollback;
be->be.compile_query = pgendCompileQuery;
be->be.free_query = pgendFreeQuery;
be->be.compile_query = pgendCompileQuery;
be->be.free_query = pgendFreeQuery;
be->be.run_query = pgendRunQuery;
be->be.price_lookup = pgendPriceFind;
@ -2317,21 +2323,21 @@ pgend_session_begin (Backend *backend,
pgendSessionGetPid (be);
pgendSessionSetupNotifies (be);
be->be.load = pgend_book_load_poll;
be->be.begin = pgend_do_begin;
be->be.commit = pgend_do_commit;
be->be.rollback = pgend_do_rollback;
be->be.load = pgend_book_load_poll;
be->be.begin = pgend_do_begin;
be->be.commit = pgend_do_commit;
be->be.rollback = pgend_do_rollback;
be->be.compile_query = pgendCompileQuery;
be->be.free_query = pgendFreeQuery;
be->be.run_query = pgendRunQuery;
be->be.price_lookup = pgendPriceFind;
be->be.compile_query = pgendCompileQuery;
be->be.free_query = pgendFreeQuery;
be->be.run_query = pgendRunQuery;
be->be.price_lookup = pgendPriceFind;
be->be.sync = pgendDoSync;
be->be.export = NULL;
be->be.percentage = NULL;
be->be.events_pending = pgendEventsPending;
be->be.process_events = pgendProcessEvents;
be->be.sync = pgendDoSync;
be->be.export = NULL;
be->be.percentage = NULL;
be->be.events_pending = pgendEventsPending;
be->be.process_events = pgendProcessEvents;
PWARN ("mode=multi-user is beta -- \n"
"we've fixed all known bugs but that doesn't mean\n"

View File

@ -1,69 +1,69 @@
--
-- 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), TIMESTAMP, TIMESTAMP)
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'
LANGUAGE 'sql';
CREATE FUNCTION gncSubtotalClearedBalance (CHAR(32), TIMESTAMP, TIMESTAMP)
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 <> \\'n\\''
LANGUAGE 'sql';
CREATE FUNCTION gncSubtotalReconedBalance (CHAR(32), TIMESTAMP, TIMESTAMP)
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';
-- 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
"-- \n"
"-- FILE: \n"
"-- functions.sql \n"
"-- \n"
"-- FUNCTION: \n"
"-- Define assorted utility functions. \n"
"-- \n"
"-- HISTORY: \n"
"-- Copyright (C) 2001 Linas Vepstas \n"
"-- \n"
" \n"
" \n"
"-- utility functions to compute checkpoint balance subtotals \n"
" \n"
"CREATE FUNCTION gncSubtotalBalance (CHAR(32), TIMESTAMP, TIMESTAMP) \n"
" RETURNS INT8 \n"
" AS 'SELECT INT8(sum(gncEntry.amount)) \n"
" FROM gncEntry, gncTransaction \n"
" WHERE \n"
" gncEntry.accountGuid = $1 AND \n"
" gncEntry.transGuid = gncTransaction.transGuid AND \n"
" gncTransaction.date_posted BETWEEN $2 AND $3' \n"
" LANGUAGE 'sql'; \n"
" \n"
"CREATE FUNCTION gncSubtotalClearedBalance (CHAR(32), TIMESTAMP, TIMESTAMP) \n"
" RETURNS INT8 \n"
" AS 'SELECT INT8(sum(gncEntry.amount)) \n"
" FROM gncEntry, gncTransaction \n"
" WHERE \n"
" gncEntry.accountGuid = $1 AND \n"
" gncEntry.transGuid = gncTransaction.transGuid AND \n"
" gncTransaction.date_posted BETWEEN $2 AND $3 AND \n"
" gncEntry.reconciled <> \\'n\\'' \n"
" LANGUAGE 'sql'; \n"
" \n"
"CREATE FUNCTION gncSubtotalReconedBalance (CHAR(32), TIMESTAMP, TIMESTAMP) \n"
" RETURNS INT8 \n"
" AS 'SELECT INT8(sum(gncEntry.amount)) \n"
" FROM gncEntry, gncTransaction \n"
" WHERE \n"
" gncEntry.accountGuid = $1 AND \n"
" gncEntry.transGuid = gncTransaction.transGuid AND \n"
" gncTransaction.date_posted BETWEEN $2 AND $3 AND \n"
" (gncEntry.reconciled = \\'y\\' OR \n"
" gncEntry.reconciled = \\'f\\')' \n"
" LANGUAGE 'sql'; \n"
" \n"
"-- helper functions. These intentionally use the 'wrong' fraction. \n"
"-- This is because value_frac * amount * price = value * amount_frac \n"
" \n"
"CREATE FUNCTION gncHelperPrVal (gncEntry) \n"
" RETURNS INT8 \n"
" AS 'SELECT abs($1 . value * gncCommodity.fraction) \n"
" FROM gncEntry, gncAccount, gncCommodity \n"
" WHERE \n"
" $1 . accountGuid = gncAccount.accountGuid AND \n"
" gncAccount.commodity = gncCommodity.commodity' \n"
" LANGUAGE 'sql'; \n"
" \n"
"CREATE FUNCTION gncHelperPrAmt (gncEntry) \n"
" RETURNS INT8 \n"
" AS 'SELECT abs($1 . amount * gncCommodity.fraction) \n"
" FROM gncEntry, gncTransaction, gncCommodity \n"
" WHERE \n"
" $1 . transGuid = gncTransaction.transGuid AND \n"
" gncTransaction.currency = gncCommodity.commodity' \n"
" LANGUAGE 'sql'; \n"
" \n"
"-- end of file";

File diff suppressed because it is too large Load Diff

View File

@ -286,7 +286,7 @@ store_cb (const char *key, kvp_value *val, gpointer p)
case KVP_TYPE_TIMESPEC:
{
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);
pgendPutOneKVPtimespecOnly (be, cb_data);
}

View File

@ -108,30 +108,30 @@ int finishQuery(PGBackend *be);
* discarded (only error conditions are checked for).
*/
#define FINISH_QUERY(conn) \
{ \
int i=0; \
PGresult *result; \
/* complete/commit the transaction, check the status */ \
do { \
#define FINISH_QUERY(conn) \
{ \
int i=0; \
PGresult *result; \
/* complete/commit the transaction, check the status */ \
do { \
gchar *msg = NULL; \
ExecStatusType status; \
result = PQgetResult((conn)); \
if (!result) break; \
PINFO ("clearing result %d", i); \
status = PQresultStatus(result); \
if (PGRES_COMMAND_OK != status) { \
PERR("finish query failed:\n" \
"\t%s", PQerrorMessage((conn))); \
PQclear(result); \
xaccBackendSetMessage (&be->be, msg); \
ExecStatusType status; \
result = PQgetResult((conn)); \
if (!result) break; \
PINFO ("clearing result %d", i); \
status = PQresultStatus(result); \
if (PGRES_COMMAND_OK != status) { \
msg = PQresultErrorMessage(result); \
PERR("finish query failed:\n\t%s", msg); \
PQclear(result); \
xaccBackendSetMessage (&be->be, msg); \
xaccBackendSetError (&be->be, ERR_BACKEND_SERVER_ERR); \
break; \
} \
PQclear(result); \
i++; \
} while (result); \
}
break; \
} \
PQclear(result); \
i++; \
} while (result); \
} \
/* --------------------------------------------------------------- */
/* The GET_RESULTS macro grabs the result of an pgSQL query off the

View File

@ -1,174 +1,174 @@
--
-- FILE:
-- table-audit.sql
--
-- FUNCTION:
-- Define the audit trail tables
-- Note that these tables must be kept manually in sync with those
-- in table-create.sql
--
-- HISTORY:
-- Copyright (C) 2000, 2001 Linas Vepstas
--
-- The change field may be 'a' -- add, 'd' -- delete/drop, 'm' -- modify
--
-- The objtype field may be 'a' -- account, 'c' -- commodity, 'e' -- entry,
-- 'k' -- kvp, 'p' -- price, 't' -- transaction
--
-- The objtype is the class type of the child class.
--
-- Note that SQL is only partially object-oriented. Thus, we use the
-- gncAuditTrail table to define the parent class; the children inherit
-- from it. Since SQL doesn't tell the parent who the child was, we use
-- the 'objtype' field to store the class type of the child.
--
-- Thus, we should really enforce a constraint on this field:
-- CREATE TABLE gncAccountTrail (
-- objtype CHAR NOT NULL CHECK (objtype == 'a')
-- and so on.
CREATE TABLE gncAuditTrail (
sessionGuid CHAR(32) NOT NULL, -- who changed it
date_changed TIMESTAMP, -- when they changed it
change CHAR NOT NULL,
objtype CHAR NOT NULL
);
-- would love to inherit, but can't because this wrecks the primary key
CREATE TABLE gncAccountTrail (
accountGuid CHAR(32) NOT NULL, -- override, not a primary key anymore
parentGuid CHAR(32) NOT NULL,
bookGuid CHAR(32) NOT NULL,
accountName TEXT NOT NULL CHECK (accountName <> ''),
accountCode TEXT,
description TEXT,
type TEXT NOT NULL,
commodity TEXT NOT NULL CHECK (commodity <>''),
version INT4 NOT NULL,
iguid INT4 DEFAULT 0
) INHERITS (gncAuditTrail);
CREATE INDEX gncAccountTrail_account_idx ON gncAccountTrail (accountGuid);
CREATE TABLE gncBookTrail (
bookGuid CHAR(32) NOT NULL,
book_open CHAR DEFAULT 'n',
version INT4 NOT NULL,
iguid INT4 DEFAULT 0
) INHERITS (gncAuditTrail);
CREATE INDEX gncBookTrail_book_idx ON gncBookTrail (bookGuid);
CREATE TABLE gncCommodityTrail (
commodity TEXT NOT NULL, -- override, not a primary key anymore
fullname TEXT,
namespace TEXT NOT NULL,
mnemonic TEXT NOT NULL,
code TEXT,
fraction INT DEFAULT '100'
) INHERITS (gncAuditTrail);
CREATE INDEX gncCommodityTrail_commodity_idx ON gncCommodityTrail (commodity);
CREATE TABLE gncEntryTrail (
entryGuid CHAR(32) NOT NULL, -- override, not a primary key anymore
accountGuid CHAR(32) NOT NULL,
transGuid CHAR(32) NOT NULL,
memo TEXT,
action TEXT,
reconciled CHAR DEFAULT 'n',
date_reconciled TIMESTAMP,
amount INT8 DEFAULT '0',
value INT8 DEFAULT '0',
iguid INT4 DEFAULT 0
) INHERITS (gncAuditTrail);
CREATE INDEX gncEntryTrail_entry_idx ON gncEntryTrail (entryGuid);
CREATE TABLE gncPriceTrail (
priceGuid CHAR(32) NOT NULL, -- override, not a primary key anymore
commodity TEXT NOT NULL CHECK (commodity <>''),
currency TEXT NOT NULL CHECK (commodity <>''),
time TIMESTAMP,
source TEXT,
type TEXT,
valueNum INT8 DEFAULT '0',
valueDenom INT4 DEFAULT '100',
version INT4 NOT NULL,
bookGuid CHAR(32) NOT NULL
) INHERITS (gncAuditTrail);
CREATE INDEX gncPriceTrail_price_idx ON gncPriceTrail (priceGuid);
CREATE TABLE gncTransactionTrail (
transGuid CHAR(32) NOT NULL, -- override, not a primary key anymore
last_modified TIMESTAMP DEFAULT 'NOW',
date_entered TIMESTAMP,
date_posted TIMESTAMP,
num TEXT,
description TEXT,
currency TEXT NOT NULL CHECK (currency <> ''),
version INT4 NOT NULL,
iguid INT4 DEFAULT 0
) INHERITS (gncAuditTrail);
CREATE INDEX gncTransactionTrail_trans_idx ON gncTransactionTrail (transGuid);
CREATE TABLE gncKVPvalueTrail (
iguid INT4,
ipath INT4,
type char(4)
) INHERITS (gncAuditTrail);
CREATE TABLE gncKVPvalue_int64Trail (
iguid INT4,
ipath INT4,
type char(4),
data INT8
) INHERITS (gncAuditTrail);
CREATE TABLE gncKVPvalue_dblTrail (
iguid INT4,
ipath INT4,
type char(4),
data FLOAT8
) INHERITS (gncAuditTrail);
CREATE TABLE gncKVPvalue_numericTrail (
iguid INT4,
ipath INT4,
type char(4),
num INT8,
denom INT8
) INHERITS (gncAuditTrail);
CREATE TABLE gncKVPvalue_strTrail (
iguid INT4,
ipath INT4,
type char(4),
data TEXT
) INHERITS (gncAuditTrail);
CREATE TABLE gncKVPvalue_guidTrail (
iguid INT4,
ipath INT4,
type char(4),
data CHAR(32)
) INHERITS (gncAuditTrail);
CREATE TABLE gncKVPvalue_timespecTrail (
iguid INT4,
ipath INT4,
type char(4),
data TIMESTAMP
) INHERITS (gncAuditTrail);
CREATE TABLE gncKVPvalue_listTrail (
iguid INT4,
ipath INT4,
type char(4),
data TEXT[]
) INHERITS (gncAuditTrail);
-- end of file
"-- \n"
"-- FILE: \n"
"-- table-audit.sql \n"
"-- \n"
"-- FUNCTION: \n"
"-- Define the audit trail tables \n"
"-- Note that these tables must be kept manually in sync with those \n"
"-- in table-create.sql \n"
"-- \n"
"-- HISTORY: \n"
"-- Copyright (C) 2000, 2001 Linas Vepstas \n"
"-- \n"
"-- 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, \n"
"-- 'k' -- kvp, 'p' -- price, 't' -- transaction \n"
"-- \n"
"-- The objtype is the class type of the child class. \n"
"-- \n"
"-- Note that SQL is only partially object-oriented. Thus, we use the \n"
"-- 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 \n"
"-- the 'objtype' field to store the class type of the child. \n"
"-- \n"
"-- Thus, we should really enforce a constraint on this field: \n"
"-- CREATE TABLE gncAccountTrail ( \n"
"-- objtype CHAR NOT NULL CHECK (objtype == 'a') \n"
"-- and so on. \n"
" \n"
"CREATE TABLE gncAuditTrail ( \n"
" sessionGuid CHAR(32) NOT NULL, -- who changed it \n"
" date_changed TIMESTAMP, -- when they changed it \n"
" change CHAR NOT NULL, \n"
" objtype CHAR NOT NULL \n"
"); \n"
" \n"
"-- would love to inherit, but can't because this wrecks the primary key \n"
" \n"
"CREATE TABLE gncAccountTrail ( \n"
" accountGuid CHAR(32) NOT NULL, -- override, not a primary key anymore \n"
" parentGuid CHAR(32) NOT NULL, \n"
" bookGuid CHAR(32) NOT NULL, \n"
" accountName TEXT NOT NULL CHECK (accountName <> ''), \n"
" accountCode TEXT, \n"
" description TEXT, \n"
" type TEXT NOT NULL, \n"
" commodity TEXT NOT NULL CHECK (commodity <>''), \n"
" version INT4 NOT NULL, \n"
" iguid INT4 DEFAULT 0 \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE INDEX gncAccountTrail_account_idx ON gncAccountTrail (accountGuid); \n"
" \n"
"CREATE TABLE gncBookTrail ( \n"
" bookGuid CHAR(32) NOT NULL, \n"
" book_open CHAR DEFAULT 'n', \n"
" version INT4 NOT NULL, \n"
" iguid INT4 DEFAULT 0 \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE INDEX gncBookTrail_book_idx ON gncBookTrail (bookGuid); \n"
" \n"
"CREATE TABLE gncCommodityTrail ( \n"
" commodity TEXT NOT NULL, -- override, not a primary key anymore \n"
" fullname TEXT, \n"
" namespace TEXT NOT NULL, \n"
" mnemonic TEXT NOT NULL, \n"
" code TEXT, \n"
" fraction INT DEFAULT '100' \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE INDEX gncCommodityTrail_commodity_idx ON gncCommodityTrail (commodity); \n"
" \n"
"CREATE TABLE gncEntryTrail ( \n"
" entryGuid CHAR(32) NOT NULL, -- override, not a primary key anymore \n"
" accountGuid CHAR(32) NOT NULL, \n"
" transGuid CHAR(32) NOT NULL, \n"
" memo TEXT, \n"
" action TEXT, \n"
" reconciled CHAR DEFAULT 'n', \n"
" date_reconciled TIMESTAMP, \n"
" amount INT8 DEFAULT '0', \n"
" value INT8 DEFAULT '0', \n"
" iguid INT4 DEFAULT 0 \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE INDEX gncEntryTrail_entry_idx ON gncEntryTrail (entryGuid); \n"
" \n"
"CREATE TABLE gncPriceTrail ( \n"
" priceGuid CHAR(32) NOT NULL, -- override, not a primary key anymore \n"
" commodity TEXT NOT NULL CHECK (commodity <>''), \n"
" currency TEXT NOT NULL CHECK (commodity <>''), \n"
" time TIMESTAMP, \n"
" source TEXT, \n"
" type TEXT, \n"
" valueNum INT8 DEFAULT '0', \n"
" valueDenom INT4 DEFAULT '100', \n"
" version INT4 NOT NULL, \n"
" bookGuid CHAR(32) NOT NULL \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE INDEX gncPriceTrail_price_idx ON gncPriceTrail (priceGuid); \n"
" \n"
"CREATE TABLE gncTransactionTrail ( \n"
" transGuid CHAR(32) NOT NULL, -- override, not a primary key anymore \n"
" last_modified TIMESTAMP DEFAULT 'NOW', \n"
" date_entered TIMESTAMP, \n"
" date_posted TIMESTAMP, \n"
" num TEXT, \n"
" description TEXT, \n"
" currency TEXT NOT NULL CHECK (currency <> ''), \n"
" version INT4 NOT NULL, \n"
" iguid INT4 DEFAULT 0 \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE INDEX gncTransactionTrail_trans_idx ON gncTransactionTrail (transGuid); \n"
" \n"
"CREATE TABLE gncKVPvalueTrail ( \n"
" iguid INT4, \n"
" ipath INT4, \n"
" type char(4) \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE TABLE gncKVPvalue_int64Trail ( \n"
" iguid INT4, \n"
" ipath INT4, \n"
" type char(4), \n"
" data INT8 \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE TABLE gncKVPvalue_dblTrail ( \n"
" iguid INT4, \n"
" ipath INT4, \n"
" type char(4), \n"
" data FLOAT8 \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE TABLE gncKVPvalue_numericTrail ( \n"
" iguid INT4, \n"
" ipath INT4, \n"
" type char(4), \n"
" num INT8, \n"
" denom INT8 \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE TABLE gncKVPvalue_strTrail ( \n"
" iguid INT4, \n"
" ipath INT4, \n"
" type char(4), \n"
" data TEXT \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE TABLE gncKVPvalue_guidTrail ( \n"
" iguid INT4, \n"
" ipath INT4, \n"
" type char(4), \n"
" data CHAR(32) \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE TABLE gncKVPvalue_timespecTrail ( \n"
" iguid INT4, \n"
" ipath INT4, \n"
" type char(4), \n"
" data TIMESTAMP \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"CREATE TABLE gncKVPvalue_listTrail ( \n"
" iguid INT4, \n"
" ipath INT4, \n"
" type char(4), \n"
" data TEXT[] \n"
") INHERITS (gncAuditTrail); \n"
" \n"
"-- end of file";

View File

@ -1,246 +1,246 @@
--
-- FILE:
-- table-create.sql
--
-- FUNCTION:
-- Define the tables needed to initialize a new GnuCash database
--
-- These tables roughly mirror the c structs in
-- TransactionP.h, AccountP.h, gnc-commodity.c
-- Please refer to the C files to get the right level of documentation.
--
-- If these tables are changed or added to, a correspionding
-- audit-trail table (in table-audit.sql) must be updated as well.
--
-- These tables are specifically designed for the
-- postgres database server, but are hopefull relatively portable.
--
-- These tables are hand-built, but maybe they should be
-- auto-built with the m4 macros ...
--
-- HISTORY:
-- Copyright (C) 2000, 2001 Linas Vepstas
--
CREATE TABLE gncVersion (
major INT NOT NULL,
minor INT NOT NULL,
rev INT DEFAULT '0',
name TEXT UNIQUE NOT NULL CHECK (name <> ''),
date TIMESTAMP DEFAULT 'NOW'
);
-- Commodity structure
-- Store currency, security types. Namespace includes
-- ISO4217 for currencies, NASDAQ, AMEX, NYSE, EUREX for
-- stocks. See the C documentation for details.
CREATE TABLE gncCommodity (
commodity TEXT PRIMARY KEY,
fullname TEXT,
namespace TEXT NOT NULL,
mnemonic TEXT NOT NULL,
code TEXT,
fraction INT DEFAULT '100'
);
CREATE TABLE gncBook (
bookGuid CHAR(32) PRIMARY KEY,
book_open CHAR DEFAULT 'n',
version INT4 NOT NULL,
iguid INT4 DEFAULT 0
);
-- Account structure -- parentGUID points to parent account
-- guid. There is no supports for Groups in this schema.
-- (there seems to be no strong need to have groups in the DB.)
CREATE TABLE gncAccount (
accountGuid CHAR(32) PRIMARY KEY,
parentGuid CHAR(32) NOT NULL,
bookGuid CHAR(32) NOT NULL,
accountName TEXT NOT NULL CHECK (accountName <> ''),
accountCode TEXT,
description TEXT,
type TEXT NOT NULL,
commodity TEXT NOT NULL CHECK (commodity <>''),
version INT4 NOT NULL,
iguid INT4 DEFAULT 0
);
-- CREATE INDEX gncAccount_pg_idx ON gncAccount (parentGuid);
CREATE TABLE gncTransaction (
transGuid CHAR(32) PRIMARY KEY,
last_modified TIMESTAMP DEFAULT 'NOW',
date_entered TIMESTAMP,
date_posted TIMESTAMP,
num TEXT,
description TEXT,
currency TEXT NOT NULL CHECK (currency <> ''),
version INT4 NOT NULL,
iguid INT4 DEFAULT 0
);
CREATE INDEX gncTransaction_posted_idx ON gncTransaction (date_posted);
-- a gncEntry is what we call 'Split' elsewhere in the engine
-- Here, we call it a 'journal entry'
CREATE TABLE gncEntry (
entryGuid CHAR(32) PRIMARY KEY,
accountGuid CHAR(32) NOT NULL,
transGuid CHAR(32) NOT NULL,
memo TEXT,
action TEXT,
reconciled CHAR DEFAULT 'n',
date_reconciled TIMESTAMP,
amount INT8 DEFAULT '0',
value INT8 DEFAULT '0',
iguid INT4 DEFAULT 0
);
CREATE INDEX gncEntry_acc_idx ON gncEntry (accountGuid);
CREATE INDEX gncEntry_trn_idx ON gncEntry (transGuid);
-- The checkpoint table provides balance information
-- The balance is provided in the indicated currency;
-- this allows the potential of maintaining balance information
-- in multiple currencies.
-- (e.g. report stock account balances in shares of stock,
-- and in dollars)
-- the 'type' field indicates what type of balance this is
-- (simple, FIFO, LIFO, or other accounting method)
CREATE TABLE gncCheckpoint (
accountGuid CHAR(32) NOT NULL,
date_start TIMESTAMP NOT NULL,
date_end TIMESTAMP NOT NULL,
commodity TEXT NOT NULL CHECK (commodity <>''),
type TEXT DEFAULT 'simple',
balance INT8 DEFAULT '0',
cleared_balance INT8 DEFAULT '0',
reconciled_balance INT8 DEFAULT '0',
PRIMARY KEY (accountGuid, date_start, commodity)
);
-- The price table stores the price of 'commodity' valued
-- in units of 'currency'
CREATE TABLE gncPrice (
priceGuid CHAR(32) PRIMARY KEY,
commodity TEXT NOT NULL CHECK (commodity <>''),
currency TEXT NOT NULL CHECK (commodity <>''),
time TIMESTAMP,
source TEXT,
type TEXT,
valueNum INT8 DEFAULT '0',
valueDenom INT4 DEFAULT '100',
version INT4 NOT NULL,
bookGuid CHAR(32) NOT NULL
);
-- The session directory serves several purposes. First and formost,
-- it notes the database access type. There are three modes:
-- o 'Single User' -- Only one user can have access to the database
-- at a time.
-- o 'Multi-User Polled' -- multiple users
-- o 'Muilti-User Event Driven'
-- See Design.txt for more info.
-- Note that a client can lie about its identity, sign-on time, etc.
-- so these records aren't really sufficient for a true audit.
CREATE TABLE gncSession (
sessionGuid CHAR(32) PRIMARY KEY,
session_mode CHAR(16) NOT NULL,
hostname TEXT,
login_name TEXT,
gecos TEXT,
time_on TIMESTAMP NOT NULL,
time_off TIMESTAMP NOT NULL DEFAULT 'INFINITY'
);
-- The kvp path-cache replaces a long path name with a single unique
-- number. The guid-cache replaces a 32-byte guid with a shorter
-- 4-byte identifier. The KVP Value table stores the actual values.
CREATE TABLE gncPathCache (
ipath SERIAL PRIMARY KEY,
path TEXT
);
CREATE SEQUENCE gnc_iguid_seq START 1;
CREATE TABLE gncKVPvalue (
iguid INT4,
ipath INT4,
type char(4),
PRIMARY KEY (iguid, ipath)
);
-- CREATE INDEX gncKVPvalue_iguid_idx ON gncKVPvalue (iguid);
-- Add primary keys to each kvp table ... because key inheritance
-- is ambiguously defined and thus not implemented in postgres.
-- Note, however, adding these keys degrades performance by 20%
-- (even after a vacuum analyze), and adding indexes degrades
-- an additional 15% !! I find this result surprising, so I
-- simply leave these commented out ... (as of postgres 7.1.2)
-- Note, indexex on the main, non-inherited tables *are* important
-- for ensuring good performance, so this effect seems to be related
-- to inheritance
CREATE TABLE gncKVPvalue_int64 (
data INT8
-- PRIMARY KEY (iguid, ipath)
) INHERITS (gncKVPvalue);
-- CREATE INDEX gncKVPvalue_int64_iguid_idx ON gncKVPvalue_int64 (iguid);
CREATE TABLE gncKVPvalue_dbl (
data FLOAT8
-- PRIMARY KEY (iguid, ipath)
) INHERITS (gncKVPvalue);
-- CREATE INDEX gncKVPvalue_dbl_iguid_idx ON gncKVPvalue_dbl (iguid);
CREATE TABLE gncKVPvalue_numeric (
num INT8,
denom INT8
-- PRIMARY KEY (iguid, ipath)
) INHERITS (gncKVPvalue);
-- CREATE INDEX gncKVPvalue_numeric_iguid_idx ON gncKVPvalue_numeric (iguid);
CREATE TABLE gncKVPvalue_str (
data TEXT
-- PRIMARY KEY (iguid, ipath)
) INHERITS (gncKVPvalue);
-- CREATE INDEX gncKVPvalue_str_iguid_idx ON gncKVPvalue_str (iguid);
CREATE TABLE gncKVPvalue_guid (
data CHAR(32)
-- PRIMARY KEY (iguid, ipath)
) INHERITS (gncKVPvalue);
-- CREATE INDEX gncKVPvalue_guid_iguid_idx ON gncKVPvalue_guid (iguid);
CREATE TABLE gncKVPvalue_timespec (
data TIMESTAMP
-- PRIMARY KEY (iguid, ipath)
) INHERITS (gncKVPvalue);
-- CREATE INDEX gncKVPvalue_timespec_iguid_idx ON gncKVPvalue_timespec (iguid);
CREATE TABLE gncKVPvalue_list (
data TEXT[]
-- PRIMARY KEY (iguid, ipath)
) INHERITS (gncKVPvalue);
-- CREATE INDEX gncKVPvalue_list_iguid_idx ON gncKVPvalue_list (iguid);
-- end of file
"-- \n"
"-- FILE: \n"
"-- table-create.sql \n"
"-- \n"
"-- FUNCTION: \n"
"-- Define the tables needed to initialize a new GnuCash database \n"
"-- \n"
"-- These tables roughly mirror the c structs in \n"
"-- TransactionP.h, AccountP.h, gnc-commodity.c \n"
"-- 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 \n"
"-- audit-trail table (in table-audit.sql) must be updated as well. \n"
"-- \n"
"-- These tables are specifically designed for the \n"
"-- postgres database server, but are hopefull relatively portable. \n"
"-- \n"
"-- These tables are hand-built, but maybe they should be \n"
"-- auto-built with the m4 macros ... \n"
"-- \n"
"-- HISTORY: \n"
"-- Copyright (C) 2000, 2001 Linas Vepstas \n"
"-- \n"
" \n"
"CREATE TABLE gncVersion ( \n"
" major INT NOT NULL, \n"
" minor INT NOT NULL, \n"
" rev INT DEFAULT '0', \n"
" name TEXT UNIQUE NOT NULL CHECK (name <> ''), \n"
" date TIMESTAMP DEFAULT 'NOW' \n"
"); \n"
" \n"
"-- Commodity structure \n"
"-- Store currency, security types. Namespace includes \n"
"-- ISO4217 for currencies, NASDAQ, AMEX, NYSE, EUREX for \n"
"-- stocks. See the C documentation for details. \n"
" \n"
"CREATE TABLE gncCommodity ( \n"
" commodity TEXT PRIMARY KEY, \n"
" fullname TEXT, \n"
" namespace TEXT NOT NULL, \n"
" mnemonic TEXT NOT NULL, \n"
" code TEXT, \n"
" fraction INT DEFAULT '100' \n"
"); \n"
" \n"
"CREATE TABLE gncBook ( \n"
" bookGuid CHAR(32) PRIMARY KEY, \n"
" book_open CHAR DEFAULT 'n', \n"
" version INT4 NOT NULL, \n"
" iguid INT4 DEFAULT 0 \n"
"); \n"
" \n"
"-- Account structure -- parentGUID points to parent account \n"
"-- guid. There is no supports for Groups in this schema. \n"
"-- (there seems to be no strong need to have groups in the DB.) \n"
" \n"
"CREATE TABLE gncAccount ( \n"
" accountGuid CHAR(32) PRIMARY KEY, \n"
" parentGuid CHAR(32) NOT NULL, \n"
" bookGuid CHAR(32) NOT NULL, \n"
" accountName TEXT NOT NULL CHECK (accountName <> ''), \n"
" accountCode TEXT, \n"
" description TEXT, \n"
" type TEXT NOT NULL, \n"
" commodity TEXT NOT NULL CHECK (commodity <>''), \n"
" version INT4 NOT NULL, \n"
" iguid INT4 DEFAULT 0 \n"
"); \n"
" \n"
"-- CREATE INDEX gncAccount_pg_idx ON gncAccount (parentGuid); \n"
" \n"
"CREATE TABLE gncTransaction ( \n"
" transGuid CHAR(32) PRIMARY KEY, \n"
" last_modified TIMESTAMP DEFAULT 'NOW', \n"
" date_entered TIMESTAMP, \n"
" date_posted TIMESTAMP, \n"
" num TEXT, \n"
" description TEXT, \n"
" currency TEXT NOT NULL CHECK (currency <> ''), \n"
" version INT4 NOT NULL, \n"
" iguid INT4 DEFAULT 0 \n"
"); \n"
" \n"
"CREATE INDEX gncTransaction_posted_idx ON gncTransaction (date_posted); \n"
" \n"
"-- a gncEntry is what we call 'Split' elsewhere in the engine \n"
"-- Here, we call it a 'journal entry' \n"
" \n"
"CREATE TABLE gncEntry ( \n"
" entryGuid CHAR(32) PRIMARY KEY, \n"
" accountGuid CHAR(32) NOT NULL, \n"
" transGuid CHAR(32) NOT NULL, \n"
" memo TEXT, \n"
" action TEXT, \n"
" reconciled CHAR DEFAULT 'n', \n"
" date_reconciled TIMESTAMP, \n"
" amount INT8 DEFAULT '0', \n"
" value INT8 DEFAULT '0', \n"
" iguid INT4 DEFAULT 0 \n"
"); \n"
" \n"
"CREATE INDEX gncEntry_acc_idx ON gncEntry (accountGuid); \n"
"CREATE INDEX gncEntry_trn_idx ON gncEntry (transGuid); \n"
" \n"
"-- The checkpoint table provides balance information \n"
"-- The balance is provided in the indicated currency; \n"
"-- this allows the potential of maintaining balance information \n"
"-- in multiple currencies. \n"
"-- (e.g. report stock account balances in shares of stock, \n"
"-- and in dollars) \n"
"-- the 'type' field indicates what type of balance this is \n"
"-- (simple, FIFO, LIFO, or other accounting method) \n"
" \n"
"CREATE TABLE gncCheckpoint ( \n"
" accountGuid CHAR(32) NOT NULL, \n"
" date_start TIMESTAMP NOT NULL, \n"
" date_end TIMESTAMP NOT NULL, \n"
" commodity TEXT NOT NULL CHECK (commodity <>''), \n"
" type TEXT DEFAULT 'simple', \n"
" balance INT8 DEFAULT '0', \n"
" cleared_balance INT8 DEFAULT '0', \n"
" reconciled_balance INT8 DEFAULT '0', \n"
" \n"
" PRIMARY KEY (accountGuid, date_start, commodity) \n"
"); \n"
" \n"
"-- The price table stores the price of 'commodity' valued \n"
"-- in units of 'currency' \n"
"CREATE TABLE gncPrice ( \n"
" priceGuid CHAR(32) PRIMARY KEY, \n"
" commodity TEXT NOT NULL CHECK (commodity <>''), \n"
" currency TEXT NOT NULL CHECK (commodity <>''), \n"
" time TIMESTAMP, \n"
" source TEXT, \n"
" type TEXT, \n"
" valueNum INT8 DEFAULT '0', \n"
" valueDenom INT4 DEFAULT '100', \n"
" version INT4 NOT NULL, \n"
" bookGuid CHAR(32) NOT NULL \n"
"); \n"
" \n"
" \n"
"-- The session directory serves several purposes. First and formost, \n"
"-- it notes the database access type. There are three modes: \n"
"-- o 'Single User' -- Only one user can have access to the database \n"
"-- at a time. \n"
"-- o 'Multi-User Polled' -- multiple users \n"
"-- o 'Muilti-User Event Driven' \n"
"-- See Design.txt for more info. \n"
"-- 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. \n"
" \n"
"CREATE TABLE gncSession ( \n"
" sessionGuid CHAR(32) PRIMARY KEY, \n"
" session_mode CHAR(16) NOT NULL, \n"
" hostname TEXT, \n"
" login_name TEXT, \n"
" gecos TEXT, \n"
" time_on TIMESTAMP NOT NULL, \n"
" time_off TIMESTAMP NOT NULL DEFAULT 'INFINITY' \n"
"); \n"
" \n"
" \n"
"-- 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 \n"
"-- 4-byte identifier. The KVP Value table stores the actual values. \n"
" \n"
"CREATE TABLE gncPathCache ( \n"
" ipath SERIAL PRIMARY KEY, \n"
" path TEXT \n"
"); \n"
" \n"
"CREATE SEQUENCE gnc_iguid_seq START 1; \n"
" \n"
"CREATE TABLE gncKVPvalue ( \n"
" iguid INT4, \n"
" ipath INT4, \n"
" type char(4), \n"
" \n"
" PRIMARY KEY (iguid, ipath) \n"
"); \n"
" \n"
"-- CREATE INDEX gncKVPvalue_iguid_idx ON gncKVPvalue (iguid); \n"
" \n"
"-- Add primary keys to each kvp table ... because key inheritance \n"
"-- is ambiguously defined and thus not implemented in postgres. \n"
"-- Note, however, adding these keys degrades performance by 20% \n"
"-- (even after a vacuum analyze), and adding indexes degrades \n"
"-- an additional 15% !! I find this result surprising, so I \n"
"-- simply leave these commented out ... (as of postgres 7.1.2) \n"
"-- Note, indexex on the main, non-inherited tables *are* important \n"
"-- for ensuring good performance, so this effect seems to be related \n"
"-- to inheritance \n"
" \n"
"CREATE TABLE gncKVPvalue_int64 ( \n"
" data INT8 \n"
"-- PRIMARY KEY (iguid, ipath) \n"
") INHERITS (gncKVPvalue); \n"
" \n"
"-- CREATE INDEX gncKVPvalue_int64_iguid_idx ON gncKVPvalue_int64 (iguid); \n"
" \n"
"CREATE TABLE gncKVPvalue_dbl ( \n"
" data FLOAT8 \n"
"-- PRIMARY KEY (iguid, ipath) \n"
") INHERITS (gncKVPvalue); \n"
" \n"
"-- CREATE INDEX gncKVPvalue_dbl_iguid_idx ON gncKVPvalue_dbl (iguid); \n"
" \n"
"CREATE TABLE gncKVPvalue_numeric ( \n"
" num INT8, \n"
" denom INT8 \n"
"-- PRIMARY KEY (iguid, ipath) \n"
") INHERITS (gncKVPvalue); \n"
" \n"
"-- CREATE INDEX gncKVPvalue_numeric_iguid_idx ON gncKVPvalue_numeric (iguid); \n"
" \n"
"CREATE TABLE gncKVPvalue_str ( \n"
" data TEXT \n"
"-- PRIMARY KEY (iguid, ipath) \n"
") INHERITS (gncKVPvalue); \n"
" \n"
"-- CREATE INDEX gncKVPvalue_str_iguid_idx ON gncKVPvalue_str (iguid); \n"
" \n"
"CREATE TABLE gncKVPvalue_guid ( \n"
" data CHAR(32) \n"
"-- PRIMARY KEY (iguid, ipath) \n"
") INHERITS (gncKVPvalue); \n"
" \n"
"-- CREATE INDEX gncKVPvalue_guid_iguid_idx ON gncKVPvalue_guid (iguid); \n"
" \n"
"CREATE TABLE gncKVPvalue_timespec ( \n"
" data TIMESTAMP \n"
"-- PRIMARY KEY (iguid, ipath) \n"
") INHERITS (gncKVPvalue); \n"
" \n"
"-- CREATE INDEX gncKVPvalue_timespec_iguid_idx ON gncKVPvalue_timespec (iguid); \n"
" \n"
"CREATE TABLE gncKVPvalue_list ( \n"
" data TEXT[] \n"
"-- PRIMARY KEY (iguid, ipath) \n"
") INHERITS (gncKVPvalue); \n"
" \n"
"-- CREATE INDEX gncKVPvalue_list_iguid_idx ON gncKVPvalue_list (iguid); \n"
" \n"
"-- end of file";

View File

@ -1,26 +1,26 @@
--
-- FILE:
-- table-drop.sql
--
-- FUNCTION:
-- Drop the tables needed to run GnuCash database
DROP TABLE gncCommodity;
DROP TABLE gncAccount;
DROP TABLE gncTransaction;
DROP TABLE gncEntry;
DROP TABLE gncCheckpoint;
DROP TABLE gncSession;
--
DROP TABLE gncPathCache;
DROP TABLE gncGUIDCache;
DROP TABLE gncKVPvalue;
DROP TABLE gncKVPvalue_int64;
DROP TABLE gncKVPvalue_dbl;
DROP TABLE gncKVPvalue_numeric;
DROP TABLE gncKVPvalue_str;
DROP TABLE gncKVPvalue_guid;
DROP TABLE gncKVPvalue_timespec;
DROP TABLE gncKVPvalue_list;
DROP TABLE gncKVPvalue_frame;
"-- \n"
"-- FILE: \n"
"-- table-drop.sql \n"
"-- \n"
"-- FUNCTION: \n"
"-- Drop the tables needed to run GnuCash database \n"
" \n"
" \n"
"DROP TABLE gncCommodity; \n"
"DROP TABLE gncAccount; \n"
"DROP TABLE gncTransaction; \n"
"DROP TABLE gncEntry; \n"
"DROP TABLE gncCheckpoint; \n"
"DROP TABLE gncSession; \n"
"-- \n"
"DROP TABLE gncPathCache; \n"
"DROP TABLE gncGUIDCache; \n"
"DROP TABLE gncKVPvalue; \n"
"DROP TABLE gncKVPvalue_int64; \n"
"DROP TABLE gncKVPvalue_dbl; \n"
"DROP TABLE gncKVPvalue_numeric; \n"
"DROP TABLE gncKVPvalue_str; \n"
"DROP TABLE gncKVPvalue_guid; \n"
"DROP TABLE gncKVPvalue_timespec; \n"
"DROP TABLE gncKVPvalue_list; \n"
"DROP TABLE gncKVPvalue_frame;";

View File

@ -1,19 +1,19 @@
--
-- FILE:
-- table-version.sql
--
-- FUNCTION:
-- Insert the latest version information into the gncVersion table.
--
-- Inserting in the same query as creating the table does not
-- work under Postgres 7.0
--
-- HISTORY:
-- Copyright (C) 2001 Linux Developers Group
--
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');
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,3,1,'Add kvp_timespec tables');
INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,4,1,'Add support for multiple books');
"-- \n"
"-- FILE: \n"
"-- table-version.sql \n"
"-- \n"
"-- FUNCTION: \n"
"-- Insert the latest version information into the gncVersion table. \n"
"-- \n"
"-- Inserting in the same query as creating the table does not \n"
"-- work under Postgres 7.0 \n"
"-- \n"
"-- HISTORY: \n"
"-- Copyright (C) 2001 Linux Developers Group \n"
"-- \n"
" \n"
"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'); \n"
"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'); \n"
"INSERT INTO gncVersion (major,minor,rev,name) VALUES (1,4,1,'Add support for multiple books');";

View File

@ -3,30 +3,35 @@
EXIT_VALUE=0
PATH=/usr/lib/postgresql/bin:$PATH
PGCTL=`which pg_ctl 2> /dev/null`
DB=$PWD/gnc_test_db
SOCKDIR=$PWD/gnc_test_db_sock
SOCKNUM=7777
# I couldn't get this to work -- the shell seems to think "'-k" is an
# argument after it finishes expanding ${PG_CTL}...
# PG_CTL="pg_ctl -D "${DB}" -o '-k ${SOCKDIR} -p ${SOCKNUM}'"
our_pg_ctl ()
{
if [ ${PGCTL}X == X ]; then
exit -1
fi
pg_ctl -D "${DB}" -o "-k ${SOCKDIR} -p ${SOCKNUM}" "$@";
}
case $1 in
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 ${SOCKDIR}
initdb ${DB} || EXIT_VALUE=1
mkdir ${SOCKDIR} || EXIT_VALUE=1
;;
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 ${SOCKDIR}
;;
@ -34,13 +39,13 @@ case $1 in
our_pg_ctl start
;;
stop)
pg_ctl -D ${DB} -o '-k ${SOCKDIR} -p 7777' stop
pg_ctl -D ${DB} -o '-k ${SOCKDIR} -p 7777' stop || exit -1
;;
status)
our_pg_ctl status
;;
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
;;
*)

View File

@ -2,17 +2,25 @@
EXIT_VALUE=0
rm -f test_file_*
./db-control.sh create
./db-control.sh start
# .libs/test-db || EXIT_VALUE=1
# 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
./db-control.sh destroy
exit $EXIT_VALUE

File diff suppressed because it is too large Load Diff