* src/backend/postgres/PostgresBackend.c: allow gnucash tables

to be installed in an existing database.

* src/backend/postgres/upgrade.c: use pointer<->int conversion
macros


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6501 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2002-01-03 10:04:01 +00:00
parent 875a439abc
commit 8ee531499a
3 changed files with 92 additions and 60 deletions

View File

@ -1,3 +1,11 @@
2002-01-03 Dave Peticolas <dave@krondo.com>
* src/backend/postgres/PostgresBackend.c: allow gnucash tables
to be installed in an existing database.
* src/backend/postgres/upgrade.c: use pointer<->int conversion
macros
2001-12-27 Dave Peticolas <dave@krondo.com>
* src/backend/postgres/test/test-db.c: expand testing

View File

@ -1412,11 +1412,28 @@ pgend_price_load_single (Backend *bend, GNCBook *book)
*/
static gpointer
db_exists_cb (PGBackend *be, PGresult *result, int j, gpointer data)
has_results_cb (PGBackend *be, PGresult *result, int j, gpointer data)
{
return GINT_TO_POINTER (TRUE);
}
static void
pgend_create_db (PGBackend *be)
{
/* We do this in pieces, so as not to exceed the max length
* for postgres queries (which is 8192). */
SEND_QUERY (be,table_create_str, );
FINISH_QUERY(be->connection);
SEND_QUERY (be,table_version_str, );
FINISH_QUERY(be->connection);
SEND_QUERY (be,table_audit_str, );
FINISH_QUERY(be->connection);
SEND_QUERY (be,sql_functions_str, );
FINISH_QUERY(be->connection);
be->freshly_created_db = TRUE;
be->freshly_created_prdb = TRUE;
}
static void
pgend_session_begin (Backend *backend,
@ -1654,7 +1671,7 @@ pgend_session_begin (Backend *backend,
p = stpcpy (p, "';");
SEND_QUERY (be,be->buff, );
db_exists = GPOINTER_TO_INT(pgendGetResults(be, db_exists_cb,
db_exists = GPOINTER_TO_INT(pgendGetResults(be, has_results_cb,
GINT_TO_POINTER (FALSE)));
PQfinish (be->connection);
@ -1736,7 +1753,7 @@ pgend_session_begin (Backend *backend,
p = stpcpy (p, "';");
SEND_QUERY (be,be->buff, );
db_exists = GPOINTER_TO_INT (pgendGetResults (be, db_exists_cb,
db_exists = GPOINTER_TO_INT (pgendGetResults (be, has_results_cb,
GINT_TO_POINTER (FALSE)));
if (FALSE == db_exists)
@ -1775,27 +1792,18 @@ pgend_session_begin (Backend *backend,
return;
}
/* Finally, create all the tables and indexes.
* We do this in pieces, so as not to exceed the max length
* for postgres queries (which is 8192).
*/
SEND_QUERY (be,table_create_str, );
FINISH_QUERY(be->connection);
SEND_QUERY (be,table_version_str, );
FINISH_QUERY(be->connection);
SEND_QUERY (be,table_audit_str, );
FINISH_QUERY(be->connection);
SEND_QUERY (be,sql_functions_str, );
FINISH_QUERY(be->connection);
be->freshly_created_db = TRUE;
be->freshly_created_prdb = TRUE;
/* Finally, create all the tables and indexes. */
pgend_create_db (be);
}
else
{
gboolean gncaccount_exists;
/* Database exists, although we were asked to create it.
* We interpret this to mean that its downlevel, and
* user wants us to upgrade it. So connect and upgrade.
*/
* We interpret this to mean that either it's downlevel,
* and user wants us to upgrade it, or we are installing
* gnucash tables into an existing database. So do one or
* the other. */
PQfinish (be->connection);
@ -1826,6 +1834,20 @@ pgend_session_begin (Backend *backend,
return;
}
/* See if the gncaccount table exists. If it does not,
* create all the tables. We assume that there will always
* be a gncaccount table. */
p = "SELECT tablename FROM pg_tables WHERE tablename='gncaccount';";
SEND_QUERY (be,p, );
gncaccount_exists =
GPOINTER_TO_INT (pgendGetResults (be, has_results_cb, FALSE));
if (!gncaccount_exists)
{
pgend_create_db (be);
}
else
{
rc = pgendDBVersionIsCurrent (be);
if (0 > rc)
{
@ -1846,7 +1868,7 @@ pgend_session_begin (Backend *backend,
"SELECT time_off FROM gncSession WHERE time_off ='infinity';";
SEND_QUERY (be,p, );
someones_still_on =
GPOINTER_TO_INT (pgendGetResults (be, db_exists_cb,
GPOINTER_TO_INT (pgendGetResults (be, has_results_cb,
GINT_TO_POINTER (FALSE)));
if (someones_still_on)
{
@ -1872,6 +1894,7 @@ pgend_session_begin (Backend *backend,
}
}
}
}
/* free url only after login completed */
g_free(url);

View File

@ -46,7 +46,7 @@ static short module = MOD_BACKEND;
static gpointer
version_table_cb (PGBackend *be, PGresult *result, int j, gpointer data)
{
return (gpointer) TRUE;
return GINT_TO_POINTER (TRUE);
}
static void
@ -60,7 +60,8 @@ pgendVersionTable (PGBackend *be)
p = "SELECT tablename FROM pg_tables WHERE tablename='gncversion';";
SEND_QUERY (be,p, );
table_exists = (gboolean) pgendGetResults (be, version_table_cb, FALSE);
table_exists = GPOINTER_TO_INT (pgendGetResults (be, version_table_cb,
FALSE));
if (table_exists) return;