[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gnue/geas/src/objectstore mysql_access.h object...
From: |
Reinhard Mueller |
Subject: |
gnue/geas/src/objectstore mysql_access.h object... |
Date: |
Tue, 22 May 2001 12:05:12 -0700 |
CVSROOT: /cvs
Module name: gnue
Changes by: Reinhard Mueller <address@hidden> 01/05/22 12:05:12
Modified files:
geas/src/objectstore: mysql_access.h objectstore.c objectstore.h
postgresql_access.h
Log message:
reformatted code
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/objectstore/mysql_access.h.diff?cvsroot=OldCVS&tr1=1.19&tr2=1.20&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/objectstore/objectstore.c.diff?cvsroot=OldCVS&tr1=1.53&tr2=1.54&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/objectstore/objectstore.h.diff?cvsroot=OldCVS&tr1=1.16&tr2=1.17&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gnue/geas/src/objectstore/postgresql_access.h.diff?cvsroot=OldCVS&tr1=1.25&tr2=1.26&r1=text&r2=text
Patches:
Index: gnue/geas/src/objectstore/mysql_access.h
diff -u gnue/geas/src/objectstore/mysql_access.h:1.19
gnue/geas/src/objectstore/mysql_access.h:1.20
--- gnue/geas/src/objectstore/mysql_access.h:1.19 Thu Apr 5 15:21:26 2001
+++ gnue/geas/src/objectstore/mysql_access.h Tue May 22 12:05:11 2001
@@ -1,25 +1,30 @@
-
/*
- geas - GNU Enterprise Application Server
-
+ Interface to MySQL Database
+
Copyright (C) 2001 Free Software Foundation
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
+
+ This file is part of the GNU Enterprise Application Server (GEAS)
+
+ GEAS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ GEAS is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
+ along with GEAS; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ $Id: mysql_access.h,v 1.20 2001/05/22 19:05:11 reinhard Exp $
*/
+/* This is not really a header file. It's rather a piece of code that is
+ included conditionally. */
+
/* MySQL support */
#ifndef USE_MYSQL
#error "--with-mysql was not used when building GEAS"
@@ -29,771 +34,781 @@
#include <mysql.h>
struct MySQL_connection
- {
- /* the first line must be: struct active_connection base; */
- struct active_connection base;
-
- /* any MySQL specific data goes here */
- MYSQL *handle;
- };
+{
+ /* the first line must be: struct active_connection base; */
+ struct active_connection base;
+
+ /* any MySQL specific data goes here */
+ MYSQL *handle;
+};
struct MySQL_handle
- {
- /* the first line must be: struct database_handle base; */
- struct database_handle base;
+{
+ /* the first line must be: struct database_handle base; */
+ struct database_handle base;
- /* any MySQL specific data goes here */
- };
+ /* any MySQL specific data goes here */
+};
struct active_connection *
- MySQL_get_connection(struct database_handle *hnd)
- {
- struct MySQL_handle *h = (struct MySQL_handle *)hnd;
- struct active_connection *retval = NULL;
- struct active_connection *tmp = NULL;
- int i;
- unsigned long int queue = UINT_MAX;
-trace_functioncall();
-
- /*
- * find available connection: * first available and connected
- * connection * else first available and non connected and connect it
- * immediately * else first connected with lowest queue * else fail
- * */
-
- /* available and connected */
- /* TODO: make connection check depend on actual database state, to detect
- * unexpected disconnections */
- for (i = 0; i < h->base.num_connections; i++)
- {
+MySQL_get_connection (struct database_handle *hnd)
+{
+ struct MySQL_handle *h = (struct MySQL_handle *) hnd;
+ struct active_connection *retval = NULL;
+ struct active_connection *tmp = NULL;
+ int i;
+ unsigned long int queue = UINT_MAX;
+ trace_functioncall ();
+
+ /*
+ find available connection:
+ * first available and connected connection
+ * else first available and non connected and connect it immediately
+ * else first connected with lowest queue
+ * else fail
+ */
+
+ /* available and connected */
+ /* TODO: make connection check depend on actual database state, to detect
+ * unexpected disconnections */
+ for (i = 0; i < h->base.num_connections; i++)
+ {
retval =
- (struct active_connection *) & ((struct MySQL_connection *)h->base.
- connections)[i];
+ (struct active_connection *) &((struct MySQL_connection *) h->
+ base.connections)[i];
if (retval->available && retval->connected)
- {
- retval->available = FALSE;
- return (retval);
- }
- }
-
- /* available and not connected, if connection succeeds */
- for (i = 0; i < h->base.num_connections; i++)
- {
+ {
+ retval->available = FALSE;
+ return (retval);
+ }
+ }
+
+ /* available and not connected, if connection succeeds */
+ for (i = 0; i < h->base.num_connections; i++)
+ {
retval =
- (struct active_connection *) & ((struct MySQL_connection *)h->base.
- connections)[i];
+ (struct active_connection *) &((struct MySQL_connection *) h->
+ base.connections)[i];
if (retval->available && !retval->connected)
- {
- /* try to connect to database */
- if (hnd->connect(hnd, i))
+ {
+ /* try to connect to database */
+ if (hnd->connect (hnd, i))
{
- return (retval);
+ return (retval);
}
- }
- }
+ }
+ }
- fprintf(stderr,"\nTODO: handle no connection\n");
- fprintf(stderr,"needs to wait until a connection becomes available, as
another\n");
- fprintf(stderr,"thread releases a connection\n\n");
- abort();
-
- /* lowest queue */
- /* wait until the least used connection is available */
- }
+ fprintf (stderr, "\nTODO: handle no connection\n");
+ fprintf (stderr,
+ "needs to wait until a connection becomes available, as another\n");
+ fprintf (stderr, "thread releases a connection\n\n");
+ abort ();
+
+ /* lowest queue */
+ /* wait until the least used connection is available */
+}
static gboolean
-MySQL_connect(struct database_handle *hnd, unsigned long int index)
- {
- struct MySQL_handle *h = (struct MySQL_handle *)hnd;
- gboolean retval = FALSE;
- struct MySQL_connection *c;
-
- /* range check */
- if (index >= hnd->num_connections)
- {
- errormsg("Invalid connection index");
+MySQL_connect (struct database_handle *hnd, unsigned long int index)
+{
+ struct MySQL_handle *h = (struct MySQL_handle *) hnd;
+ gboolean retval = FALSE;
+ struct MySQL_connection *c;
+
+ /* range check */
+ if (index >= hnd->num_connections)
+ {
+ errormsg ("Invalid connection index");
return (FALSE);
- }
+ }
- /* get connection */
- c =
- (struct MySQL_connection *)&((struct MySQL_connection *)hnd->
- connections)[index];
-
- /* TODO: thread safety */
- if (!c->base.connected)
- {
- c->handle = mysql_init(NULL);
+ /* get connection */
+ c =
+ (struct MySQL_connection *) &((struct MySQL_connection *)
+ hnd->connections)[index];
+
+ /* TODO: thread safety */
+ if (!c->base.connected)
+ {
+ c->handle = mysql_init (NULL);
if (c->handle == NULL)
- {
- errormsg("mysql_init() failed");
- return (FALSE);
- }
+ {
+ errormsg ("mysql_init() failed");
+ return (FALSE);
+ }
if (!mysql_real_connect
- (c->handle, hnd->hostname, hnd->username, hnd->password,
- hnd->dbname, hnd->port, hnd->unixsocket, 0))
- {
- errormsg("MySQL error: %s", mysql_error(c->handle));
- mysql_close(c->handle);
- c->handle = NULL;
- return (FALSE);
- }
+ (c->handle, hnd->hostname, hnd->username, hnd->password,
+ hnd->dbname, hnd->port, hnd->unixsocket, 0))
+ {
+ errormsg ("MySQL error: %s", mysql_error (c->handle));
+ mysql_close (c->handle);
+ c->handle = NULL;
+ return (FALSE);
+ }
c->base.connected = TRUE;
retval = TRUE;
- }
- return (retval);
- }
+ }
+ return (retval);
+}
static gboolean
-MySQL_disconnect(struct database_handle *hnd, unsigned long int index)
- {
- struct MySQL_handle *h = (struct MySQL_handle *)hnd;
- struct MySQL_connection *c;
-
- /* range check */
- if (index >= hnd->num_connections)
- return (FALSE);
+MySQL_disconnect (struct database_handle *hnd, unsigned long int index)
+{
+ struct MySQL_handle *h = (struct MySQL_handle *) hnd;
+ struct MySQL_connection *c;
+
+ /* range check */
+ if (index >= hnd->num_connections)
+ return (FALSE);
+
+ /* get connection */
+ c =
+ (struct MySQL_connection *) &((struct MySQL_connection *)
+ hnd->connections)[index];
+
+ /* if not connected, 'succeed' at disconnecting */
+ if (!c->base.connected)
+ return (TRUE);
+
+ /* TODO: thread safety */
+ mysql_close (c->handle);
+ c->handle = NULL;
+ c->base.connected = FALSE;
+ return (TRUE);
+}
- /* get connection */
- c =
- (struct MySQL_connection *)&((struct MySQL_connection *)hnd->
- connections)[index];
-
- /* if not connected, 'succeed' at disconnecting */
- if (!c->base.connected)
- return (TRUE);
-
- /* TODO: thread safety */
- mysql_close(c->handle);
- c->handle = NULL;
- c->base.connected = FALSE;
- return (TRUE);
- }
-
static struct query_result *
- MySQL_execute_query(struct database_handle *ph,
- QueryData * query, int *errorcode, char
**errormsg)
- {
- int dbtype;
- char *fieldname,*val;
- odl_class *c;
-
- /* result pointer */
- struct query_result *result = new_query_result();
-
- /* convert to actual type */
- struct MySQL_handle *h = (struct MySQL_handle *)ph;
-
- struct MySQL_connection *con;
-
- MYSQL_RES *res;
- MYSQL_ROW row;
- int err;
-
- /* claim a connection */
- con = (struct MySQL_connection *)ph->get_connection(ph);
- if( !con )
- {
- fprintf( stderr , "No available connection : should have aborted by
now.\n" );
- abort();
- }
+MySQL_execute_query (struct database_handle *ph,
+ QueryData * query, int *errorcode, char **errormsg)
+{
+ int dbtype;
+ char *fieldname, *val;
+ odl_class *c;
+
+ /* result pointer */
+ struct query_result *result = new_query_result ();
+
+ /* convert to actual type */
+ struct MySQL_handle *h = (struct MySQL_handle *) ph;
+
+ struct MySQL_connection *con;
+
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ int err;
+
+ /* claim a connection */
+ con = (struct MySQL_connection *) ph->get_connection (ph);
+ if (!con)
+ {
+ fprintf (stderr,
+ "No available connection : should have aborted by now.\n");
+ abort ();
+ }
- if (!result)
- {
+ if (!result)
+ {
if (errorcode)
- *errorcode = ( -1); /* TODO: meaningful
error codes */
+ *errorcode = (-1); /* TODO: meaningful error codes */
if (errormsg)
- *errormsg = g_strdup("out of memory");
+ *errormsg = g_strdup ("out of memory");
return (NULL);
- }
+ }
- /* TODO: database dependant quote mode selection */
- dbtype = OQL_DBTYPE_MYSQL;
- debug_output(DEBUGLEVEL_HIGH,"SQL query: '%s'",
- oql_query_as_sql(query, dbtype));
- c = odl_find_class( all_classes , oql_query_get_classname(query) , NULL );
- err = mysql_query(con->handle, oql_query_as_sql(query,dbtype));
- if (err == 0)
- {
+ /* TODO: database dependant quote mode selection */
+ dbtype = OQL_DBTYPE_MYSQL;
+ debug_output (DEBUGLEVEL_HIGH, "SQL query: '%s'",
+ oql_query_as_sql (query, dbtype));
+ c = odl_find_class (all_classes, oql_query_get_classname (query), NULL);
+ err = mysql_query (con->handle, oql_query_as_sql (query, dbtype));
+ if (err == 0)
+ {
/* query appeared to succeed */
- res = mysql_store_result(con->handle);
+ res = mysql_store_result (con->handle);
if (res == NULL)
- {
- if (mysql_field_count(con->handle) == 0)
+ {
+ if (mysql_field_count (con->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);
- result->success = TRUE;
+ /* query does not return rows, and didn't - ok */
+ /* eg delete, insert, or replace SQL statemenmts */
+ result->rows_affected = mysql_affected_rows (con->handle);
+ result->success = TRUE;
}
- else
+ 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;
- result->success = FALSE;
- return (result);
+ /* 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;
+ result->success = FALSE;
+ return (result);
}
- }
- else /* res != NULL */
- {
- /* returned some rows of data */
- result->rows_affected = 0;
- result->field_count = mysql_num_fields(res);
- result->success = TRUE;
+ }
+ else /* res != NULL */
+ {
+ /* returned some rows of data */
+ result->rows_affected = 0;
+ result->field_count = mysql_num_fields (res);
+ result->success = TRUE;
- /* for each entry, extract object ID */
- while (row = mysql_fetch_row(res))
+ /* 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;
-
- result->rows_affected++;
-
- /* 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++)
- {
- fieldname = (char *)oql_query_get_field_name( query , i );
- val = oql_translate_from_read( row[i] , c , fieldname ,
dbtype );
- add_field_to_result_row(r,val);
- }
- /* add entry to list */
- result->data = g_list_prepend(result->data, r);
+ /* TODO: create list of objectIDs - need class
+ definitions */
+ char *keydata = "";
+ int i;
+ DatabaseResultRow_t r = NULL;
+
+ result->rows_affected++;
+
+ /* 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++)
+ {
+ fieldname = (char *) oql_query_get_field_name (query, i);
+ val =
+ oql_translate_from_read (row[i], c, fieldname, dbtype);
+ add_field_to_result_row (r, val);
+ }
+ /* add entry to list */
+ result->data = g_list_prepend (result->data, r);
}
- mysql_free_result(res);
- }
- }
- else
- {
+ mysql_free_result (res);
+ }
+ }
+ else
+ {
/* error during query */
/* message("error: ", mysql_error(con->handle)); */
if (errorcode)
- *errorcode = ( -1); /* TODO: meaningful
error codes */
+ *errorcode = (-1); /* TODO: meaningful error codes */
if (errormsg)
- *errormsg = g_strdup(mysql_error(con->handle));
+ *errormsg = g_strdup (mysql_error (con->handle));
result->success = FALSE;
- }
- /* release this connection */
- con->base.available = TRUE;
- result->data = g_list_reverse(result->data);
- return (result);
- }
+ }
+ /* release this connection */
+ con->base.available = TRUE;
+ result->data = g_list_reverse (result->data);
+ return (result);
+}
static struct query_result *MySQL_delete_object
- (struct database_handle *ph,
- const char *classname, const char *key, int *errorcode, char
**errormsg)
- {
- struct query_result *retval = NULL;
- QueryData *q = oql_delete_object(classname, key);
-
-trace_functioncall();
- if (q)
- {
- retval = MySQL_execute_query(ph, q, errorcode, errormsg);
- oql_free_query(q);
- }
- else
- {
+ (struct database_handle *ph,
+ const char *classname, const char *key, int *errorcode, char **errormsg)
+{
+ struct query_result *retval = NULL;
+ QueryData *q = oql_delete_object (classname, key);
+
+ trace_functioncall ();
+ if (q)
+ {
+ retval = MySQL_execute_query (ph, q, errorcode, errormsg);
+ oql_free_query (q);
+ }
+ else
+ {
if (errorcode)
- *errorcode = ( -1); /* TODO: meaningful
error codes */
+ *errorcode = (-1); /* TODO: meaningful error codes */
if (errormsg)
- *errormsg = g_strdup("Could not create query");
- }
- return (retval);
- }
+ *errormsg = g_strdup ("Could not create query");
+ }
+ return (retval);
+}
static struct query_result *MySQL_delete_all_objects
- (struct database_handle *ph,
- const char *classname, const char *fieldname, const char *key, int
*errorcode, char **errormsg)
- {
- struct query_result *retval = NULL;
- QueryData *q = oql_delete_all_objects(classname,fieldname, key);
-
-trace_functioncall();
- if (q)
- {
- retval = MySQL_execute_query(ph, q, errorcode, errormsg);
- oql_free_query(q);
- }
- else
- {
+ (struct database_handle *ph,
+ const char *classname, const char *fieldname, const char *key,
+ int *errorcode, char **errormsg)
+{
+ struct query_result *retval = NULL;
+ QueryData *q = oql_delete_all_objects (classname, fieldname, key);
+
+ trace_functioncall ();
+ if (q)
+ {
+ retval = MySQL_execute_query (ph, q, errorcode, errormsg);
+ oql_free_query (q);
+ }
+ else
+ {
if (errorcode)
- *errorcode = ( -1); /* TODO: meaningful
error codes */
+ *errorcode = (-1); /* TODO: meaningful error codes */
if (errormsg)
- *errormsg = g_strdup("Could not create query");
- }
- return (retval);
- }
+ *errormsg = g_strdup ("Could not create query");
+ }
+ return (retval);
+}
static struct query_result *MySQL_write_object
- (struct database_handle *ph,
- ObjectData * cachedobject, int *errorcode, char **errormsg)
- {
- struct query_result *retval = NULL;
- QueryData *q;
- q = oql_write_object(cachedobject);
- if (q)
- {
- retval = MySQL_execute_query(ph, q, errorcode, errormsg);
- oql_free_query(q);
- }
- else
- {
+ (struct database_handle *ph,
+ ObjectData * cachedobject, int *errorcode, char **errormsg)
+{
+ struct query_result *retval = NULL;
+ QueryData *q;
+ q = oql_write_object (cachedobject);
+ if (q)
+ {
+ retval = MySQL_execute_query (ph, q, errorcode, errormsg);
+ oql_free_query (q);
+ }
+ else
+ {
if (errorcode)
- *errorcode = ( -1); /* TODO: meaningful
error codes */
+ *errorcode = (-1); /* TODO: meaningful error codes */
if (errormsg)
- *errormsg = g_strdup("Could not create write query");
- }
- return (retval);
- }
+ *errormsg = g_strdup ("Could not create write query");
+ }
+ return (retval);
+}
/* free memory */
static void
-MySQL_delete_database_handle(struct database_handle *hnd)
- {
- int i;
- struct MySQL_handle *h = (struct MySQL_handle *)hnd;
-
- if (h)
- {
- free_generic_database(hnd);
+MySQL_delete_database_handle (struct database_handle *hnd)
+{
+ int i;
+ struct MySQL_handle *h = (struct MySQL_handle *) hnd;
+
+ if (h)
+ {
+ free_generic_database (hnd);
if (h->base.connections)
- {
- for (i = 0; i < h->base.num_connections; i++)
+ {
+ for (i = 0; i < h->base.num_connections; i++)
{
- struct MySQL_connection *c
- =
- (struct MySQL_connection *) & ((struct
MySQL_connection *)
- hnd->connections)[i];
+ struct MySQL_connection *c
+ =
+ (struct MySQL_connection *) &((struct MySQL_connection *)
+ hnd->connections)[i];
- if (c->handle)
- mysql_close(c->handle);
+ if (c->handle)
+ mysql_close (c->handle);
}
- g_free(h->base.connections);
- }
+ g_free (h->base.connections);
+ }
- g_free(h);
- }
- }
+ g_free (h);
+ }
+}
static DatabaseDefinition *
-MySQL_read_database_definition(struct database_handle *hnd)
- {
- struct MySQL_handle *h = (struct MySQL_handle *)hnd;
- MYSQL *handle;
- MYSQL_RES *res;
- MYSQL_ROW row;
- char *buf;
- GList *l;
- int i;
- DatabaseDefinition *db = NULL;
- char *p;
-
- db = create_database_definition(h->base.name);
- if (!db)
+MySQL_read_database_definition (struct database_handle *hnd)
+{
+ struct MySQL_handle *h = (struct MySQL_handle *) hnd;
+ MYSQL *handle;
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ char *buf;
+ GList *l;
+ int i;
+ DatabaseDefinition *db = NULL;
+ char *p;
+
+ db = create_database_definition (h->base.name);
+ if (!db)
+ return (NULL);
+
+ /* connect to database */
+ handle = mysql_init (NULL);
+ if (!handle)
+ {
+ errormsg ("Failed to initialise MySQL connection.");
+ free_database_definition (db);
return (NULL);
-
- /* connect to database */
- handle = mysql_init(NULL);
- if (!handle)
- {
- errormsg("Failed to initialise MySQL connection.");
- free_database_definition(db);
+ }
+ if (!mysql_real_connect
+ (handle, hnd->hostname, hnd->username, hnd->password,
+ hnd->dbname, hnd->port, hnd->unixsocket, 0))
+ {
+ errormsg ("Failed to connect to MySQL database %s.", hnd->name);
+ mysql_close (handle);
+ free_database_definition (db);
return (NULL);
- }
- if (!mysql_real_connect
- (handle, hnd->hostname, hnd->username, hnd->password,
- hnd->dbname, hnd->port, hnd->unixsocket, 0))
- {
- errormsg("Failed to connect to MySQL database %s.", hnd->name);
- mysql_close(handle);
- free_database_definition(db);
- return (NULL);
- }
+ }
- /* get list of tables */
- res = mysql_list_tables(handle, NULL);
- if (!res)
- {
- errormsg("Failed to get MySQL table definitions from database %s.",
- hnd->name);
- mysql_close(handle);
- free_database_definition(db);
+ /* get list of tables */
+ res = mysql_list_tables (handle, NULL);
+ if (!res)
+ {
+ errormsg ("Failed to get MySQL table definitions from database %s.",
+ hnd->name);
+ mysql_close (handle);
+ free_database_definition (db);
return (NULL);
- }
- while ((row = mysql_fetch_row(res)) != NULL)
- {
+ }
+ while ((row = mysql_fetch_row (res)) != NULL)
+ {
char *name;
name = row[0];
- if( name[0] == '_' && name[1] == '_' )
- name += 2;
- add_database_table(db, row[0]);
+ if (name[0] == '_' && name[1] == '_')
+ name += 2;
+ add_database_table (db, row[0]);
/* message( " tab: %s" , row[0] ); */
- }
+ }
- /* for each table: */
- for (i = 0; i < count_database_tables(db); i++)
- {
- DatabaseTable *tab = get_database_table(db, i);
+ /* for each table: */
+ for (i = 0; i < count_database_tables (db); i++)
+ {
+ DatabaseTable *tab = get_database_table (db, i);
DatabaseColumn *c;
enum odl_fieldtype type;
int err;
/* get list of fields and types */
- buf = g_strdup_printf("SHOW COLUMNS FROM %s", tab->name);
- err = mysql_query(handle, buf);
- g_free(buf);
+ buf = g_strdup_printf ("SHOW COLUMNS FROM %s", tab->name);
+ err = mysql_query (handle, buf);
+ g_free (buf);
if (err)
- {
- errormsg
- ("Failed to get MySQL table %s definition from database %s.",
- tab->name, hnd->name);
- mysql_close(handle);
- free_database_definition(db);
- return (NULL);
- }
- res = mysql_store_result(handle);
+ {
+ errormsg
+ ("Failed to get MySQL table %s definition from database %s.",
+ tab->name, hnd->name);
+ mysql_close (handle);
+ free_database_definition (db);
+ return (NULL);
+ }
+ res = mysql_store_result (handle);
if (!res)
- {
- errormsg("Error storing query result");
- mysql_close(handle);
- free_database_definition(db);
- return (NULL);
- }
-
- if (mysql_num_rows(res) == 0)
- {
- /* no data in table? */
- message("Warning: no fields in table %s in database %s",
- tab->name, hnd->name);
- }
+ {
+ errormsg ("Error storing query result");
+ mysql_close (handle);
+ free_database_definition (db);
+ return (NULL);
+ }
+
+ if (mysql_num_rows (res) == 0)
+ {
+ /* no data in table? */
+ message ("Warning: no fields in table %s in database %s",
+ tab->name, hnd->name);
+ }
else
- {
- /* store column details */
- while ((row = mysql_fetch_row(res)) != NULL)
+ {
+ /* store column details */
+ while ((row = mysql_fetch_row (res)) != NULL)
{
- char * t = strchr(row[1], '(');
- char *name;
+ char *t = strchr (row[1], '(');
+ char *name;
- if (t)
- *t = '\0';
+ if (t)
+ *t = '\0';
- /* information only, type is ignored */
- /* ie: accuracy is not critical */
- /* except when display will be too confusing */
- if (g_strcasecmp(row[1], "char") == 0)
- type = DT_char;
- else if (g_strcasecmp(row[1], "int") == 0)
- type = DT_int;
- else
- type = DT_unknown;
-
- name = row[0];
- if( name[0] == '_' && name[1] == '_' )
- name += 2;
-
- /* convert further double underscores to a single dot */
- for( p=strstr(name,"__") ; p != NULL ; p=strstr(name,"__") )
- {
- int size;
- void *src,*dest;
-
- *p = '.';
- src = p+2;
- dest = p+1;
- size = strlen(src) + 1;
- memmove( dest , src , size );
- }
+ /* information only, type is ignored */
+ /* ie: accuracy is not critical */
+ /* except when display will be too confusing */
+ if (g_strcasecmp (row[1], "char") == 0)
+ type = DT_char;
+ else if (g_strcasecmp (row[1], "int") == 0)
+ type = DT_int;
+ else
+ type = DT_unknown;
+
+ name = row[0];
+ if (name[0] == '_' && name[1] == '_')
+ name += 2;
+
+ /* convert further double underscores to a single dot */
+ for (p = strstr (name, "__"); p != NULL;
+ p = strstr (name, "__"))
+ {
+ int size;
+ void *src, *dest;
+
+ *p = '.';
+ src = p + 2;
+ dest = p + 1;
+ size = strlen (src) + 1;
+ memmove (dest, src, size);
+ }
- add_database_column(tab, name, type);
+ add_database_column (tab, name, type);
}
- }
- }
- /* close the database */
- mysql_close(handle);
- return (db);
- }
+ }
+ }
+ /* close the database */
+ mysql_close (handle);
+ return (db);
+}
void
-MySQL_add_column_data(GString * buf, GList * l, const char *separator)
- {
- char *name;
- DBchange *c;
- int len;
+MySQL_add_column_data (GString * buf, GList * l, const char *separator)
+{
+ char *name;
+ DBchange *c;
+ int len;
- while (l)
- {
+ while (l)
+ {
c = (DBchange *) l->data;
- name = oql_quote_column( NULL , c->name , OQL_DBTYPE_MYSQL );
- g_string_append(buf, name);
- g_free( name );
- g_string_append(buf, " ");
+ name = oql_quote_column (NULL, c->name, OQL_DBTYPE_MYSQL);
+ g_string_append (buf, name);
+ g_free (name);
+ g_string_append (buf, " ");
switch (c->datatype)
- {
- 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:
- if( !c->format )
- g_string_sprintfa(buf, "TEXT"); /* <= 64k characters */
- else
- {
- len = atoi( c->format );
- if ( len < 256 ) g_string_sprintfa(buf, "TINYTEXT");
- else if( len < 65536 ) g_string_sprintfa(buf, "TEXT");
- else if( len < 16777216 ) g_string_sprintfa(buf, "MEDIUMTEXT");
- else g_string_sprintfa(buf, "LONGTEXT");
- }
- break;
- case DT_int:
- g_string_sprintfa(buf, "INT");
- break;
- case DT_date:
- g_string_sprintfa(buf, "DATE");
- break;
- case DT_time:
- g_string_sprintfa(buf, "TIME");
- break;
- case DT_datetime:
- g_string_sprintfa(buf, "DATETIME");
- break;
- case DT_bool:
- g_string_sprintfa(buf, "CHAR(1)");
- break;
- case DT_float:
- g_string_sprintfa(buf, "DOUBLE");
- break;
- case DT_unsignedint:
- g_string_sprintfa(buf, "INT UNSIGNED");
- break;
- case DT_object:
- g_string_sprintfa(buf, "CHAR(34)");
- break;
- default:
- break;
- }
+ {
+ 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:
+ if (!c->format)
+ g_string_sprintfa (buf, "TEXT"); /* <= 64k characters */
+ else
+ {
+ len = atoi (c->format);
+ if (len < 256)
+ g_string_sprintfa (buf, "TINYTEXT");
+ else if (len < 65536)
+ g_string_sprintfa (buf, "TEXT");
+ else if (len < 16777216)
+ g_string_sprintfa (buf, "MEDIUMTEXT");
+ else
+ g_string_sprintfa (buf, "LONGTEXT");
+ }
+ break;
+ case DT_int:
+ g_string_sprintfa (buf, "INT");
+ break;
+ case DT_date:
+ g_string_sprintfa (buf, "DATE");
+ break;
+ case DT_time:
+ g_string_sprintfa (buf, "TIME");
+ break;
+ case DT_datetime:
+ g_string_sprintfa (buf, "DATETIME");
+ break;
+ case DT_bool:
+ g_string_sprintfa (buf, "CHAR(1)");
+ break;
+ case DT_float:
+ g_string_sprintfa (buf, "DOUBLE");
+ break;
+ case DT_unsignedint:
+ g_string_sprintfa (buf, "INT UNSIGNED");
+ break;
+ case DT_object:
+ g_string_sprintfa (buf, "CHAR(34)");
+ break;
+ default:
+ break;
+ }
if (c->notnull)
- g_string_append(buf, " NOT NULL");
+ g_string_append (buf, " NOT NULL");
else
- g_string_append(buf, " ");
+ g_string_append (buf, " ");
- g_string_append(buf, separator);
- l = g_list_next(l);
- }
- }
+ g_string_append (buf, separator);
+ l = g_list_next (l);
+ }
+}
struct query_result *
- MySQL_update_tables(struct database_handle *h,
- gboolean remove_items, int *errorcode, char
**errormsg)
- {
- char *name;
- GString *buf;
- DatabaseChange *changes = NULL;
- GList *required = NULL;
- GList *tmp, *l;
- DatabaseDefinition *database = NULL;
- MYSQL *handle;
- MYSQL_RES *res;
- MYSQL_ROW row;
- 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 = odl_tree_list_classes(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);
- odl_namelist_free(required);
- required = NULL;
+MySQL_update_tables (struct database_handle *h,
+ gboolean remove_items, int *errorcode, char **errormsg)
+{
+ char *name;
+ GString *buf;
+ DatabaseChange *changes = NULL;
+ GList *required = NULL;
+ GList *tmp, *l;
+ DatabaseDefinition *database = NULL;
+ MYSQL *handle;
+ MYSQL_RES *res;
+ MYSQL_ROW row;
+ 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 = odl_tree_list_classes (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);
+ odl_namelist_free (required);
+ required = NULL;
- if (!changes)
- {
+ if (!changes)
+ {
/* no changes required! yay! */
/* don't care about a result - error msgs alreayd printed */
- message("No database changes.");
+ message ("No database changes.");
return (NULL);
- }
+ }
- 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"));
+ 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", h->name);
- while (tmp)
- {
- remove_message(changefile, (DBchange *) tmp->data);
- tmp = g_list_next(tmp);
- }
- fprintf(changefile, "\n\n");
+ /* 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", h->name);
+ while (tmp)
+ {
+ remove_message (changefile, (DBchange *) tmp->data);
+ tmp = g_list_next (tmp);
+ }
+ fprintf (changefile, "\n\n");
- if (!changes->adds)
- {
+ if (!changes->adds)
+ {
/* no additions, so don't both with the rest */
- fclose(changefile);
+ fclose (changefile);
return (NULL);
- }
+ }
- /* connect to database */
- handle = mysql_init(NULL);
- if (!handle)
- {
- errormsg("Failed to initialise MySQL connection.");
- fclose(changefile);
+ /* connect to database */
+ handle = mysql_init (NULL);
+ if (!handle)
+ {
+ errormsg ("Failed to initialise MySQL connection.");
+ fclose (changefile);
return (NULL);
- }
- if (!mysql_real_connect
- (handle, h->hostname, h->username, h->password,
- h->dbname, h->port, h->unixsocket, 0))
- {
- errormsg("Failed to connect to MySQL database %s.", h->name);
- mysql_close(handle);
- fclose(changefile);
+ }
+ if (!mysql_real_connect
+ (handle, h->hostname, h->username, h->password,
+ h->dbname, h->port, h->unixsocket, 0))
+ {
+ errormsg ("Failed to connect to MySQL database %s.", h->name);
+ mysql_close (handle);
+ fclose (changefile);
return (NULL);
- }
+ }
- /* update tables on server */
- tmp = changes->adds;
- fprintf(changefile, "These changes are being made automatically:\n\n");
- while (tmp)
- {
+ /* 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);
+ add_message (changefile, (DBchange *) tmp->data);
if (add->type == DBCH_ADD_TABLE)
- {
- /* for each new table, construct a CREATE command */
- buf = g_string_new("");
- name = oql_quote_column( add->name , NULL , OQL_DBTYPE_MYSQL );
- g_string_sprintf(buf, "CREATE TABLE %s (", name);
- g_free( name );
- MySQL_add_column_data(buf, add->columns, ", ");
- g_string_append(buf, "PRIMARY KEY (ObjectID) )");
- }
+ {
+ /* for each new table, construct a CREATE command */
+ buf = g_string_new ("");
+ name = oql_quote_column (add->name, NULL, OQL_DBTYPE_MYSQL);
+ g_string_sprintf (buf, "CREATE TABLE %s (", name);
+ g_free (name);
+ MySQL_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("");
- name = oql_quote_column( add->name , NULL , OQL_DBTYPE_MYSQL );
- g_string_sprintf(buf, "ALTER TABLE %s ADD ", name);
- g_free( name );
- MySQL_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';
- }
+ {
+ /* for each table with new columns, construct a MODIFY command
+ */
+ buf = g_string_new ("");
+ name = oql_quote_column (add->name, NULL, OQL_DBTYPE_MYSQL);
+ g_string_sprintf (buf, "ALTER TABLE %s ADD ", name);
+ g_free (name);
+ MySQL_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);
+ g_strdown (buf->str);
/* printf( "CREATE/ALTER QUERY: [%s]\n" , buf->str ); */
- err = mysql_query(handle, buf->str);
+ err = mysql_query (handle, buf->str);
if (err == 0)
- {
- /* query appeared to succeed */
- message( "[%s] succeeded\n\n" , buf->str );
- }
+ {
+ /* query appeared to succeed */
+ message ("[%s] succeeded\n\n", buf->str);
+ }
else
- {
- /* TODO: error handling */
- message( "[%s] failed\n" , buf->str );
- errormsg(mysql_error(handle));
- message( "\n" );
- }
-
- tmp = g_list_next(tmp);
- }
- fprintf(changefile, "\n");
- mysql_close(handle);
- fclose(changefile);
- message( "Done updating database" );
-
- /* don't care about a result - error msgs alreayd printed */
- return (NULL);
- }
+ {
+ /* TODO: error handling */
+ message ("[%s] failed\n", buf->str);
+ errormsg (mysql_error (handle));
+ message ("\n");
+ }
+
+ tmp = g_list_next (tmp);
+ }
+ fprintf (changefile, "\n");
+ mysql_close (handle);
+ fclose (changefile);
+ message ("Done updating database");
+
+ /* don't care about a result - error msgs alreayd printed */
+ return (NULL);
+}
/* initialise a connection to a specificv MySQL database */
static struct MySQL_handle *
- MySQL_create_database_handle(configuration config, const char *dbname)
- {
- int i;
- struct MySQL_handle *h =
-
- (struct MySQL_handle *)g_malloc(sizeof(struct MySQL_handle));
+MySQL_create_database_handle (configuration config, const char *dbname)
+{
+ int i;
+ struct MySQL_handle *h =
+ (struct MySQL_handle *) g_malloc (sizeof (struct MySQL_handle));
- if (h)
- {
+ if (h)
+ {
/* clear all pointers */
/* none here */
/* store general data */
if (!generic_database_config
- (config, dbname, (struct database_handle *)h))
- {
- MySQL_delete_database_handle((struct database_handle *)h);
- return (NULL);
- }
+ (config, dbname, (struct database_handle *) h))
+ {
+ MySQL_delete_database_handle ((struct database_handle *) h);
+ return (NULL);
+ }
/* h->whatever = MySQL specific options */
/* if fail, delete handle and return NULL */
@@ -811,34 +826,31 @@
/* create connection data storage */
h->base.connections =
+ (struct active_connection *) g_new0 (struct MySQL_connection,
+ h->base.num_connections);
- (struct active_connection *)g_new0(struct MySQL_connection,
- h->base.num_connections);
-
/* abort if resource acquisition failed */
if (!h->base.connections /* || !other data */ )
- {
- MySQL_delete_database_handle((struct database_handle *)h);
- return (NULL);
- }
+ {
+ MySQL_delete_database_handle ((struct database_handle *) h);
+ return (NULL);
+ }
/* initialise connections */
for (i = 0; i < h->base.num_connections; i++)
- {
- struct MySQL_connection *c
- =
- (struct MySQL_connection *) & ((struct MySQL_connection
*)h->
-
- base.connections)[i];
-
- /* set general state */
- c->base.available = TRUE;
- c->base.connected = FALSE;
-
- /* any MySQL specific data */
- c->handle = NULL; /* no connection yet */
- }
- }
- return (h);
- }
-
+ {
+ struct MySQL_connection *c
+ =
+ (struct MySQL_connection *) &((struct MySQL_connection *) h->base.
+ connections)[i];
+
+ /* set general state */
+ c->base.available = TRUE;
+ c->base.connected = FALSE;
+
+ /* any MySQL specific data */
+ c->handle = NULL; /* no connection yet */
+ }
+ }
+ return (h);
+}
Index: gnue/geas/src/objectstore/objectstore.c
diff -u gnue/geas/src/objectstore/objectstore.c:1.53
gnue/geas/src/objectstore/objectstore.c:1.54
--- gnue/geas/src/objectstore/objectstore.c:1.53 Mon May 14 14:57:57 2001
+++ gnue/geas/src/objectstore/objectstore.c Tue May 22 12:05:11 2001
@@ -1,22 +1,25 @@
/*
- geas - GNU Enterprise Application Server
-
+ Interface to the database backend(s)
+
Copyright (C) 2001 Free Software Foundation
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
+
+ This file is part of the GNU Enterprise Application Server (GEAS)
+
+ GEAS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ GEAS is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
+ along with GEAS; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ $Id: objectstore.c,v 1.54 2001/05/22 19:05:11 reinhard Exp $
*/
#include "config.h"
@@ -36,9 +39,8 @@
#ifdef MAX_DATABASE_CONNECTIONS
static int max_database_connections = MAX_DATABASE_CONNECTIONS;
#else
-static int max_database_connections = 1; /* default of 1 connection per
-
-database */
+static int max_database_connections = 1; /* default of 1 connection per
+ database */
#endif
/* forward references */
@@ -51,108 +53,103 @@
row = g_list_append(row,field)
/* database operations supported */
-typedef gboolean(*connect_function) (struct database_handle * h,
- unsigned long int index);
-typedef gboolean(*disconnect_function) (struct database_handle * h,
- unsigned long int index);
-typedef struct query_result *(*execute_query_function) (struct database_handle
*
- h,
- QueryData * query,
- int *errorcode,
-
- char **errormsg);
-
-typedef struct query_result *(*delete_object_function) (struct database_handle
*
- h,
- const char *classname,
- const char *key,
- int *errorcode,
-
- char **errormsg);
-typedef struct query_result *(*delete_all_objects_function) (struct
database_handle *
- h,
- const char *classname,
- const char *fieldname,
- const char *key,
- int *errorcode,
-
- char **errormsg);
-typedef struct query_result *(*write_object_function) (struct database_handle *
- h,
- ObjectData * cacheobject,
- int *errorcode,
-
- char **errormsg);
-
-typedef struct query_result *(*update_tables_function) (struct database_handle
*
- h,
- gboolean remove_items,
- int *errorcode,
+typedef gboolean (*connect_function) (struct database_handle * h,
+ unsigned long int index);
+typedef gboolean (*disconnect_function) (struct database_handle * h,
+ unsigned long int index);
+typedef struct query_result *(*execute_query_function) (struct database_handle
+ * h,
+ QueryData * query,
+ int *errorcode,
+ char **errormsg);
+
+typedef struct query_result *(*delete_object_function) (struct database_handle
+ * h,
+ const char *classname,
+ const char *key,
+ int *errorcode,
+ char **errormsg);
+typedef struct query_result *(*delete_all_objects_function) (struct
+ database_handle *
+ h,
+ const char
+ *classname,
+ const char
+ *fieldname,
+ const char *key,
+ int *errorcode,
+ char **errormsg);
+typedef struct query_result *(*write_object_function) (struct database_handle
+ * h,
+ ObjectData *
+ cacheobject,
+ int *errorcode,
+ char **errormsg);
+
+typedef struct query_result *(*update_tables_function) (struct database_handle
+ * h,
+ gboolean remove_items,
+ int *errorcode,
+ char **errormsg);
- char **errormsg);
-
typedef void (*delete_database_function) (struct database_handle * h);
typedef struct active_connection *(*get_connection_function) (struct
- database_handle *
-
- h);
+ database_handle
+ * h);
/* base structures */
struct database_handle
- {
- /* generic data */
- char *name; /* name this
entry */
- char *type; /* what DB
server is on the other end? */
-
- /* semi-generic database config */
- /* used by most servers */
- char *dbname, *username, *password, *hostname, *unixsocket;
- signed long int port;
- unsigned long int retries; /* times to retry before giving up */
-
- /* list of connections in use */
- unsigned long int num_connections;
- void *connections;
-
- /* functions to execute database operations */
- execute_query_function execute;
- connect_function connect;
- disconnect_function disconnect;
- delete_database_function delete_database;
- get_connection_function get_connection;
- delete_object_function delete_object;
- delete_all_objects_function delete_all_objects;
- write_object_function write_object;
- update_tables_function update_tables;
- };
+{
+ /* generic data */
+ char *name; /* name this entry */
+ char *type; /* what DB server is on the other end? */
+
+ /* semi-generic database config */
+ /* used by most servers */
+ char *dbname, *username, *password, *hostname, *unixsocket;
+ signed long int port;
+ unsigned long int retries; /* times to retry before giving up */
+
+ /* list of connections in use */
+ unsigned long int num_connections;
+ void *connections;
+
+ /* functions to execute database operations */
+ execute_query_function execute;
+ connect_function connect;
+ disconnect_function disconnect;
+ delete_database_function delete_database;
+ get_connection_function get_connection;
+ delete_object_function delete_object;
+ delete_all_objects_function delete_all_objects;
+ write_object_function write_object;
+ update_tables_function update_tables;
+};
struct active_connection
- {
- /* general data */
- int index;
- gboolean available; /* TRUE if no other threads
are using it */
- gboolean connected; /* TRUE if currently
connected to database */
- unsigned long int queue; /* count of threads waiting for this
-
connection */
- };
+{
+ /* general data */
+ int index;
+ gboolean available; /* TRUE if no other threads are using it */
+ gboolean connected; /* TRUE if currently connected to database */
+ unsigned long int queue; /* count of threads waiting for this
+ connection */
+};
/* maintain a list of databases in use */
static GList *database_list = NULL;
/* private function prototypes */
-static struct database_handle *find_database_handle(GList * list,
- const char *database,
- int *err, char **errmsg);
-static gboolean generic_database_config(configuration config,
-
- const char *database,
- struct database_handle *h);
-static void free_generic_database(struct database_handle *h);
-static struct query_result *new_query_result();
-static void
-remove_message(FILE * fp, DBchange * c);
-static void
-add_message(FILE * fp, DBchange * c);
+static struct database_handle *find_database_handle (GList * list,
+ const char *database,
+ int *err, char **errmsg);
+static gboolean generic_database_config (configuration config,
+ const char *database,
+ struct database_handle *h);
+static void free_generic_database (struct database_handle *h);
+static struct query_result *new_query_result ();
+static void remove_message (FILE * fp, DBchange * c);
+static void add_message (FILE * fp, DBchange * c);
/* create database handles for each supported database */
#ifdef USE_MYSQL
@@ -164,289 +161,312 @@
#ifdef USE_LIBGDA
#include "libgda_access.h"
#endif
-
-/* public functions */
+/* ========================================================================= *\
+ * public functions
+\* ========================================================================= */
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
void
-update_objectstore_databases(gboolean remove_items)
- {
- FILE *changefile;
- struct database_handle *h = NULL;
- const char *database = get_first_active_database(configdata); /* HACK
- HACK
- HACK
*/
-
- /* write header to change file */
- debug_output(DEBUGLEVEL_HIGH, "writing header to change file" );
- changefile =
- fopen(get_global_option_str
- (configdata, "databasechangefile", "database.changes.txt"), "w");
-
- if (changefile)
- {
- show_version(changefile, SHORT_VERSION);
- fprintf(changefile,
-
"===========================================================================\n");
- fprintf(changefile, "Database change requirements information\n");
- fprintf(changefile,
-
"===========================================================================\n\n");
- fclose(changefile);
- }
-
- /* automatic class storage installer */
-
- /* find the database */
- debug_output(DEBUGLEVEL_HIGH, "getting db handle" );
-
- h = find_database_handle(database_list, database, NULL, NULL);
- if (!h)
- {
- errormsg("Could not find database '%s'", database);
- return ;
- }
-
- /* make it update (TODO: error msg handling) */
- /* message( "updating..." ); */
- debug_output(DEBUGLEVEL_HIGH, "updating the tables" );
-
- h->update_tables(h, remove_items, NULL, NULL);
- }
-
+update_objectstore_databases (gboolean remove_items)
+{
+ FILE *changefile;
+ struct database_handle *h = NULL;
+ const char *database = get_first_active_database (configdata); /* HACK
+ HACK
+ HACK */
+
+ /* write header to change file */
+ debug_output (DEBUGLEVEL_HIGH, "writing header to change file");
+ changefile =
+ fopen (get_global_option_str
+ (configdata, "databasechangefile", "database.changes.txt"), "w");
+
+ if (changefile)
+ {
+ show_version (changefile, SHORT_VERSION);
+ fprintf (changefile,
+
"===========================================================================\n");
+ fprintf (changefile, "Database change requirements information\n");
+ fprintf (changefile,
+
"===========================================================================\n\n");
+ fclose (changefile);
+ }
+
+ /* automatic class storage installer */
+
+ /* find the database */
+ debug_output (DEBUGLEVEL_HIGH, "getting db handle");
+
+ h = find_database_handle (database_list, database, NULL, NULL);
+ if (!h)
+ {
+ errormsg ("Could not find database '%s'", database);
+ return;
+ }
+
+ /* make it update (TODO: error msg handling) */
+ /* message( "updating..." ); */
+ debug_output (DEBUGLEVEL_HIGH, "updating the tables");
+
+ h->update_tables (h, remove_items, NULL, NULL);
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
struct query_result *
- query_objectstore(QueryData * query, int *err, char **errmsg)
- {
- struct database_handle *h = NULL;
- struct query_result *retval = NULL;
- struct query_result *cacheresult = NULL;
- struct query_result *storeresult = NULL;
- struct active_connection *con = NULL;
- GList *l;
- const char *database = get_first_active_database(configdata); /* HACK
*/
-
- /* TODO: database dependant quote mode selection */
-trace_functioncall();
-
- /* clear error indicators */
- if (err)
- (*err) = 0;
- if (errmsg)
- (*errmsg) = NULL;
-
- /* find database handle named 'database' */
- /* self_test_message("Looking for database '%s'", database); */
- h = find_database_handle(database_list, database, err, errmsg);
- if (!h)
- return (NULL);
-
- /* finish off the query */
- /* add_order_by(query, NULL); */
-
- /* TODO: */
- /* cacheresult = search_cache( query ); */
-
- /*message( "-----------------------------------------" );*/
- /* execute query (errors passed back automatically) */
- /* TODO: if error == unexpected disconnection then try to reconnect */
- /* self_test_message("Executing"); */
+query_objectstore (QueryData * query, int *err, char **errmsg)
+{
+ struct database_handle *h = NULL;
+ struct query_result *retval = NULL;
+ struct query_result *cacheresult = NULL;
+ struct query_result *storeresult = NULL;
+ struct active_connection *con = NULL;
+ GList *l;
+ const char *database = get_first_active_database (configdata); /*
HACK */
+
+ /* TODO: database dependant quote mode selection */
+ trace_functioncall ();
+
+ /* clear error indicators */
+ if (err)
+ (*err) = 0;
+ if (errmsg)
+ (*errmsg) = NULL;
+
+ /* find database handle named 'database' */
+ /* self_test_message("Looking for database '%s'", database); */
+ h = find_database_handle (database_list, database, err, errmsg);
+ if (!h)
+ return (NULL);
+
+ /* finish off the query */
+ /* add_order_by(query, NULL); */
+
+ /* TODO: */
+ /* cacheresult = search_cache( query ); */
+
+ /*message( "-----------------------------------------" ); */
+ /* execute query (errors passed back automatically) */
+ /* TODO: if error == unexpected disconnection then try to reconnect */
+ /* self_test_message("Executing"); */
/* printf( "SQL: %s\n" , oql_query_as_sql(query,OQL_DBTYPE_CACHEONLY) ); */
- storeresult = h->execute(h, query, err, errmsg);
+ storeresult = h->execute (h, query, err, errmsg);
/* printf( "query done\n" ); */
#ifdef DEBUG
- if( errmsg && *errmsg && debuglevel > 1 )
- errormsg( "Query error: %s" , *errmsg );
+ if (errmsg && *errmsg && debuglevel > 1)
+ errormsg ("Query error: %s", *errmsg);
#endif
-
- /* TODO: */
- /* retval = merge_results(cacheresult,storeresult); */
- retval = storeresult; /* temp: return just the store result */
-
- if (retval)
- retval->query = query;
-
- /* done */
- return (retval);
- }
+ /* TODO: */
+ /* retval = merge_results(cacheresult,storeresult); */
+ retval = storeresult; /* temp: return just the store result */
+
+ if (retval)
+ retval->query = query;
+
+ /* done */
+ return (retval);
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
struct query_result *
- delete_from_objectstore(const char *classname, const char *key, int
*err,
- char **errmsg)
- {
- struct database_handle *h = NULL;
- struct query_result *retval = NULL;
- struct active_connection *con = NULL;
- GList *l;
- const char *database = get_first_active_database(configdata); /* HACK
*/
+delete_from_objectstore (const char *classname, const char *key, int *err,
+ char **errmsg)
+{
+ struct database_handle *h = NULL;
+ struct query_result *retval = NULL;
+ struct active_connection *con = NULL;
+ GList *l;
+ const char *database = get_first_active_database (configdata); /*
HACK */
+
+ trace_functioncall ();
+ if (!classname || !key)
+ return (NULL);
-trace_functioncall();
- if (!classname || !key)
- return (NULL);
-
/* message("Deleting %s/%s from database",classname,key); */
- /* clear error indicators */
- if (err)
- (*err) = 0;
- if (errmsg)
- (*errmsg) = NULL;
-
- /* find database handle named 'database' */
- /* self_test_message("Looking for database '%s'", database); */
- h = find_database_handle(database_list, database, err, errmsg);
- if (!h)
- return (NULL);
-
- /* execute query (errors passed back automatically) */
- /* self_test_message("Executing"); */
- retval = h->delete_object(h, classname, key, err, errmsg);
-
- /* done */
- return (retval);
- }
-
+ /* clear error indicators */
+ if (err)
+ (*err) = 0;
+ if (errmsg)
+ (*errmsg) = NULL;
+
+ /* find database handle named 'database' */
+ /* self_test_message("Looking for database '%s'", database); */
+ h = find_database_handle (database_list, database, err, errmsg);
+ if (!h)
+ return (NULL);
+
+ /* execute query (errors passed back automatically) */
+ /* self_test_message("Executing"); */
+ retval = h->delete_object (h, classname, key, err, errmsg);
+
+ /* done */
+ return (retval);
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
struct query_result *
- delete_all_from_objectstore(const char *classname,
- const char *fieldname,
- const char *key, int *err,
- char **errmsg)
- {
- struct database_handle *h = NULL;
- struct query_result *retval = NULL;
- struct active_connection *con = NULL;
- GList *l;
- const char *database = get_first_active_database(configdata); /* HACK
*/
+delete_all_from_objectstore (const char *classname,
+ const char *fieldname,
+ const char *key, int *err, char **errmsg)
+{
+ struct database_handle *h = NULL;
+ struct query_result *retval = NULL;
+ struct active_connection *con = NULL;
+ GList *l;
+ const char *database = get_first_active_database (configdata); /*
HACK */
+
+ trace_functioncall ();
+ if (!classname || !key)
+ return (NULL);
-trace_functioncall();
- if (!classname || !key)
- return (NULL);
-
/* message("Deleting %s from database where %s.%s =
%s",classname,classname,fieldname,key); */
-
- /* clear error indicators */
- if (err)
- (*err) = 0;
- if (errmsg)
- (*errmsg) = NULL;
-
- /* find database handle named 'database' */
- /* self_test_message("Looking for database '%s'", database); */
- h = find_database_handle(database_list, database, err, errmsg);
- if (!h)
- return (NULL);
-
- /* execute query (errors passed back automatically) */
- /* self_test_message("Executing"); */
- retval = h->delete_all_objects(h, classname,fieldname, key, err, errmsg);
-
- /* done */
- return (retval);
- }
+ /* clear error indicators */
+ if (err)
+ (*err) = 0;
+ if (errmsg)
+ (*errmsg) = NULL;
+
+ /* find database handle named 'database' */
+ /* self_test_message("Looking for database '%s'", database); */
+ h = find_database_handle (database_list, database, err, errmsg);
+ if (!h)
+ return (NULL);
+
+ /* execute query (errors passed back automatically) */
+ /* self_test_message("Executing"); */
+ retval = h->delete_all_objects (h, classname, fieldname, key, err, errmsg);
+
+ /* done */
+ return (retval);
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
struct query_result *
- write_to_objectstore(ObjectData * cachedobject, int *err, char
**errmsg)
- {
- struct database_handle *h = NULL;
- struct query_result *retval = NULL;
- struct active_connection *con = NULL;
- GList *l;
- const char *database = get_first_active_database(configdata); /* HACK
*/
-
-trace_functioncall(); if (!cachedobject)
- {
- errormsg("Null object to write");
+write_to_objectstore (ObjectData * cachedobject, int *err, char **errmsg)
+{
+ struct database_handle *h = NULL;
+ struct query_result *retval = NULL;
+ struct active_connection *con = NULL;
+ GList *l;
+ const char *database = get_first_active_database (configdata); /*
HACK */
+
+ trace_functioncall ();
+ if (!cachedobject)
+ {
+ errormsg ("Null object to write");
return (NULL);
- }
+ }
- /* message("Writing %s/%s to database", get_object_class(cachedobject) ,
- get_object_key(cachedobject) ); */
+ /* message("Writing %s/%s to database", get_object_class(cachedobject) ,
+ get_object_key(cachedobject) ); */
- /* clear error indicators */
- if (err)
- (*err) = 0;
- if (errmsg)
- (*errmsg) = NULL;
-
- /* find database handle named 'database' */
- /* self_test_message("Looking for database '%s'", database); */
- h = find_database_handle(database_list, database, err, errmsg);
- if (!h)
- {
- errormsg("Could not find database '%s'", database);
+ /* clear error indicators */
+ if (err)
+ (*err) = 0;
+ if (errmsg)
+ (*errmsg) = NULL;
+
+ /* find database handle named 'database' */
+ /* self_test_message("Looking for database '%s'", database); */
+ h = find_database_handle (database_list, database, err, errmsg);
+ if (!h)
+ {
+ errormsg ("Could not find database '%s'", database);
return (NULL);
- }
-
- /* execute query (errors passed back automatically) */
- /* self_test_message("Executing"); */
- retval = h->write_object(h, cachedobject, err, errmsg);
-
- /* done */
- return (retval);
- }
+ }
+ /* execute query (errors passed back automatically) */
+ /* self_test_message("Executing"); */
+ retval = h->write_object (h, cachedobject, err, errmsg);
+
+ /* done */
+ return (retval);
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
void
-free_query_result(struct query_result *result)
- {
- GList *ll, *fl;
+free_query_result (struct query_result *result)
+{
+ GList *ll, *fl;
- if (result)
- {
+ if (result)
+ {
if (result->data)
- {
- ll = result->data;
- while (ll)
+ {
+ ll = result->data;
+ while (ll)
{
- fl = (GList *) ll->data;
- while (fl)
- {
- if (fl->data)
- g_free(fl->data);
- fl = g_list_next(fl);
- }
- if (ll->data)
- g_list_free(ll->data);
- ll = g_list_next(ll);
+ fl = (GList *) ll->data;
+ while (fl)
+ {
+ if (fl->data)
+ g_free (fl->data);
+ fl = g_list_next (fl);
+ }
+ if (ll->data)
+ g_list_free (ll->data);
+ ll = g_list_next (ll);
}
- g_list_free(result->data);
- }
- g_free(result);
- }
- }
-
+ g_list_free (result->data);
+ }
+ g_free (result);
+ }
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
gboolean
-initialise_objectstore(configuration config)
- {
- int i;
- struct database_handle *h = NULL;
- gboolean succeeded = FALSE;
-
- /* for each database, create a new instance of the appropriate type */
- /* self_test_message("%d databases", count_configured_databases(config)); */
-
- for (i = 0; i < count_configured_databases(config); i++)
- {
- const char *dbname = get_database_name(config, i);
+initialise_objectstore (configuration config)
+{
+ int i;
+ struct database_handle *h = NULL;
+ gboolean succeeded = FALSE;
+
+ /* for each database, create a new instance of the appropriate type */
+ /* self_test_message("%d databases", count_configured_databases(config)); */
+
+ for (i = 0; i < count_configured_databases (config); i++)
+ {
+ const char *dbname = get_database_name (config, i);
const char *type;
/* self_test_message("init: database %d name: '%s'",i, dbname); */
/* if no name, ignore - should never happen, anyway */
if (!dbname)
- {
- continue; /* skip */
- }
+ {
+ continue; /* skip */
+ }
/* if not active, skip this entire entry */
- if (get_database_option_bool(config, dbname, "active", FALSE) == FALSE)
- {
- continue; /* skip */
- }
+ if (get_database_option_bool (config, dbname, "active", FALSE) == FALSE)
+ {
+ continue; /* skip */
+ }
/* find which database code to use */
- type = get_database_option(config, dbname, "type");
+ type = get_database_option (config, dbname, "type");
if (!type)
- {
- continue; /* skip */
- }
+ {
+ continue; /* skip */
+ }
/* self_test_message("Database %s: type = %s", dbname, type); */
@@ -455,433 +475,466 @@
to use */
#ifdef USE_MYSQL
- if (g_strcasecmp(type, "MySQL") == 0)
- {
- h =
- (struct database_handle *)MySQL_create_database_handle(config,
- dbname);
- succeeded = TRUE;
- }
+ if (g_strcasecmp (type, "MySQL") == 0)
+ {
+ h =
+ (struct database_handle *) MySQL_create_database_handle (config,
+ dbname);
+ succeeded = TRUE;
+ }
#endif
/* ******************** */
#ifdef USE_POSTGRESQL
- if (!succeeded && g_strcasecmp(type, "PostgreSQL") == 0)
- {
- h =(struct database_handle
*)PostgreSQL_create_database_handle(config, dbname);
- succeeded = TRUE;
- }
+ if (!succeeded && g_strcasecmp (type, "PostgreSQL") == 0)
+ {
+ h =
+ (struct database_handle *)
+ PostgreSQL_create_database_handle (config, dbname);
+ succeeded = TRUE;
+ }
#endif
/* ******************** */
#ifdef USE_LIBGDA
- if (!succeeded && g_strcasecmp(type, "libGDA") == 0)
- {
- h = (struct database_handle
*)libGDA_create_database_handle(config,dbname);
- succeeded = TRUE;
- }
+ if (!succeeded && g_strcasecmp (type, "libGDA") == 0)
+ {
+ h =
+ (struct database_handle *) libGDA_create_database_handle (config,
+ dbname);
+ succeeded = TRUE;
+ }
#endif
/* ******************** */
if (!succeeded)
- {
- errormsg
- ("Database '%s' is of type %s, but this is not supported or
could\nnot be initialised.\n",
- dbname, type);
- h = NULL;
- continue; /* go to next
item in list */
- }
+ {
+ errormsg
+ ("Database '%s' is of type %s, but this is not supported or
could\nnot be initialised.\n",
+ dbname, type);
+ h = NULL;
+ continue; /* go to next item in list */
+ }
/* add h to list of known databases */
if (h)
- {
- h->type = g_strdup(type);
- database_list = g_list_append(database_list, h);
- }
- }
- /* self_test_message( "Initialised %d databases" ,
- g_list_length(database_list) ); */
- }
-
+ {
+ h->type = g_strdup (type);
+ database_list = g_list_append (database_list, h);
+ }
+ }
+ /* self_test_message( "Initialised %d databases" ,
+ g_list_length(database_list) ); */
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
gboolean
-close_object_store()
- {
- GList *l;
- int i;
-
- trace_functioncall();
- l = database_list;
- while (l)
- {
- struct database_handle *h = (struct database_handle *)l->data;
+close_object_store ()
+{
+ GList *l;
+ int i;
+
+ trace_functioncall ();
+ l = database_list;
+ while (l)
+ {
+ struct database_handle *h = (struct database_handle *) l->data;
if (h)
- {
- for (i = 0; i < h->num_connections; i++)
+ {
+ for (i = 0; i < h->num_connections; i++)
{
- h->disconnect(h, i);
+ h->disconnect (h, i);
}
- h->delete_database(h);
- l->data = NULL;
- }
-
- l = g_list_next(l);
- }
- if (database_list)
- g_list_free(database_list);
- database_list = NULL;
- }
-
-/* private functions */
-
-/* find a database configuration by name */
+ h->delete_database (h);
+ l->data = NULL;
+ }
+
+ l = g_list_next (l);
+ }
+ if (database_list)
+ g_list_free (database_list);
+ database_list = NULL;
+}
+
+/* ========================================================================= *\
+ * private functions
+\* ========================================================================= */
+
+/* ------------------------------------------------------------------------- *\
+ * find a database configuration by name
+\* ------------------------------------------------------------------------- */
static struct database_handle *
- find_database_handle(GList * list, const char *database, int *err,
- char **errmsg)
- {
- struct database_handle *h = NULL;
-
- while (list)
- {
- h = (struct database_handle *)list->data;
+find_database_handle (GList * list, const char *database, int *err,
+ char **errmsg)
+{
+ struct database_handle *h = NULL;
+
+ while (list)
+ {
+ h = (struct database_handle *) list->data;
/* self_test_message( "%s = %s ?" , h->name, database ); */
- if (h && h->name && (g_strcasecmp(h->name, database) == 0))
- {
- /* self_test_message( "yep" ); */
- return (h);
- }
+ if (h && h->name && (g_strcasecmp (h->name, database) == 0))
+ {
+ /* self_test_message( "yep" ); */
+ return (h);
+ }
else
- {
- /* self_test_message( "nope" ); */
- h = NULL;
- }
- list = g_list_next(list);
- }
- if (!h)
- {
+ {
+ /* self_test_message( "nope" ); */
+ h = NULL;
+ }
+ list = g_list_next (list);
+ }
+ if (!h)
+ {
if (err)
- (*err) = -1; /* TODO:
meaningful error codes */
+ (*err) = -1; /* TODO: meaningful error codes */
if (errmsg)
- (*errmsg) =
- g_strdup_printf("Database '%s' was not configured.", database);
+ (*errmsg) =
+ g_strdup_printf ("Database '%s' was not configured.", database);
return (NULL);
- }
- return (h);
- }
-
+ }
+ return (h);
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
static gboolean
-generic_database_config(configuration config, const char *database,
- struct database_handle *h)
- {
- h->name = h->username = h->hostname = NULL;
- h->unixsocket = h->dbname = h->password = NULL;
-
- h->name = g_strdup(database);
- h->dbname =
- (char *)get_database_option_str(config, database, "dbname", NULL);
- h->username =
- (char *)get_database_option_str(config, database, "username", NULL);
- h->password =
- (char *)get_database_option_str(config, database, "password", NULL);
- h->hostname =
- (char *)get_database_option_str(config, database, "hostname", NULL);
- h->unixsocket =
- (char *)get_database_option_str(config, database, "unixsocket", NULL);
- h->port = get_database_option_int(config, database, "port", -1);
- h->retries = get_database_option_int(config, database, "retries", 0);
- h->num_connections =
- get_database_option_int(config, database, "connections", 5);
-
- /* copy data */
- if (h->dbname)
- h->dbname = g_strdup(h->dbname);
- else
- errormsg("Property 'database name' was not defined for database %s",
- database);
-
- if (h->username)
- h->username = g_strdup(h->username);
- /* not required */
-
- if (h->password)
- h->password = g_strdup(h->password);
- /* not required */
-
- if (h->hostname)
- h->hostname = g_strdup(h->hostname);
- /* not required */
-
- if (h->unixsocket)
- h->unixsocket = g_strdup(h->unixsocket);
- /* not required */
-
- /* force this to a valid range */
- if (h->num_connections > max_database_connections)
- h->num_connections = max_database_connections;
-
- if (h->num_connections < 1)
- h->num_connections = 1;
-
- /* clear this, for now */
- h->connections = NULL;
-
- /* check for valid data in required fields */
- if (!h->name)
- return (FALSE);
- else
- return (TRUE);
- }
-
+generic_database_config (configuration config, const char *database,
+ struct database_handle *h)
+{
+ h->name = h->username = h->hostname = NULL;
+ h->unixsocket = h->dbname = h->password = NULL;
+
+ h->name = g_strdup (database);
+ h->dbname =
+ (char *) get_database_option_str (config, database, "dbname", NULL);
+ h->username =
+ (char *) get_database_option_str (config, database, "username", NULL);
+ h->password =
+ (char *) get_database_option_str (config, database, "password", NULL);
+ h->hostname =
+ (char *) get_database_option_str (config, database, "hostname", NULL);
+ h->unixsocket =
+ (char *) get_database_option_str (config, database, "unixsocket", NULL);
+ h->port = get_database_option_int (config, database, "port", -1);
+ h->retries = get_database_option_int (config, database, "retries", 0);
+ h->num_connections =
+ get_database_option_int (config, database, "connections", 5);
+
+ /* copy data */
+ if (h->dbname)
+ h->dbname = g_strdup (h->dbname);
+ else
+ errormsg ("Property 'database name' was not defined for database %s",
+ database);
+
+ if (h->username)
+ h->username = g_strdup (h->username);
+ /* not required */
+
+ if (h->password)
+ h->password = g_strdup (h->password);
+ /* not required */
+
+ if (h->hostname)
+ h->hostname = g_strdup (h->hostname);
+ /* not required */
+
+ if (h->unixsocket)
+ h->unixsocket = g_strdup (h->unixsocket);
+ /* not required */
+
+ /* force this to a valid range */
+ if (h->num_connections > max_database_connections)
+ h->num_connections = max_database_connections;
+
+ if (h->num_connections < 1)
+ h->num_connections = 1;
+
+ /* clear this, for now */
+ h->connections = NULL;
+
+ /* check for valid data in required fields */
+ if (!h->name)
+ return (FALSE);
+ else
+ return (TRUE);
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
static void
-free_generic_database(struct database_handle *h)
- {
- if (h)
- {
+free_generic_database (struct database_handle *h)
+{
+ if (h)
+ {
if (h->name)
- g_free(h->name);
+ g_free (h->name);
if (h->username)
- g_free(h->username);
+ g_free (h->username);
if (h->password)
- g_free(h->password);
+ g_free (h->password);
if (h->hostname)
- g_free(h->hostname);
+ g_free (h->hostname);
if (h->dbname)
- g_free(h->dbname);
+ g_free (h->dbname);
if (h->unixsocket)
- g_free(h->unixsocket);
+ g_free (h->unixsocket);
if (h->type)
- g_free(h->type);
+ g_free (h->type);
/* do not free h->connections or h here */
- }
- }
+ }
+}
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
static struct query_result *
- new_query_result()
- {
- struct query_result *n =
-
- (struct query_result *)g_malloc(sizeof(struct query_result));
- if (n)
- {
+new_query_result ()
+{
+ struct query_result *n =
+ (struct query_result *) g_malloc (sizeof (struct query_result));
+ if (n)
+ {
n->success = FALSE;
n->rows_affected = 0;
n->data = NULL;
- }
- return (n);
- }
-
+ }
+ return (n);
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
static void
-remove_message(FILE * fp, DBchange * c)
- {
- GList *l;
-
- if (c->type == DBCH_UNKNOWN)
- {
- fprintf(fp, "Unknown remove change command.\n");
- return ;
- }
-
- fprintf(fp, "Remove: ");
- if (c->type == DBCH_REMOVE_TABLE)
- {
- fprintf(fp, "Table %s", c->name);
+remove_message (FILE * fp, DBchange * c)
+{
+ GList *l;
+
+ if (c->type == DBCH_UNKNOWN)
+ {
+ fprintf (fp, "Unknown remove change command.\n");
+ return;
+ }
+
+ fprintf (fp, "Remove: ");
+ if (c->type == DBCH_REMOVE_TABLE)
+ {
+ fprintf (fp, "Table %s", c->name);
if (c->columns)
- {
- fprintf(fp, "\nColumns:\n");
- l = c->columns;
- while (l)
+ {
+ fprintf (fp, "\nColumns:\n");
+ l = c->columns;
+ while (l)
{
- fprintf(fp, " %s", ((DBchange *) l->data)->name);
- l = g_list_next(l);
+ fprintf (fp, " %s", ((DBchange *) l->data)->name);
+ l = g_list_next (l);
}
- }
+ }
else
- {
- fprintf(fp, " (entire table)");
- }
- }
- fprintf(fp, "\n");
- }
-
+ {
+ fprintf (fp, " (entire table)");
+ }
+ }
+ fprintf (fp, "\n");
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
static void
-add_message(FILE * fp, DBchange * c)
- {
- GList *l;
- GString *buf;
-
- if (c->type == DBCH_UNKNOWN)
- {
- fprintf(fp, "Unknown remove change command.\n");
- return ;
- }
-
- buf = g_string_new("");
-
- if (c->type == DBCH_ADD_TABLE || c->type == DBCH_MODIFY_TABLE)
- {
- if (c->type == DBCH_MODIFY_TABLE)
- {
- g_string_append( buf , "Modify table " );
- g_string_append( buf , c->name );
- g_string_append( buf , ": Add columns " );
- fprintf(fp, "Modify: ");
- }
- else
- {
- g_string_append( buf , "Create table " );
- g_string_append( buf , c->name );
- g_string_append( buf , ": Columns " );
- fprintf(fp, "Add: ");
- }
+add_message (FILE * fp, DBchange * c)
+{
+ GList *l;
+ GString *buf;
+
+ if (c->type == DBCH_UNKNOWN)
+ {
+ fprintf (fp, "Unknown remove change command.\n");
+ return;
+ }
+
+ buf = g_string_new ("");
+
+ if (c->type == DBCH_ADD_TABLE || c->type == DBCH_MODIFY_TABLE)
+ {
+ if (c->type == DBCH_MODIFY_TABLE)
+ {
+ g_string_append (buf, "Modify table ");
+ g_string_append (buf, c->name);
+ g_string_append (buf, ": Add columns ");
+ fprintf (fp, "Modify: ");
+ }
+ else
+ {
+ g_string_append (buf, "Create table ");
+ g_string_append (buf, c->name);
+ g_string_append (buf, ": Columns ");
+ fprintf (fp, "Add: ");
+ }
- fprintf(fp, "Table %s", c->name);
+ fprintf (fp, "Table %s", c->name);
if (c->columns)
- {
- fprintf(fp, "\n Columns:\n");
- l = c->columns;
- while (l)
+ {
+ fprintf (fp, "\n Columns:\n");
+ l = c->columns;
+ while (l)
{
- g_string_append( buf , ((DBchange *) l->data)->name );
- g_string_append( buf , " " );
- g_string_append( buf , odl_datatype_name( ((DBchange *)
l->data)->datatype ) );
-
- if( ((DBchange *) l->data)->format ) {
- g_string_append( buf , "[" );
- g_string_append( buf , ((DBchange *) l->data)->format );
- g_string_append( buf , "]" );
- }
- fprintf(fp, " %s (%s%s%s)\n",
- ((DBchange *) l->data)->name,
- odl_datatype_name(((DBchange *) l->data)->
- datatype),
- ((DBchange *) l->data)->format !=
- NULL ? " : " : "",
- ((DBchange *) l->data)->format !=
- NULL ? ((DBchange *) l->data)->format : "");
-
- l = g_list_next(l);
- if(l) g_string_append( buf , "," );
+ g_string_append (buf, ((DBchange *) l->data)->name);
+ g_string_append (buf, " ");
+ g_string_append (buf,
+ odl_datatype_name (((DBchange *) l->data)->
+ datatype));
+
+ if (((DBchange *) l->data)->format)
+ {
+ g_string_append (buf, "[");
+ g_string_append (buf, ((DBchange *) l->data)->format);
+ g_string_append (buf, "]");
+ }
+ fprintf (fp, " %s (%s%s%s)\n",
+ ((DBchange *) l->data)->name,
+ odl_datatype_name (((DBchange *) l->data)->datatype),
+ ((DBchange *) l->data)->format !=
+ NULL ? " : " : "",
+ ((DBchange *) l->data)->format !=
+ NULL ? ((DBchange *) l->data)->format : "");
+
+ l = g_list_next (l);
+ if (l)
+ g_string_append (buf, ",");
}
- }
+ }
else
- {
- fprintf(fp, " (entire table)\n");
- }
- }
-
- dm_logentry( DM_EVENT_DATABASE , NULL , buf->str );
- g_string_free( buf , TRUE );
- }
+ {
+ fprintf (fp, " (entire table)\n");
+ }
+ }
+
+ dm_logentry (DM_EVENT_DATABASE, NULL, buf->str);
+ g_string_free (buf, TRUE);
+}
/* end of private functions */
#ifdef SELF_TEST
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
static void
-display_objectstore_status()
- {
- GList *l;
- int i;
-
- l = database_list;
- while (l)
- {
- struct database_handle *h = (struct database_handle *)l->data;
+display_objectstore_status ()
+{
+ GList *l;
+ int i;
+
+ l = database_list;
+ while (l)
+ {
+ struct database_handle *h = (struct database_handle *) l->data;
struct MySQL_handle *mysql;
struct MySQL_connection *c;
/*
- if (h)
- message("database: %s", h->name);
- else
- message("unknown database");
- */
- if (g_strcasecmp(h->type, "MySQL") == 0)
- {
- mysql = (struct MySQL_handle *)h;
- for (i = 0; i < h->num_connections; i++)
+ if (h)
+ message("database: %s", h->name);
+ else
+ message("unknown database");
+ */
+ if (g_strcasecmp (h->type, "MySQL") == 0)
+ {
+ mysql = (struct MySQL_handle *) h;
+ for (i = 0; i < h->num_connections; i++)
{
- struct MySQL_connection *c =
- (struct MySQL_connection *) & ((struct
MySQL_connection *)
- h->connections)[i];
-
- /* message("MySQL database %d: %s is %sconnected and is
- * %savailable", i, h->name, c->base.connected ? "" :
- * "not " , c->base.available ? "" : "not "); */
+ struct MySQL_connection *c =
+ (struct MySQL_connection *) &((struct MySQL_connection *)
+ h->connections)[i];
+
+ /* message("MySQL database %d: %s is %sconnected and is
+ * %savailable", i, h->name, c->base.connected ? "" :
+ * "not " , c->base.available ? "" : "not "); */
}
- }
-
- l = g_list_next(l);
- }
-
- }
+ }
+ l = g_list_next (l);
+ }
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
void
-self_test_objectstore()
- {
- char buf[1024];
- int err = 0;
- char *errmsg = NULL;
- struct QueryData *query;
- struct query_result *result = NULL;
- int passed = 0, failed = 0;
- int count = 0;
-
- while (1)
- {
- message("Testing object store: %d", ++count);
+self_test_objectstore ()
+{
+ char buf[1024];
+ int err = 0;
+ char *errmsg = NULL;
+ struct QueryData *query;
+ struct query_result *result = NULL;
+ int passed = 0, failed = 0;
+ int count = 0;
+
+ while (1)
+ {
+ message ("Testing object store: %d", ++count);
- display_objectstore_status();
+ display_objectstore_status ();
- query = oql_find_all_objects(configdata, "test");
+ query = oql_find_all_objects (configdata, "test");
if (!query)
- {
- /* TODO */
- continue;
- }
- result = query_objectstore(query, &err, &errmsg);
+ {
+ /* TODO */
+ continue;
+ }
+ result = query_objectstore (query, &err, &errmsg);
if (err != 0)
- {
- failed++;
- }
+ {
+ failed++;
+ }
else
- {
- int i, j;
+ {
+ int i, j;
- for (i = 0; i < result->rows_affected; i++)
+ for (i = 0; i < result->rows_affected; i++)
{
- printf("row %2d : ", i);
- for (j = 0; j < result->field_count; j++)
- {
- printf("%s.%s = %s\t", get_result_class_name(result),
- get_result_field_name(result, j),
- get_result_field(result, i, j));
- }
- printf("\n");
+ printf ("row %2d : ", i);
+ for (j = 0; j < result->field_count; j++)
+ {
+ printf ("%s.%s = %s\t", get_result_class_name (result),
+ get_result_field_name (result, j),
+ get_result_field (result, i, j));
+ }
+ printf ("\n");
}
- }
+ }
if (errmsg)
- g_free(errmsg);
+ g_free (errmsg);
if (result)
- passed = result->success;
+ passed = result->success;
- close_object_store();
- free_query_result(result);
+ close_object_store ();
+ free_query_result (result);
- initialise_objectstore(configdata);
+ initialise_objectstore (configdata);
break;
- }
+ }
- message("Object store tests completed. %d passed. %d failed.", passed,
+ message ("Object store tests completed. %d passed. %d failed.", passed,
failed);
- }
+}
#endif
Index: gnue/geas/src/objectstore/objectstore.h
diff -u gnue/geas/src/objectstore/objectstore.h:1.16
gnue/geas/src/objectstore/objectstore.h:1.17
--- gnue/geas/src/objectstore/objectstore.h:1.16 Wed Feb 28 17:55:35 2001
+++ gnue/geas/src/objectstore/objectstore.h Tue May 22 12:05:11 2001
@@ -1,26 +1,29 @@
-/*
- geas - GNU Enterprise Application Server
+/*
+ Interface to the database backend(s)
- Copyright (C) 2000 Free Software Foundation
+ Copyright (C) 2001 Free Software Foundation
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+ This file is part of the GNU Enterprise Application Server (GEAS)
+ GEAS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ GEAS is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ along with GEAS; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ $Id: objectstore.h,v 1.17 2001/05/22 19:05:11 reinhard Exp $
*/
-#ifndef MOD_OBJECTSTORE_H
-#define MOD_OBJECTSTORE_H
+#ifndef _OBJECTSTORE_H
+#define _OBJECTSTORE_H
#include <glib.h>
@@ -29,7 +32,7 @@
#include "oql/oql.h"
#include "geas-server.h"
-typedef void *DatabaseResultRow;
+typedef void *DatabaseResultRow;
/* THESE ARE ONLY VALID AFTER A SUCCESSFUL QUERY */
/* FAILED QUERIES CAN INVALIDATE THESE WITHOUT WARNING OR */
@@ -65,51 +68,48 @@
*/
struct query_result
{
- /* what were we trying to do? */
- QueryData *query;
-
- /* did it actually succeed? */
- gboolean success;
-
- /* number of rows affected, usually - not guaranteed */
- /* will be set to the number of rows returned, if any */
- int rows_affected;
- int field_count; /* and the number of fields per row */
-
- /* data found : SELECT query only, otherwise NULL */
- GList *data; /* NULL also means no data - check success field */
+ QueryData *query; /* what were we trying to do? */
+ gboolean success; /* did it actually succeed? */
+ int rows_affected; /* number of rows affected, usually -
+ not guaranteed; will be set to the
+ number of rows returned, if any */
+ int field_count; /* and the number of fields per row */
+
+ GList *data; /* data found : SELECT query only,
+ otherwise NULL; NULL also means no
+ data - check success field */
};
-gboolean initialise_object_store( configuration config );
-gboolean close_object_store();
-void free_query_result( struct query_result *result );
+gboolean initialise_object_store (configuration config);
+gboolean close_object_store ();
+void free_query_result (struct query_result *result);
/* NOTE: pass in NULL for errcode and/or errmsg if you don't wish
* to receive them. if you do pass values in, you must free the string
* allocated and stored in *errmsg */
/* perform a query */
-struct query_result *
- query_objectstore(QueryData *query, int *err,
- char **errmsg);
+struct query_result *query_objectstore (QueryData * query, int *err,
+ char **errmsg);
/* delete an object from the database */
-struct query_result *
- delete_from_objectstore( const char *classname ,
- const char *key , int *err , char **errmsg );
-
-struct query_result *
-delete_all_from_objectstore( const char *classname , const char *field,
- const char *key , int *err , char **errmsg );
+struct query_result *delete_from_objectstore (const char *classname,
+ const char *key, int *err,
+ char **errmsg);
+
+struct query_result *delete_all_from_objectstore (const char *classname,
+ const char *field,
+ const char *key, int *err,
+ char **errmsg);
/* write data from object cache to the datastore */
/* once this function returns, the object may be removed instantly,
so should not be accessed again, such as from another thread */
-struct query_result *
- write_to_objectstore( ObjectData *cachedobject , int *err , char **errmsg );
+struct query_result *write_to_objectstore (ObjectData * cachedobject,
+ int *err, char **errmsg);
/* go through all active databases, and make sure they contain */
/* the appropriate tables */
-void update_objectstore_databases( gboolean remove_items );
+void update_objectstore_databases (gboolean remove_items);
-#endif
+#endif /* not _OBJECTSTORE_H */
Index: gnue/geas/src/objectstore/postgresql_access.h
diff -u gnue/geas/src/objectstore/postgresql_access.h:1.25
gnue/geas/src/objectstore/postgresql_access.h:1.26
--- gnue/geas/src/objectstore/postgresql_access.h:1.25 Mon May 14 14:57:57 2001
+++ gnue/geas/src/objectstore/postgresql_access.h Tue May 22 12:05:12 2001
@@ -1,881 +1,949 @@
-
/*
- geas - GNU Enterprise Application Server
-
+ Interface to PostgreSQL Database
+
Copyright (C) 2001 Free Software Foundation
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
+
+ This file is part of the GNU Enterprise Application Server (GEAS)
+
+ GEAS is free software; you can redistribute it and/or modify it under
+ the terms of the GNU General Public License as published by the Free
+ Software Foundation; either version 2, or (at your option) any later
+ version.
+
+ GEAS is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ for more details.
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-
+ along with GEAS; if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ $Id: postgresql_access.h,v 1.26 2001/05/22 19:05:12 reinhard Exp $
*/
+/* This is not really a header file. It's rather a piece of code that is
+ included conditionally. */
+
/* postgresql support */
#ifndef USE_POSTGRESQL
#error "--with-postgresql was not used when building GEAS"
#endif
-/* #include <postgres.h> */
#include "libpq-fe.h"
-/* database specific data structures */
+/* ========================================================================= *\
+ * Database specific data structures
+\* ========================================================================= */
+
+/* ------------------------------------------------------------------------- *\
+ * Connection
+\* ------------------------------------------------------------------------- */
struct postgresql_connection
- {
- /* the first line must be: struct active_connection base; */
- struct active_connection base;
-
- /* any postgresql specific data goes here */
- /* one structure is allocated per connection to a database */
- PGconn *handle;
- };
+{
+ /* the first line must be: struct active_connection base; */
+ struct active_connection base;
+ /* any postgresql specific data goes here */
+ /* one structure is allocated per connection to a database */
+ PGconn *handle;
+};
+
+/* ------------------------------------------------------------------------- *\
+ * Database handle
+\* ------------------------------------------------------------------------- */
struct postgresql_handle
- {
- /* the first line must be: struct database_handle base; */
- struct database_handle base;
-
- /* any postgresql specific data goes here */
- /* one structure is allocated per distinct database in use */
- };
+{
+ /* the first line must be: struct database_handle base; */
+ struct database_handle base;
-/* handle postgresql produced NOTICE messages */
+ /* any postgresql specific data goes here */
+ /* one structure is allocated per distinct database in use */
+};
+
+/* ========================================================================= *\
+ * Database specific functions
+\* ========================================================================= */
+
+/* ------------------------------------------------------------------------- *\
+ * handle postgresql produced NOTICE messages
+\* ------------------------------------------------------------------------- */
void
-postgres_notice_processor( void *arg , const char *msg )
+postgres_notice_processor (void *arg, const char *msg)
{
- /* only print notices when debugging, for now */
- debug_output( DEBUGLEVEL_10 , msg );
+ /* only print notices when debugging, for now */
+ debug_output (DEBUGLEVEL_10, msg);
}
-/* find a connection to the database that is available for use */
+/* ------------------------------------------------------------------------- *\
+ * find a connection to the database that is available for use
+\* ------------------------------------------------------------------------- */
struct active_connection *
- postgresql_get_connection(struct database_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;
- int i;
-
- /*
- * find available connection: * first available and connected connection
*
- else first available and non connected and connect it immediately * else
- first connected with lowest queue * else fail * */
-
- /* available and connected */
- /* TODO: make connection check depend on actual database state, to detect *
- unexpected disconnections */
- for (i = 0; i < h->base.num_connections; i++)
- {
+postgresql_get_connection (struct database_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;
+ int i;
+
+ /*
+ * find available connection:
+ * first available and connected connection
+ * else first available and non connected and connect it immediately
+ * else first connected with lowest queue
+ * else fail
+ */
+
+ /* available and connected */
+ /* TODO: make connection check depend on actual database state, to detect *
+ unexpected disconnections */
+ for (i = 0; i < h->base.num_connections; i++)
+ {
retval =
- (struct active_connection *) & ((struct postgresql_connection *)h->
- base.connections)[i];
+ (struct active_connection *) &((struct postgresql_connection *)
+ h->base.connections)[i];
if (retval->available && retval->connected)
- {
- retval->index = i;
- retval->available = FALSE;
- return (retval);
- }
- }
-
- /* available and not connected, if connection succeeds */
- for (i = 0; i < h->base.num_connections; i++)
- {
+ {
+ retval->index = i;
+ retval->available = FALSE;
+ return (retval);
+ }
+ }
+
+ /* available and not connected, if connection succeeds */
+ for (i = 0; i < h->base.num_connections; i++)
+ {
retval =
- (struct active_connection *) & ((struct postgresql_connection *)h->
- base.connections)[i];
+ (struct active_connection *) &((struct postgresql_connection *)
+ h->base.connections)[i];
if (retval->available && !retval->connected)
- {
- /* try to connect to database */
- if (hnd->connect(hnd, i))
+ {
+ /* try to connect to database */
+ if (hnd->connect (hnd, i))
{
- return (retval);
+ return (retval);
}
- }
- }
+ }
+ }
- fprintf(stderr, "\nTODO: handle no connection\n");
- fprintf(stderr,
+ fprintf (stderr, "\nTODO: handle no connection\n");
+ fprintf (stderr,
"needs to wait until a connection ebcomes available, as another\n");
- fprintf(stderr, "thread has the connection\n\n");
- abort();
- }
+ fprintf (stderr, "thread has the connection\n\n");
+ abort ();
+}
-/* activate a connection, so it can be used */
+/* ------------------------------------------------------------------------- *\
+ * activate a connection, so it can be used
+\* ------------------------------------------------------------------------- */
static gboolean
-postgresql_connect(struct database_handle *hnd, unsigned long int index)
- {
- struct postgresql_handle *h = (struct postgresql_handle *)hnd;
- gboolean retval = FALSE;
- struct postgresql_connection *c;
- char *pgoptions, *pgtty;
- char tmpport[20];
- PGresult *res;
-
- pgtty = NULL;
- pgoptions = NULL;
-
- /* range check */
- if (index >= hnd->num_connections)
- {
+postgresql_connect (struct database_handle *hnd, unsigned long int index)
+{
+ struct postgresql_handle *h = (struct postgresql_handle *) hnd;
+ gboolean retval = FALSE;
+ struct postgresql_connection *c;
+ char *pgoptions, *pgtty;
+ char tmpport[20];
+ PGresult *res;
+
+ pgtty = NULL;
+ pgoptions = NULL;
+
+ /* range check */
+ if (index >= hnd->num_connections)
+ {
errormsg
- ("Invalid connection index, your trying to access a handle not
registered");
+ ("Invalid connection index, your trying to access a handle not
registered");
return (FALSE);
- }
+ }
- /* get connection, point it to the handle connection */
- c = (struct postgresql_connection *)&((struct postgresql_connection *)hnd->
- connections)[index];
-
- /* TODO: imaginary thread safety for andrewm. */
- if (!c->base.connected)
- {
- sprintf(tmpport,"%d",hnd->port);
+ /* get connection, point it to the handle connection */
+ c =
+ (struct postgresql_connection *) &((struct postgresql_connection *)
+ hnd->connections)[index];
+
+ /* TODO: imaginary thread safety for andrewm. */
+ if (!c->base.connected)
+ {
+ sprintf (tmpport, "%d", hnd->port);
c->handle =
- PQsetdbLogin(hnd->hostname, tmpport, pgoptions, pgtty,
+ PQsetdbLogin (hnd->hostname, tmpport, pgoptions, pgtty,
hnd->dbname, hnd->username, hnd->password);
- PQsetNoticeProcessor( c->handle , postgres_notice_processor , NULL );
+ PQsetNoticeProcessor (c->handle, postgres_notice_processor, NULL);
/* check to see that the backend connection was successfully made */
if (c->handle == NULL)
- {
- errormsg("failed to initilise postgresql");
- return (FALSE);
- }
+ {
+ errormsg ("failed to initilise postgresql");
+ return (FALSE);
+ }
/* it kinda got a connection but got refused for some reason */
- if (PQstatus(c->handle) == CONNECTION_BAD)
- {
- errormsg("Connection to database '%s' failed: %s\n", hnd->dbname,
- PQerrorMessage(c->handle));
- PQfinish(c->handle);
- c->handle = NULL;
- return (FALSE);
- }
+ if (PQstatus (c->handle) == CONNECTION_BAD)
+ {
+ errormsg ("Connection to database '%s' failed: %s\n", hnd->dbname,
+ PQerrorMessage (c->handle));
+ PQfinish (c->handle);
+ c->handle = NULL;
+ return (FALSE);
+ }
/* do a test listen */
- res = PQexec(c->handle, "LISTEN TBL2");
- if (PQresultStatus(res) != PGRES_COMMAND_OK)
- {
- errormsg("LISTEN command failed on postgresql connection\n");
- PQclear(res);
- PQfinish(c->handle);
- c->handle = NULL;
- return (FALSE);
- }
- PQclear(res);
+ res = PQexec (c->handle, "LISTEN TBL2");
+ if (PQresultStatus (res) != PGRES_COMMAND_OK)
+ {
+ errormsg ("LISTEN command failed on postgresql connection\n");
+ PQclear (res);
+ PQfinish (c->handle);
+ c->handle = NULL;
+ return (FALSE);
+ }
+ PQclear (res);
c->base.connected = TRUE;
retval = TRUE;
- }
- return (retval);
- }
-
-/* deactivate a connection */
-
-/* who reads comments anyway?... well i do sometiems when i'm confused or its
not my code.
- I'm guessing this is not your code or its andru looking at this a week or 2
from now */
-
-/* i think i'm hungry ... */
+ }
+ return (retval);
+}
-/* go and eat, then? */
+/* ------------------------------------------------------------------------- *\
+ * deactivate a connection
+\* ------------------------------------------------------------------------- */
static gboolean
-postgresql_disconnect(struct database_handle *hnd, unsigned long int index)
- {
- struct postgresql_handle *h = (struct postgresql_handle *)hnd;
- struct postgresql_connection *c;
-
- /* range check */
- if (index >= hnd->num_connections)
- return (FALSE);
+postgresql_disconnect (struct database_handle *hnd, unsigned long int index)
+{
+ struct postgresql_handle *h = (struct postgresql_handle *) hnd;
+ struct postgresql_connection *c;
- /* get connection */
- c = (struct postgresql_connection *)&((struct postgresql_connection *)hnd->
- connections)[index];
-
- /* if not connected, 'succeed' at disconnecting */
- if (!c->base.connected)
- return (TRUE);
-
- /* TODO: andru's imagainary thread safety */
- PQfinish(c->handle);
- c->handle = NULL;
- c->base.connected = FALSE;
- return (TRUE);
- }
+ /* range check */
+ if (index >= hnd->num_connections)
+ return (FALSE);
+
+ /* get connection */
+ c =
+ (struct postgresql_connection *) &((struct postgresql_connection *)
+ hnd->connections)[index];
+
+ /* if not connected, 'succeed' at disconnecting */
+ if (!c->base.connected)
+ return (TRUE);
+
+ /* TODO: andru's imagainary thread safety */
+ PQfinish (c->handle);
+ c->handle = NULL;
+ c->base.connected = FALSE;
+ return (TRUE);
+}
-/* perform an arbitrary query */
+/* ------------------------------------------------------------------------- *\
+ * perform an arbitrary query
+\* ------------------------------------------------------------------------- */
static struct query_result *
- postgresql_execute_query(struct database_handle *ph,
- QueryData * query, int *errorcode, char
**errormsg)
- {
- int dbtype;
- struct query_result *result = new_query_result(); /* result pointer */
- struct postgresql_handle *h = (struct postgresql_handle *)ph; /* convert to
actual type */
- struct postgresql_connection *conn;
- odl_class *c;
- char *fieldname;
-
- PGresult *res = NULL;
- int nfields, nrows;
- int row, i;
- int tries=0;
- int PQerrorcode;
-
- /* claim a connection */
- conn = (struct postgresql_connection *)ph->get_connection(ph);
- if (!conn)
- {
- errormsg("No available connection : should have aborted by now.\n");
- abort();
- }
+postgresql_execute_query (struct database_handle *ph,
+ QueryData * query, int *errorcode, char **errormsg)
+{
+ int dbtype;
+ struct query_result *result = new_query_result (); /* result pointer */
+ /* convert to actual type */
+ struct postgresql_handle *h = (struct postgresql_handle *) ph;
+ struct postgresql_connection *conn;
+ odl_class *c;
+ char *fieldname;
+
+ PGresult *res = NULL;
+ int nfields, nrows;
+ int row, i;
+ int tries = 0;
+ int PQerrorcode;
+
+ /* claim a connection */
+ conn = (struct postgresql_connection *) ph->get_connection (ph);
+ if (!conn)
+ {
+ errormsg ("No available connection : should have aborted by now.\n");
+ abort ();
+ }
- if (!result)
- {
+ if (!result)
+ {
if (errorcode)
- *errorcode = ( -1); /* TODO: meaningful
error codes */
+ *errorcode = (-1); /* TODO: meaningful error codes */
if (errormsg)
- *errormsg = g_strdup("out of memory");
+ *errormsg = g_strdup ("out of memory");
return (NULL);
- }
+ }
- dbtype = OQL_DBTYPE_POSTGRESQL;
- debug_output(DEBUGLEVEL_HIGH, "SQL query: '%s'",oql_query_as_sql(query,
dbtype));
+ dbtype = OQL_DBTYPE_POSTGRESQL;
+ debug_output (DEBUGLEVEL_HIGH, "SQL query: '%s'",
+ oql_query_as_sql (query, dbtype));
- c = odl_find_class( all_classes , oql_query_get_classname(query) , NULL );
+ c = odl_find_class (all_classes, oql_query_get_classname (query), NULL);
retry:
- tries++;
- res = PQexec(conn->handle, oql_query_as_sql(query, dbtype));
- PQerrorcode = PQresultStatus(res);
+ tries++;
+ res = PQexec (conn->handle, oql_query_as_sql (query, dbtype));
+ PQerrorcode = PQresultStatus (res);
#if 0
- if( PQerrorcode != PGRES_FATAL_ERROR )
- {
- char buf[16];
- printf( "msg: '%s'\n" , PQresultErrorMessage(res) );
- printf( "Fake database failure? (Y/N) " );
- fflush( NULL );
- gets(buf);
- if( buf[0] == 'y' || buf[0] == 'Y' ) {
- PQerrorcode = PGRES_FATAL_ERROR;
- printf( "PQerrorcode = %d\n" , PQerrorcode );
- }
- }
+ if (PQerrorcode != PGRES_FATAL_ERROR)
+ {
+ char buf[16];
+ printf ("msg: '%s'\n", PQresultErrorMessage (res));
+ printf ("Fake database failure? (Y/N) ");
+ fflush (NULL);
+ gets (buf);
+ if (buf[0] == 'y' || buf[0] == 'Y')
+ {
+ PQerrorcode = PGRES_FATAL_ERROR;
+ printf ("PQerrorcode = %d\n", PQerrorcode);
+ }
+ }
#endif
- if (PQerrorcode == PGRES_COMMAND_OK) /* query does not return rows,
-
and didn't - ok */
- {
+ if (PQerrorcode == PGRES_COMMAND_OK) /* query does not return rows,
+ and didn't - ok */
+ {
result->success = TRUE;
result->rows_affected = 0;
- /*message( "[ok, no rows expected] rows affected: %d" ,
result->rows_affected ); */
- }
- else if (PQerrorcode == PGRES_TUPLES_OK) /* returned some rows of
-
data */
- {
- /*message( "[ok, data rows expected] rows affected: %d" ,
result->rows_affected );*/
- result->rows_affected = PQntuples(res);
- result->field_count = PQnfields(res);
+ /* message ("[ok, no rows expected] rows affected: %d",
+ result->rows_affected ); */
+ }
+ else if (PQerrorcode == PGRES_TUPLES_OK) /* returned some rows of
+ data */
+ {
+ /* message ("[ok, data rows expected] rows affected: %d",
+ result->rows_affected ); */
+ 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++)
+ {
+ 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++)
{
- char *val = PQgetvalue(res, row, i);
- char *p = val;
- /* printf( " > '%s' " , val ); */
- while( p[strlen(p)-1] == ' ' ) p[strlen(p)-1] = '\0';
- /* printf( " '%s'\n" , val ); */
- fieldname = (char *)oql_query_get_field_name( query , i );
- val = oql_translate_from_read( val , c , fieldname , dbtype );
- add_field_to_result_row(r,val);
+ char *val = PQgetvalue (res, row, i);
+ char *p = val;
+ /* printf( " > '%s' " , val ); */
+ while (p[strlen (p) - 1] == ' ')
+ p[strlen (p) - 1] = '\0';
+ /* printf( " '%s'\n" , val ); */
+ fieldname = (char *) oql_query_get_field_name (query, i);
+ val = oql_translate_from_read (val, c, fieldname, dbtype);
+ add_field_to_result_row (r, val);
}
- result->data = g_list_prepend(result->data, r);
- }
- if( res != NULL ) PQclear(res);
+ result->data = g_list_prepend (result->data, r);
+ }
+ if (res != NULL)
+ PQclear (res);
res = NULL;
- }
- else
- {
- switch( PQerrorcode )
- {
- case PGRES_FATAL_ERROR:
- debug_output( DEBUGLEVEL_7, "PostgreSQL reported a fatal error" );
- break;
- case PGRES_NONFATAL_ERROR:
- debug_output( DEBUGLEVEL_7, "PostgreSQL reported a non fatal
error" );
- break;
- case PGRES_BAD_RESPONSE:
- debug_output( DEBUGLEVEL_7, "PostgreSQL reported a bad response"
);
- break;
- case PGRES_COPY_IN:
- debug_output( DEBUGLEVEL_7, "PostgreSQL reported a copy in error"
);
- break;
- case PGRES_COPY_OUT:
- debug_output( DEBUGLEVEL_7, "PostgreSQL reported a copy out
error" );
- break;
- case PGRES_EMPTY_QUERY:
- debug_output( DEBUGLEVEL_7, "PostgreSQL reported an empty query"
);
- break;
- }
- debug_output( DEBUGLEVEL_7 , "PostgreSQL Error message: %s (%d)" ,
PQresultErrorMessage(res) , PQerrorcode );
-
- if( strncmp(PQresultErrorMessage(res),"ERROR: ExecAppend: Fail to add
null value in not null attribute",64)==0 )
- {
- PQerrorcode = PGRES_NONFATAL_ERROR;
- }
-
- if( PQerrorcode == PGRES_FATAL_ERROR )
- {
- /* something really bad happened: */
- /* disconnect & reconnect then try again */
- if( res != NULL ) PQclear(res);
- res = NULL;
- debug_output( DEBUGLEVEL_8 , "disconnecting..." );
- ph->disconnect( ph , conn->base.index );
- debug_output( DEBUGLEVEL_8 , "reconnecting..." );
- ph->connect ( ph , conn->base.index );
- if( tries <= ph->retries )
- {
- /* we can try again, now :) */
- if( res != NULL ) PQclear(res);
- res = NULL;
- goto retry;
- }
- else {
- errormsg( "Retries exceeded limit with fatal database errors.
(limit of %d attempts)" , 1+ph->retries );
- errormsg( "Last error message: %s" , PQresultErrorMessage(res)
);
- }
- }
+ }
+ else
+ {
+ switch (PQerrorcode)
+ {
+ case PGRES_FATAL_ERROR:
+ debug_output (DEBUGLEVEL_7, "PostgreSQL reported a fatal error");
+ break;
+ case PGRES_NONFATAL_ERROR:
+ debug_output (DEBUGLEVEL_7,
+ "PostgreSQL reported a non fatal error");
+ break;
+ case PGRES_BAD_RESPONSE:
+ debug_output (DEBUGLEVEL_7, "PostgreSQL reported a bad response");
+ break;
+ case PGRES_COPY_IN:
+ debug_output (DEBUGLEVEL_7, "PostgreSQL reported a copy in error");
+ break;
+ case PGRES_COPY_OUT:
+ debug_output (DEBUGLEVEL_7, "PostgreSQL reported a copy out error");
+ break;
+ case PGRES_EMPTY_QUERY:
+ debug_output (DEBUGLEVEL_7, "PostgreSQL reported an empty query");
+ break;
+ }
+ debug_output (DEBUGLEVEL_7, "PostgreSQL Error message: %s (%d)",
+ PQresultErrorMessage (res), PQerrorcode);
+
+ if (strncmp
+ (PQresultErrorMessage (res),
+ "ERROR: ExecAppend: Fail to add null value in not null attribute",
+ 64) == 0)
+ {
+ PQerrorcode = PGRES_NONFATAL_ERROR;
+ }
+
+ if (PQerrorcode == PGRES_FATAL_ERROR)
+ {
+ /* something really bad happened: */
+ /* disconnect & reconnect then try again */
+ if (res != NULL)
+ PQclear (res);
+ res = NULL;
+ debug_output (DEBUGLEVEL_8, "disconnecting...");
+ ph->disconnect (ph, conn->base.index);
+ debug_output (DEBUGLEVEL_8, "reconnecting...");
+ ph->connect (ph, conn->base.index);
+ if (tries <= ph->retries)
+ {
+ /* we can try again, now :) */
+ if (res != NULL)
+ PQclear (res);
+ res = NULL;
+ goto retry;
+ }
+ else
+ {
+ errormsg
+ ("Retries exceeded limit with fatal database errors. (limit of
%d attempts)",
+ 1 + ph->retries);
+ errormsg ("Last error message: %s", PQresultErrorMessage (res));
+ }
+ }
if (errorcode)
- *errorcode = ( -1);
+ *errorcode = (-1);
if (errormsg)
- *errormsg = g_strdup(PQresultErrorMessage(res));
+ *errormsg = g_strdup (PQresultErrorMessage (res));
result->success = FALSE;
- if( res != NULL ) PQclear(res);
+ if (res != NULL)
+ PQclear (res);
res = NULL;
- }
- /* release this connection */
- conn->base.available = TRUE;
- result->data = g_list_reverse(result->data);
- return (result);
- }
-
-/* delete an object from the database, given a classname and object key */
-static struct query_result *postgresql_delete_object
- (struct database_handle *ph,
- const char *classname, const char *key, int *errorcode, char
**errormsg)
- {
- struct query_result *retval = NULL;
- QueryData *q = oql_delete_object(classname, key);
-
- if (q)
- {
- retval = postgresql_execute_query(ph, q, errorcode, errormsg);
- oql_free_query(q);
- }
- else
- {
+ }
+ /* release this connection */
+ conn->base.available = TRUE;
+ result->data = g_list_reverse (result->data);
+ return (result);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * delete an object from the database, given a classname and object key
+\* ------------------------------------------------------------------------- */
+static struct query_result *
+postgresql_delete_object (struct database_handle *ph, const char *classname,
+ const char *key, int *errorcode, char **errormsg)
+{
+ struct query_result *retval = NULL;
+ QueryData *q = oql_delete_object (classname, key);
+
+ if (q)
+ {
+ retval = postgresql_execute_query (ph, q, errorcode, errormsg);
+ oql_free_query (q);
+ }
+ else
+ {
+ if (errorcode)
+ *errorcode = (-1); /* TODO: meaningful error codes */
+ if (errormsg)
+ *errormsg = g_strdup ("Could not create query");
+ }
+ return (retval);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * delete all records that have a specific value in a specific key
+\* ------------------------------------------------------------------------- */
+static struct query_result *
+postgresql_delete_all_objects (struct database_handle *ph,
+ const char *classname, const char *field,
+ const char *key, int *errorcode, char
**errormsg)
+{
+ struct query_result *retval = NULL;
+ QueryData *q = oql_delete_all_objects (classname, field, key);
+
+ if (q)
+ {
+ retval = postgresql_execute_query (ph, q, errorcode, errormsg);
+ oql_free_query (q);
+ }
+ else
+ {
if (errorcode)
- *errorcode = ( -1); /* TODO: meaningful
error codes */
+ *errorcode = (-1); /* TODO: meaningful error codes */
if (errormsg)
- *errormsg = g_strdup("Could not create query");
- }
- return (retval);
- }
-
-static struct query_result *postgresql_delete_all_objects
- (struct database_handle *ph,
- const char *classname, const char *field, const char *key, int
*errorcode, char **errormsg)
- {
- struct query_result *retval = NULL;
- QueryData *q = oql_delete_all_objects(classname, field, key);
-
- if (q)
- {
- retval = postgresql_execute_query(ph, q, errorcode, errormsg);
- oql_free_query(q);
- }
- else
- {
+ *errormsg = g_strdup ("Could not create query");
+ }
+ return (retval);
+}
+
+/* ------------------------------------------------------------------------- *\
+ * save an object to the database from the object cache
+\* ------------------------------------------------------------------------- */
+static struct query_result *
+postgresql_write_object (struct database_handle *ph, ObjectData * cachedobject,
+ int *errorcode, char **errormsg)
+{
+ struct query_result *retval = NULL;
+ QueryData *q;
+ q = oql_write_object (cachedobject);
+ if (q)
+ {
+ retval = postgresql_execute_query (ph, q, errorcode, errormsg);
+ oql_free_query (q);
+ }
+ else
+ {
if (errorcode)
- *errorcode = ( -1); /* TODO: meaningful
error codes */
+ *errorcode = (-1); /* TODO: meaningful error codes */
if (errormsg)
- *errormsg = g_strdup("Could not create query");
- }
- return (retval);
- }
-
-/* save an object to the database from the object cache */
-static struct query_result *postgresql_write_object
- (struct database_handle *ph,
- ObjectData * cachedobject, int *errorcode, char **errormsg)
- {
- struct query_result *retval = NULL;
- QueryData *q;
- q = oql_write_object(cachedobject);
- if (q)
- {
- retval = postgresql_execute_query(ph, q, errorcode, errormsg);
- oql_free_query(q);
- }
- else
- {
- if (errorcode)
- *errorcode = ( -1); /* TODO:
meaningful error codes */
- if (errormsg)
- *errormsg = g_strdup("Could not create write query");
- }
- return (retval);
- }
+ *errormsg = g_strdup ("Could not create write query");
+ }
+ return (retval);
+}
-/* free memory */
+/* ------------------------------------------------------------------------- *\
+ * free memory
+\* ------------------------------------------------------------------------- */
static void
-postgresql_delete_database_handle(struct database_handle *hnd)
- {
- int i;
- struct postgresql_handle *h = (struct postgresql_handle *)hnd;
-
- if (h)
- {
- free_generic_database(hnd);
+postgresql_delete_database_handle (struct database_handle *hnd)
+{
+ int i;
+ struct postgresql_handle *h = (struct postgresql_handle *) hnd;
+
+ if (h)
+ {
+ free_generic_database (hnd);
if (h->base.connections)
- {
- for (i = 0; i < h->base.num_connections; i++)
+ {
+ for (i = 0; i < h->base.num_connections; i++)
{
- struct postgresql_connection *c
- =
- (struct postgresql_connection *) & ((struct
postgresql_connection *)
- hnd->connections)[i];
+ struct postgresql_connection *c
+ =
+ (struct postgresql_connection *)
+ &((struct postgresql_connection *) hnd->connections)[i];
- if (c->handle)
- PQfinish(c->handle);
+ if (c->handle)
+ PQfinish (c->handle);
}
- g_free(h->base.connections);
- }
+ g_free (h->base.connections);
+ }
- g_free(h);
- }
- }
+ g_free (h);
+ }
+}
-/* read the tables and columns from the current database */
+/* ------------------------------------------------------------------------- *\
+ * read the tables and columns from the current database
+\* ------------------------------------------------------------------------- */
static DatabaseDefinition *
-postgresql_read_database_definition(struct database_handle *hnd)
- {
- struct postgresql_handle *h = (struct postgresql_handle *)hnd;
- PGconn *handle;
- PGresult *res;
- char *buf;
- char tmpport[20];
- GList *l;
- int i, j, row;
- DatabaseDefinition *db = NULL;
-
- db = create_database_definition(h->base.name);
- if (!db)
+postgresql_read_database_definition (struct database_handle *hnd)
+{
+ struct postgresql_handle *h = (struct postgresql_handle *) hnd;
+ PGconn *handle;
+ PGresult *res;
+ char *buf;
+ char tmpport[20];
+ GList *l;
+ int i, j, row;
+ DatabaseDefinition *db = NULL;
+
+ db = create_database_definition (h->base.name);
+ if (!db)
+ return (NULL);
+
+ sprintf (tmpport, "%d", hnd->port);
+ /* connect to database */
+ handle =
+ PQsetdbLogin (hnd->hostname, tmpport, NULL, NULL, hnd->dbname,
+ hnd->username, hnd->password);
+
+ if (handle == NULL)
+ {
+ errormsg ("handle came back as null.");
+ free_database_definition (db);
return (NULL);
-
- sprintf(tmpport,"%d",hnd->port);
- /* connect to database */
- handle =
- PQsetdbLogin(hnd->hostname, tmpport, NULL, NULL, hnd->dbname,
- hnd->username, hnd->password);
-
- if (handle==NULL)
- {
- errormsg("handle came back as null.");
- free_database_definition(db);
- return (NULL);
- }
- PQsetNoticeProcessor( handle , postgres_notice_processor , NULL );
- if (PQstatus(handle) == CONNECTION_BAD)
- {
- errormsg("Connection to database '%s' failed: %s\n", hnd->dbname,
- PQerrorMessage(handle));
- PQfinish(handle);
+ }
+ PQsetNoticeProcessor (handle, postgres_notice_processor, NULL);
+ if (PQstatus (handle) == CONNECTION_BAD)
+ {
+ errormsg ("Connection to database '%s' failed: %s\n", hnd->dbname,
+ PQerrorMessage (handle));
+ PQfinish (handle);
handle = NULL;
- free_database_definition(db);
- return (NULL);
- }
-
- /* get list of tables */
- res = PQexec(handle,"SELECT tablename FROM pg_tables WHERE tableowner !=
'postgres'");
- if (!res)
- {
- errormsg("Failed to get postgresql table definitions from database %s.",
- hnd->name);
- PQfinish(handle);
- free_database_definition(db);
+ free_database_definition (db);
+ return (NULL);
+ }
+
+ /* get list of tables */
+ res =
+ PQexec (handle,
+ "SELECT tablename FROM pg_tables WHERE tableowner != 'postgres'");
+ if (!res)
+ {
+ errormsg
+ ("Failed to get postgresql table definitions from database %s.",
+ hnd->name);
+ PQfinish (handle);
+ free_database_definition (db);
return (NULL);
- }
- for(i=0;i<PQntuples(res);i++)
- {
- add_database_table(db, PQgetvalue(res,i,0));
+ }
+ for (i = 0; i < PQntuples (res); i++)
+ {
+ add_database_table (db, PQgetvalue (res, i, 0));
/* message( " tab: %s" , row[0] ); */
- }
- PQclear(res);
+ }
+ PQclear (res);
- /* for each table: */
- for (i = 0; i < count_database_tables(db); i++)
- {
- DatabaseTable *tab = get_database_table(db, i);
+ /* for each table: */
+ for (i = 0; i < count_database_tables (db); i++)
+ {
+ DatabaseTable *tab = get_database_table (db, i);
DatabaseColumn *c;
enum odl_fieldtype type;
int err;
/* get list of fields and types */
- /* printf( "handling table '%s'\n" , tab->name ); */
- buf = g_strdup_printf("select a.attname, t.typname "
- "from pg_class c, pg_attribute a, pg_type t "
- "where c.relname = '%s' and "
- "a.attnum > 0 and "
- "a.attrelid = c.oid and "
- "a.atttypid = t.oid", tab->name);
- debug_output(DEBUGLEVEL_HIGH, "query will be\n%s",buf);
-
- res = PQexec(handle, buf);
- g_free(buf);
- if (PQresultStatus(res) != PGRES_TUPLES_OK)
- {
- errormsg
- ("Failed to get postgresql table %s definition from database %s.",
- tab->name, hnd->name);
- PQclear(res);
- free_database_definition(db);
- return (NULL);
- }
- if(PQntuples(res)<=0)
- message("Warning: no fields in table %s in database %s",
+ /* printf( "handling table '%s'\n" , tab->name ); */
+ buf = g_strdup_printf ("select a.attname, t.typname "
+ "from pg_class c, pg_attribute a, pg_type t "
+ "where c.relname = '%s' and "
+ "a.attnum > 0 and "
+ "a.attrelid = c.oid and "
+ "a.atttypid = t.oid", tab->name);
+ debug_output (DEBUGLEVEL_HIGH, "query will be\n%s", buf);
+
+ res = PQexec (handle, buf);
+ g_free (buf);
+ if (PQresultStatus (res) != PGRES_TUPLES_OK)
+ {
+ errormsg
+ ("Failed to get postgresql table %s definition from database %s.",
+ tab->name, hnd->name);
+ PQclear (res);
+ free_database_definition (db);
+ return (NULL);
+ }
+ if (PQntuples (res) <= 0)
+ message ("Warning: no fields in table %s in database %s",
tab->name, hnd->name);
- for (row = 0; row < PQntuples(res); row++)
- {
- char *name,*p;
+ for (row = 0; row < PQntuples (res); row++)
+ {
+ char *name, *p;
- if (g_strcasecmp(PQgetvalue(res,row,1),"char") == 0)
+ if (g_strcasecmp (PQgetvalue (res, row, 1), "char") == 0)
type = DT_char;
- else if (g_strcasecmp(PQgetvalue(res,row,1), "int") == 0)
+ else if (g_strcasecmp (PQgetvalue (res, row, 1), "int") == 0)
type = DT_int;
- else
+ else
type = DT_unknown;
+
+ /* convert further double underscores to a single dot */
+ name = g_strdup (PQgetvalue (res, row, 0));
+ for (p = strstr (name, "__"); p != NULL; p = strstr (name, "__"))
+ {
+ int size;
+ void *src, *dest;
+
+ *p = '.';
+ src = p + 2;
+ dest = p + 1;
+ size = strlen (src) + 1;
+ memmove (dest, src, size);
+ }
- /* convert further double underscores to a single dot */
- name = g_strdup( PQgetvalue(res,row,0) );
- for( p=strstr(name,"__") ; p != NULL ; p=strstr(name,"__") )
- {
- int size;
- void *src,*dest;
-
- *p = '.';
- src = p+2;
- dest = p+1;
- size = strlen(src) + 1;
- memmove( dest , src , size );
- }
-
- add_database_column(tab,name,type);
- g_free( name );
- }
- PQclear(res);
- }
- /* close the database */
- PQfinish(handle);
- return (db);
- }
-
+ add_database_column (tab, name, type);
+ g_free (name);
+ }
+ PQclear (res);
+ }
+ /* close the database */
+ PQfinish (handle);
+ return (db);
+}
+
+/* ------------------------------------------------------------------------- *\
+ *
+\* ------------------------------------------------------------------------- */
void
-postgresql_add_column_data(GString * buf, GList * l, const char *separator)
- {
- DBchange *c;
- char *name;
+postgresql_add_column_data (GString *buf, GList *l, const char *separator)
+{
+ DBchange *c;
+ char *name;
- while (l)
- {
+ while (l)
+ {
c = (DBchange *) l->data;
- name = oql_quote_column( NULL , c->name , OQL_DBTYPE_POSTGRESQL );
- g_string_append(buf, name);
- g_free( name );
- g_string_append(buf, " ");
+ name = oql_quote_column (NULL, c->name, OQL_DBTYPE_POSTGRESQL);
+ g_string_append (buf, name);
+ g_free (name);
+ g_string_append (buf, " ");
switch (c->datatype)
- {
- case DT_date:
- g_string_sprintfa(buf, "DATE");
- break;
- case DT_time:
- g_string_sprintfa(buf, "TIME");
- break;
- case DT_datetime:
- g_string_sprintfa(buf, "TIMESTAMP");
- break;
- case DT_float:
- /* TODO: proper float type */
- g_string_sprintfa(buf, "CHAR(16)");
- break;
- case DT_bool:
- g_string_sprintfa(buf, "CHAR(1)");
- break;
- 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, "TEXT");
- break;
- case DT_int:
- g_string_sprintfa(buf, "INT");
- break;
- case DT_unsignedint:
- g_string_sprintfa(buf, "INT");
- break;
- case DT_object:
- g_string_sprintfa(buf, "CHAR(34)");
- break;
- default:
- printf( "unknown type: %d %s\n" , c->datatype ,
odl_datatype_name(c->datatype) );
- g_string_sprintfa(buf, "UNKNOWN_TYPE");
- break;
- }
+ {
+ case DT_date:
+ g_string_sprintfa (buf, "DATE");
+ break;
+ case DT_time:
+ g_string_sprintfa (buf, "TIME");
+ break;
+ case DT_datetime:
+ g_string_sprintfa (buf, "TIMESTAMP");
+ break;
+ case DT_float:
+ /* TODO: proper float type */
+ g_string_sprintfa (buf, "CHAR(16)");
+ break;
+ case DT_bool:
+ g_string_sprintfa (buf, "CHAR(1)");
+ break;
+ 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, "TEXT");
+ break;
+ case DT_int:
+ g_string_sprintfa (buf, "INT");
+ break;
+ case DT_unsignedint:
+ g_string_sprintfa (buf, "INT");
+ break;
+ case DT_object:
+ g_string_sprintfa (buf, "CHAR(34)");
+ break;
+ default:
+ printf ("unknown type: %d %s\n", c->datatype,
+ odl_datatype_name (c->datatype));
+ g_string_sprintfa (buf, "UNKNOWN_TYPE");
+ break;
+ }
if (c->notnull)
- g_string_append(buf, " NOT NULL");
+ g_string_append (buf, " NOT NULL");
else
- g_string_append(buf, " ");
+ g_string_append (buf, " ");
- g_string_append(buf, separator);
- l = g_list_next(l);
- }
- }
+ g_string_append (buf, separator);
+ l = g_list_next (l);
+ }
+}
-/* update a */
+/* ------------------------------------------------------------------------- *\
+ * Update the table scheme in the db to fit the current class definition
+\* ------------------------------------------------------------------------- */
struct query_result *
- postgresql_update_tables(struct database_handle *hnd,
- gboolean remove_items, int *errorcode, char
**errormsg)
- {
- char *name;
- GString *buf;
- DatabaseChange *changes = NULL;
- GList *required = NULL;
- GList *tmp, *l;
- char tmpport[20];
- DatabaseDefinition *database = NULL;
- PGconn *handle;
- PGresult *res;
- int err;
- FILE *changefile;
-
- debug_output(DEBUGLEVEL_HIGH, "pg - updating the tables");
-
- /* 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 = odl_tree_list_classes(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 = postgresql_read_database_definition(hnd);
- /* 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);
- odl_namelist_free(required);
- required = NULL;
+postgresql_update_tables (struct database_handle *hnd,
+ gboolean remove_items, int *errorcode,
+ char **errormsg)
+{
+ char *name;
+ GString *buf;
+ DatabaseChange *changes = NULL;
+ GList *required = NULL;
+ GList *tmp, *l;
+ char tmpport[20];
+ DatabaseDefinition *database = NULL;
+ PGconn *handle;
+ PGresult *res;
+ int err;
+ FILE *changefile;
+
+ debug_output (DEBUGLEVEL_HIGH, "pg - updating the tables");
+
+ /* 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 = odl_tree_list_classes (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 = postgresql_read_database_definition (hnd);
+ /* 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);
+ odl_namelist_free (required);
+ required = NULL;
- if (!changes)
- {
+ if (!changes)
+ {
/* no changes required! yay! */
/* don't care about a result - error msgs alreayd printed */
- message("No database changes.");
+ message ("No database changes.");
return (NULL);
- }
+ }
- 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"));
+ 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");
+ }
+ /* 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)
- {
+ if (!changes->adds)
+ {
/* no additions, so don't both with the rest */
- fclose(changefile);
+ fclose (changefile);
return (NULL);
- }
- /* connect to database */
- sprintf(tmpport,"%d",hnd->port);
- handle =
- PQsetdbLogin(hnd->hostname, tmpport, NULL, NULL, hnd->dbname,
- hnd->username, hnd->password);
- if (!handle)
- {
- errormsg("Failed to initialise Postgres connection.");
- fclose(changefile);
+ }
+ /* connect to database */
+ sprintf (tmpport, "%d", hnd->port);
+ handle =
+ PQsetdbLogin (hnd->hostname, tmpport, NULL, NULL, hnd->dbname,
+ hnd->username, hnd->password);
+ if (!handle)
+ {
+ errormsg ("Failed to initialise Postgres connection.");
+ fclose (changefile);
return (NULL);
- }
- PQsetNoticeProcessor( handle , postgres_notice_processor , NULL );
+ }
+ PQsetNoticeProcessor (handle, postgres_notice_processor, NULL);
- /* update tables on server */
- tmp = changes->adds;
- fprintf(changefile, "These changes are being made automatically:\n\n");
- while (tmp)
- {
+ /* 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);
+ add_message (changefile, (DBchange *) tmp->data);
if (add->type == DBCH_ADD_TABLE)
- {
- /* for each new table, construct a CREATE command */
- buf = g_string_new("");
- name = oql_quote_column( add->name , NULL , OQL_DBTYPE_POSTGRESQL );
- g_string_sprintf(buf, "CREATE TABLE %s (", name);
- g_free( name );
- postgresql_add_column_data(buf, add->columns, ", ");
- g_string_append(buf, "PRIMARY KEY (ObjectID) )");
-
- /* execute CREATE query */
- g_strdown(buf->str);
- /* printf( "CREATE 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 */
- errormsg( "[%s] failed" , buf->str );
- errormsg(PQresultErrorMessage(res));
- }
+ {
+ /* for each new table, construct a CREATE command */
+ buf = g_string_new ("");
+ name = oql_quote_column (add->name, NULL, OQL_DBTYPE_POSTGRESQL);
+ g_string_sprintf (buf, "CREATE TABLE %s (", name);
+ g_free (name);
+ postgresql_add_column_data (buf, add->columns, ", ");
+ g_string_append (buf, "PRIMARY KEY (ObjectID) )");
+
+ /* execute CREATE query */
+ g_strdown (buf->str);
+ /* printf( "CREATE 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 */
+ errormsg ("[%s] failed", buf->str);
+ errormsg (PQresultErrorMessage (res));
+ }
+
-
- }
+ }
else if (add->type == DBCH_MODIFY_TABLE)
- {
+ {
- GList *tmplist;
- GList *l = add->columns;
- while( l )
- {
- buf = g_string_new("");
- name = oql_quote_column( add->name , NULL , OQL_DBTYPE_POSTGRESQL );
- g_string_sprintf(buf, "ALTER TABLE %s ADD ", name);
- g_free( name );
-
- /* tmplst hack because postgresql can only add one column at a time */
- /* and I want to reuse postgresql_add_column_data */
- tmplist = g_list_append( NULL , l->data );
- postgresql_add_column_data(buf, tmplist, "");
- g_list_free( tmplist );
-
-
- /* execute ALTER query */
- g_strdown(buf->str);
- /* printf( "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));
- }
- g_string_free( buf , TRUE );
-
- l = g_list_next( l );
- }
- }
- 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);
- }
+ GList *tmplist;
+ GList *l = add->columns;
+ while (l)
+ {
+ buf = g_string_new ("");
+ name =
+ oql_quote_column (add->name, NULL, OQL_DBTYPE_POSTGRESQL);
+ g_string_sprintf (buf, "ALTER TABLE %s ADD ", name);
+ g_free (name);
+
+ /* tmplst hack because postgresql can only add one column at a
time */
+ /* and I want to reuse postgresql_add_column_data */
+ tmplist = g_list_append (NULL, l->data);
+ postgresql_add_column_data (buf, tmplist, "");
+ g_list_free (tmplist);
+
+
+ /* execute ALTER query */
+ g_strdown (buf->str);
+ /* printf( "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));
+ }
+ g_string_free (buf, TRUE);
+
+ l = g_list_next (l);
+ }
+ }
+ tmp = g_list_next (tmp);
+ }
+ fprintf (changefile, "\n");
+
+ PQfinish (handle);
+ fclose (changefile);
+ /* message( "Done updating database" ); */
-/* initialise a connection to a specific postgresql 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)
- {
- int i;
- struct postgresql_handle *h =
- (struct postgresql_handle *)g_malloc(sizeof(struct
postgresql_handle));
+PostgreSQL_create_database_handle (configuration config, const char *dbname)
+{
+ int i;
+ struct postgresql_handle *h =
+ (struct postgresql_handle *) g_malloc (sizeof (struct postgresql_handle));
- if (h)
- {
+ if (h)
+ {
/* clear all <datatbasetype>_handle variables */
/* none here */
/* store general data */
if (!generic_database_config
- (config, dbname, (struct database_handle *)h))
- {
- postgresql_delete_database_handle((struct database_handle *)h);
- return (NULL);
- }
+ (config, dbname, (struct database_handle *) h))
+ {
+ postgresql_delete_database_handle ((struct database_handle *) h);
+ return (NULL);
+ }
/* read postgresql options from configuration file */
/* should be the only change required in this function */
@@ -895,31 +963,31 @@
/* create connection data storage */
h->base.connections =
- (struct active_connection *)g_new0(struct postgresql_connection,
- h->base.num_connections);
+ (struct active_connection *) g_new0 (struct postgresql_connection,
+ h->base.num_connections);
/* abort if resource acquisition failed */
if (!h->base.connections /* || !other data */ )
- {
- postgresql_delete_database_handle((struct database_handle *)h);
- return (NULL);
- }
+ {
+ postgresql_delete_database_handle ((struct database_handle *) h);
+ return (NULL);
+ }
/* initialise connections */
for (i = 0; i < h->base.num_connections; i++)
- {
- struct postgresql_connection *c
- =
- (struct postgresql_connection *)
- & ((struct postgresql_connection
*)h->base.connections)[i];
-
- /* set general state */
- c->base.available = TRUE;
- c->base.connected = FALSE;
-
- /* any postgresql specific data */
- c->handle = NULL; /* no connection yet */
- }
- }
- return (h);
- }
+ {
+ struct postgresql_connection *c
+ =
+ (struct postgresql_connection *)
+ &((struct postgresql_connection *) h->base.connections)[i];
+
+ /* set general state */
+ c->base.available = TRUE;
+ c->base.connected = FALSE;
+
+ /* any postgresql specific data */
+ c->handle = NULL; /* no connection yet */
+ }
+ }
+ return (h);
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- gnue/geas/src/objectstore mysql_access.h object...,
Reinhard Mueller <=