[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas TODO configure.in src/objectstore/obj...
From: |
James Thompson |
Subject: |
gnue/geas TODO configure.in src/objectstore/obj... |
Date: |
Sat, 17 Feb 2001 20:25:19 -0800 |
CVSROOT: /cvs
Module name: gnue
Changes by: James Thompson <address@hidden> 01/02/17 20:25:19
Modified files:
geas : TODO configure.in
geas/src/objectstore: objectstore.c postgresql_access.h
Log message:
Added check for libuuid
Postgresql driver will now compile. It is still not feature complete.
Started adding auto table update support to postgresql driver
CVSWeb URLs:
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/geas/TODO.diff?r1=1.26&r2=1.27
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/geas/configure.in.diff?r1=1.17&r2=1.18
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/geas/src/objectstore/objectstore.c.diff?r1=1.35&r2=1.36
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/geas/src/objectstore/postgresql_access.h.diff?r1=1.1&r2=1.2
Patches:
Index: gnue/geas/TODO
diff -u gnue/geas/TODO:1.26 gnue/geas/TODO:1.27
--- gnue/geas/TODO:1.26 Thu Feb 8 17:07:09 2001
+++ gnue/geas/TODO Sat Feb 17 20:25:19 2001
@@ -13,10 +13,6 @@
should set OAF_CFLAGS and OAF_LFLAGS appropriately (or at least let me see
where to set them)
-
-Add a check for libuuid
-
-
On 'make install', the following should be done:
IDL files in geas/idl should be copied to /usr/share/idl/geas (although the
Index: gnue/geas/configure.in
diff -u gnue/geas/configure.in:1.17 gnue/geas/configure.in:1.18
--- gnue/geas/configure.in:1.17 Thu Feb 8 13:56:14 2001
+++ gnue/geas/configure.in Sat Feb 17 20:25:19 2001
@@ -22,6 +22,7 @@
AC_HEADER_STDC
AC_CHECK_HEADERS(unistd.h)
AC_CHECK_HEADERS(sys/types.h)
+AC_CHECK_HEADERS(uuid/uuid.h,,AC_MSG_ERROR('You need the uuid library') )
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
Index: gnue/geas/src/objectstore/objectstore.c
diff -u gnue/geas/src/objectstore/objectstore.c:1.35
gnue/geas/src/objectstore/objectstore.c:1.36
--- gnue/geas/src/objectstore/objectstore.c:1.35 Wed Feb 7 12:43:19 2001
+++ gnue/geas/src/objectstore/objectstore.c Sat Feb 17 20:25:19 2001
@@ -1,4 +1,3 @@
-
/*
geas - GNU Enterprise Application Server
@@ -147,6 +146,9 @@
#ifdef USE_MYSQL
#include "mysql_access.h"
#endif
+#ifdef USE_POSTGRESQL
+#include "postgresql_access.h"
+#endif
/* public functions */
@@ -156,15 +158,14 @@
FILE *changefile;
struct database_handle *h = NULL;
const char *database = get_first_active_database(configdata); /* HACK
-
-
HACK
-
HACK */
+ HACK
+ HACK
*/
/* write header to change file */
-
changefile =
fopen(get_global_option_str
(configdata, "databasechangefile", "database.changes.txt"), "w");
+
if (changefile)
{
show_version(changefile, SHORT_VERSION);
@@ -419,7 +420,7 @@
if (!succeeded && g_strcasecmp(type, "PostgreSQL") == 0)
{
- h = PostgreSQL_create_database_handle(d);
+ h =(struct database_handle
*)PostgreSQL_create_database_handle(config, dbname);
succeeded = TRUE;
}
#endif
Index: gnue/geas/src/objectstore/postgresql_access.h
diff -u gnue/geas/src/objectstore/postgresql_access.h:1.1
gnue/geas/src/objectstore/postgresql_access.h:1.2
--- gnue/geas/src/objectstore/postgresql_access.h:1.1 Thu Feb 15 19:17:29 2001
+++ gnue/geas/src/objectstore/postgresql_access.h Sat Feb 17 20:25:19 2001
@@ -46,9 +46,8 @@
#error "--with-postgresql was not used when building GEAS"
#endif
-/* include postgresql specific files */
-#include <postgres.h>
-#include <libpq-fe.h>
+/* #include <postgres.h> */
+#include "libpq-fe.h"
/* database specific data structures */
struct postgresql_connection
@@ -74,7 +73,7 @@
struct active_connection *
postgresql_get_connection(struct database_handle *hnd)
{
- struct postgresql_handle *handle = (struct postgresql_handle *)hnd;
+ struct postgresql_handle *h = (struct postgresql_handle *)hnd;
struct active_connection *retval = NULL;
struct active_connection *tmp = NULL;
unsigned long int queue = UINT_MAX;
@@ -227,8 +226,9 @@
struct postgresql_handle *h = (struct postgresql_handle *)ph; /* convert
to actual type */
struct postgresql_connection *conn;
- PQresult *res;
- int nfields, nrows;
+ PGresult *res;
+ int nfields, nrows;
+ int row, i;
/* claim a connection */
conn = (struct postgresql_connection *)ph->get_connection(ph);
@@ -253,74 +253,46 @@
debug_output(DEBUGLEVEL_HIGH, "SQL query: '%s'",
oql_query_as_sql(query, quotemode));
res = PQexec(conn->handle,oql_query_as_sql(query, quotemode));
- if (res == PGRES_COMMAND_OK)
+ if (PQresultStatus(res) == PGRES_COMMAND_OK) /* query does not return rows,
and didn't - ok */
{
- nrows = PQn
- if (PQ
- if (mysql_field_count(conn->handle) == 0)
- {
- /* query does not return rows, and didn't - ok */
- /* eg delete, insert, or replace SQL statemenmts */
- result->rows_affected = mysql_affected_rows(con->handle);
- }
- else
- {
- /* should have returned rows of data, and didn't - error */
- con->base.available = TRUE;
- if (errorcode)
- *errorcode = ( -1); /* TODO: meaningful error codes */
- if (errormsg)
- *errormsg = g_strdup(mysql_error(con->handle));
-
- /* release this connection */
- con->base.available = TRUE;
- return (result);
- }
- }
- else /* res != NULL */
- {
- /* returned some rows of data */
- result->rows_affected = mysql_affected_rows(con->handle);
- result->field_count = mysql_num_fields(res);
- result->success = TRUE;
-
- /* for each entry, extract object ID */
- while (row = mysql_fetch_row(res))
- {
- /* TODO: create list of objectIDs - need class
- definitions */
- char *keydata = "";
- int i;
- DatabaseResultRow_t r = NULL;
-
- /* the result set is a linked list of rows */
- /* each row is in turn a linked list of strings */
- /* where entry N is field N, listed left to right */
- /* in the SELECT query: */
- /* SELECT objectID,name,age : */
- /* objectID = field 0, name = field 1, age = field 2 */
- /* first row returned = row 0 (start of list), 2nd = row
- 1 (next in list) */
- for (i = 0; i < mysql_num_fields(res); i++)
- {
- add_field_to_result_row(r, g_strdup(row[i]));
- }
- /* add entry to list */
- result->data = g_list_append(result->data, r);
- }
-
- mysql_free_result(res);
- }
- }
- else
- {
- /* error during query */
- if (errorcode)
- *errorcode = ( res);
- if (errormsg)
- *errormsg = g_strdup(PQresultStatus(res));
- result->success = FALSE;
+ result->rows_affected = PQcmdTuples(res);
}
+ else if (PQresultStatus(res) == PGRES_TUPLES_OK) /* returned some rows of
data */
+ {
+ result->rows_affected = PQntuples(res);
+ result->field_count = PQnfields(res);
+ result->success = TRUE;
+
+ /* for each entry, extract object ID */
+ for (row = 0; row < result->rows_affected; row ++)
+ {
+ char *keydata = "";
+ int i;
+ DatabaseResultRow_t r = NULL;
+ /* the result set is a linked list of rows */
+ /* each row is in turn a linked list of strings */
+ /* where entry N is field N, listed left to right */
+ /* in the SELECT query: */
+ /* SELECT objectID,name,age : */
+ /* objectID = field 0, name = field 1, age = field 2 */
+ /* first row returned = row 0 (start of list), 2nd = row
+ 1 (next in list) */
+ for (i = 0; i < result->field_count; i++)
+ {
+ add_field_to_result_row(r, g_strdup(PQgetvalue(res,row,i)));
+ }
+ result->data = g_list_append(result->data, r);
+ }
+ PQclear(res);
+ }
+ else /* error during query */
+ {
+ if (errorcode)
+ *errorcode = (-1);
+ if (errormsg)
+ *errormsg = g_strdup(PQresultErrorMessage(res));
+ result->success = FALSE;
+ }
/* release this connection */
conn->base.available = TRUE;
return (result);
@@ -352,21 +324,215 @@
{
}
+
+
+void
+postgresql_add_column_data(GString * buf, GList * l, const char *separator)
+{
+ DBchange *c;
+
+ while (l)
+ {
+ c = (DBchange *) l->data;
+ g_string_append(buf, c->name);
+ g_string_append(buf, " ");
+ switch (c->fieldtype)
+ {
+ case DT_char:
+ g_string_sprintfa(buf, "CHAR");
+ if (c->format)
+ g_string_sprintfa(buf, "(%s)", c->format);
+ else
+ g_string_sprintfa(buf, "(1)");
+ break;
+ case DT_text:
+ g_string_sprintfa(buf, "VARCHAR");
+ if (c->format)
+ g_string_sprintfa(buf, "(%s)", c->format);
+ else
+ g_string_sprintfa(buf, "(16)");
+ break;
+ case DT_int:
+ g_string_sprintfa(buf, "INT");
+ break;
+ case DT_unsignedint:
+ g_string_sprintfa(buf, "INT UNSIGNED");
+ break;
+ case DT_object:
+ g_string_sprintfa(buf, "VARCHAR(38)");
+ break;
+ default:
+ break;
+ }
+ if (c->notnull)
+ g_string_append(buf, " NOT NULL");
+ else
+ g_string_append(buf, " ");
+
+ g_string_append(buf, separator);
+ l = g_list_next(l);
+ }
+}
+
/* update a */
struct query_result *
- postgresql_update_tables(struct database_handle *h,
+ postgresql_update_tables(struct database_handle *hnd,
gboolean remove_items, int *errorcode, char
**errormsg)
- {
- /* read database definition */
+{
+ GString *buf;
+ DatabaseChange *changes = NULL;
+ GList *required = NULL;
+ GList *tmp, *l;
+ DatabaseDefinition *database = NULL;
+ PGconn *handle;
+ PGresult *res;
+ int err;
+ FILE *changefile;
+
+ /* hard code this to OFF - is intended for remote admin */
+ remove_items = FALSE;
+
+ /* clear error indicators */
+ if (errorcode)
+ *errorcode = 0;
+ if (errormsg)
+ *errormsg = NULL;
+
+ /* make a list of required classnames in this database */
+ required = get_classname_list(all_classes);
+ /* currently only a single SQL database is allowed at one time */
+ /* so all classes are required */
+ /* TODO: remove names from list if not required in */
+
+ /* read current table definitions from database */
+// database = MySQL_read_database_definition(h);
+ /* show_database_definition( database ); */
+
+ /* compare to current classes for this database */
+ /* if table doesn't match a class, report the table as unnecessary */
+ /* if column doesn't match a class field, report it as unnecessary */
+ /* if class doesn't match a table, record the table as required */
+ /* if data field doesn't match a column, record the column as required */
+ changes = compare_classes_to_database(all_classes, required, database);
+ free_classname_list(required);
+ required = NULL;
+
+ if (!changes)
+ {
+ /* no changes required! yay! */
+ /* don't care about a result - error msgs alreayd printed */
+ message("No database changes.");
+ return (NULL);
+ }
- /* call libclassdef function to calculate required changes to the
database */
+ changefile =
+ fopen(get_global_option_str
+ (configdata, "databasechangefile", "database.changes.txt"), "a");
+ if (!changefile)
+ {
+ errormsg("Could not open log file '%s' for database changes.",
+ get_global_option_str(configdata, "databasechangefile",
+ "database.changes.txt"));
+ return (NULL);
+ }
+ /* display remove suggestions */
+ tmp = changes->removes;
+ if (tmp)
+ fprintf(changefile,
+ "These changes should be made to database '%s', unless there has
been an\n"
+ "error in the configuration of GEAS:\n\n", hnd->name);
+ while (tmp)
+ {
+ remove_message(changefile, (DBchange *) tmp->data);
+ tmp = g_list_next(tmp);
+ }
+ fprintf(changefile, "\n\n");
+
+ if (!changes->adds)
+ {
+ /* no additions, so don't both with the rest */
+ fclose(changefile);
+ return (NULL);
+ }
+ /* connect to database */
+ handle = PQsetdbLogin(hnd->hostname, hnd->port, NULL, NULL,
hnd->dbname,hnd->username,hnd->password);
+ if (!handle)
+ {
+ errormsg("Failed to initialise Postgres connection.");
+ fclose(changefile);
+ return (NULL);
+ }
- /* update database. write to logfile a list of tables/columns that need
removed */
- }
+ /* update tables on server */
+ tmp = changes->adds;
+ fprintf(changefile, "These changes are being made automatically:\n\n");
+ while (tmp)
+ {
+ DBchange *add = (DBchange *) tmp->data;
+
+ /* display add requirement */
+ add_message(changefile, (DBchange *) tmp->data);
+
+ if (add->type == DBCH_ADD_TABLE)
+ {
+ /* for each new table, construct a CREATE command */
+ buf = g_string_new("");
+ g_string_sprintf(buf, "CREATE TABLE %s (", add->name);
+ postgresql_add_column_data(buf, add->columns, ", ");
+ g_string_append(buf, "PRIMARY KEY (ObjectID) )");
+ }
+ else if (add->type == DBCH_MODIFY_TABLE)
+ {
+ /* for each table with new columns, construct a MODIFY command
+ */
+ buf = g_string_new("");
+ g_string_sprintf(buf, "ALTER TABLE %s ADD ", add->name);
+ postgresql_add_column_data(buf, add->columns, ", ADD ");
+ buf->str[strlen(buf->str) - 5] = '\0';
+ while (isspace(buf->str[strlen(buf->str) - 1]) ||
+ buf->str[strlen(buf->str) - 1] == ',')
+ buf->str[strlen(buf->str) - 1] = '\0';
+ }
+
+ /* execute query */
+
+ g_strdown(buf->str);
+ /* printf( "CREATE/ALTER QUERY: [%s]\n" , buf->str ); */
+ res = PQexec(handle, buf->str);
+ if (PQresultStatus(res) == PGRES_COMMAND_OK )
+ {
+ /* query appeared to succeed */
+ /* message( "[%s] succeeded" , buf->str ); */
+ }
+ else
+ {
+ /* TODO: error handling */
+ /* message( "[%s] failed" , buf->str ); */
+ errormsg(PQresultErrorMessage(res));
+ }
+
+ tmp = g_list_next(tmp);
+ }
+ fprintf(changefile, "\n");
+
+
+
+ PQfinish(handle);
+ fclose(changefile);
+ /* message( "Done updating database" ); */
+
+
+
+
+
+
+ /* don't care about a result - error msgs alreayd printed */
+ return (NULL);
+}
/* initialise a connection to a specific postgresql database */
static struct postgresql_handle *
- postgresql_create_database_handle(configuration config, const char
*dbname)
+ PostgreSQL_create_database_handle(configuration config, const char
*dbname)
{
int i;
struct postgresql_handle *h =
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/geas TODO configure.in src/objectstore/obj...,
James Thompson <=