commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnue/objectserver README server/gedi-implementa...


From: James Thompson
Subject: gnue/objectserver README server/gedi-implementa...
Date: Thu, 21 Sep 2000 21:45:21 -0700

CVSROOT:        /cvs
Module name:    gnue
Changes by:     James Thompson <address@hidden> 00/09/21 21:45:21

Modified files:
        objectserver   : README 
        objectserver/server: gedi-implementation.c gedi-implementation.h 
                             gedi.conf impl-support.c unique.dat 
Added files:
        objectserver/cld_parser: pout.sql 

Log message:
        Added the start of postgresql support to the code
        This code compiles but doesn't as of yet work
        Added info to README to explain how to setup postgres demo
        Added static pout.sql since maketables doesn't produce postgres sql

CVSWeb URLs:
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/objectserver/README.diff?r1=1.3&r2=1.4
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/objectserver/cld_parser/pout.sql.diff?r1=NONE&r2=1.1
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/objectserver/server/gedi-implementation.c.diff?r1=1.3&r2=1.4
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/objectserver/server/gedi-implementation.h.diff?r1=1.3&r2=1.4
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/objectserver/server/gedi.conf.diff?r1=1.2&r2=1.3
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/objectserver/server/impl-support.c.diff?r1=1.3&r2=1.4
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/objectserver/server/unique.dat.diff?r1=1.2&r2=1.3

Patches:
Index: gnue/objectserver/README
diff -u gnue/objectserver/README:1.3 gnue/objectserver/README:1.4
--- gnue/objectserver/README:1.3        Thu Sep 21 19:05:00 2000
+++ gnue/objectserver/README    Thu Sep 21 21:45:20 2000
@@ -6,16 +6,30 @@
   dmalloc (http://dmalloc.com/)
   
    
-to run a demo of this code.....
+to run a MySQL demo of this code.....
 
-Configure MySQL Once
-  In the cld_parser directory
-  ./maketables -f out.sql test.cld
-  mysql -t test < out.sql
-
-Run code
-  In the server directory
-   ./gedi-server
+  Setup Tables in MySql
+    In the cld_parser directory
+    ./maketables -f out.sql test.cld
+    mysql -t test < out.sql
 
-  In the demo/python_client directory (in a different window)
-   ./client.py
+  Run code
+    In the server directory
+     ./gedi-server
+
+    In the demo/python_client directory (in a different window)
+     ./client.py
+
+to run a postgresql demo of this code.....
+   Setup Tables in pgsql
+     (maketables does not yet support pgsql use the static 
+      file for now)
+     psql -f pout.sql -u -h gnue gnue
+
+  Run code
+    In the server directory
+     ./gedi-server
+
+    In the demo/python_client directory (in a different window)
+     ./client.py
+
Index: gnue/objectserver/server/gedi-implementation.c
diff -u gnue/objectserver/server/gedi-implementation.c:1.3 
gnue/objectserver/server/gedi-implementation.c:1.4
--- gnue/objectserver/server/gedi-implementation.c:1.3  Thu Sep 21 17:08:14 2000
+++ gnue/objectserver/server/gedi-implementation.c      Thu Sep 21 21:45:20 2000
@@ -909,6 +909,10 @@
    {
    CORBA_boolean retval = CORBA_FALSE;
 
+#ifdef USE_POSTGRESQL
+  gchar *connect_string = NULL;
+#endif
+
    if (servant->connection.isConnected)
       {
       make_AlreadyConnected_exception(ev,
@@ -916,8 +920,8 @@
       return (CORBA_FALSE);
       }
 
-#ifdef USE_MYSQL
    printf("allocating handle\n");
+#ifdef USE_MYSQL
    servant->connection.handle = mysql_init(NULL);
    if (servant->connection.handle == NULL)
       {
@@ -947,6 +951,30 @@
       return (CORBA_FALSE);
       }
 #else ifdef USE_POSTGRESQL
+   if  (get_database_prop(servant->attr_name, "username", NULL)) {
+     connect_string = g_strconcat(" user=",
+       get_database_prop(servant->attr_name, "username", NULL), NULL);
+   }
+   if (get_database_prop(servant->attr_name, "password", NULL)) {
+     connect_string = g_strconcat(connect_string," password=",
+       get_database_prop(servant->attr_name, "password", NULL), NULL);
+   }
+   if (get_database_prop(servant->attr_name, "dbname", NULL)) {
+     connect_string = g_strconcat(connect_string," dbname=",
+       get_database_prop(servant->attr_name, "dbname", NULL), NULL);
+   }
+   if (get_database_prop(servant->attr_name, "hostname", NULL)) {
+     connect_string = g_strconcat(connect_string," host=",
+       get_database_prop(servant->attr_name, "hostname", NULL), NULL);
+   }
+
+   
+   servant->connection.handle = PQconnectdb(connect_string);
+   if (PQstatus(servant->connection.handle) == CONNECTION_OK)
+     {
+      make_ServerError_exception(ev, "Database connection failed");
+      return (CORBA_FALSE);
+     }
 #endif
    printf("connected...\n");
 
@@ -965,9 +993,10 @@
       make_ServerError_exception(ev, "Failed to read class definitions");
 #ifdef USE_MYSQL
       mysql_close(servant->connection.handle);
-      servant->connection.handle = NULL;
 #else ifdef USE_POSTGRESQL
+      PQfinish(servant->connection.handle);
 #endif
+      servant->connection.handle = NULL;
       return (CORBA_FALSE);
       }
 
@@ -997,9 +1026,10 @@
    /* TEMPORARY */
 #ifdef USE_MYSQL
    mysql_close(servant->connection.handle);
-   servant->connection.handle = NULL;
 #else ifdef USE_POSTGRESQL
+   PQfinish(servant->connection.handle);
 #endif
+   servant->connection.handle = NULL;
    /* TEMPORARY */
 
    free_class_defs(servant->connection.classdefs);
Index: gnue/objectserver/server/gedi-implementation.h
diff -u gnue/objectserver/server/gedi-implementation.h:1.3 
gnue/objectserver/server/gedi-implementation.h:1.4
--- gnue/objectserver/server/gedi-implementation.h:1.3  Thu Sep 21 17:21:07 2000
+++ gnue/objectserver/server/gedi-implementation.h      Thu Sep 21 21:45:20 2000
@@ -13,6 +13,7 @@
 #ifdef USE_MYSQL
 #include <mysql.h>
 #else ifdef USE_POSTGRESQL
+#include "libpq-fe.h"
 #endif
 
 /*
@@ -51,7 +52,7 @@
 #ifdef USE_MYSQL
    MYSQL *handle;
 #else ifdef USE_POSTGRESQL
-   int handle;
+   PGconn *handle;
 #endif
    }
 database_connection;
Index: gnue/objectserver/server/gedi.conf
diff -u gnue/objectserver/server/gedi.conf:1.2 
gnue/objectserver/server/gedi.conf:1.3
--- gnue/objectserver/server/gedi.conf:1.2      Thu Sep 21 17:08:14 2000
+++ gnue/objectserver/server/gedi.conf  Thu Sep 21 21:45:20 2000
@@ -25,8 +25,21 @@
 provider    gda-not-done-yet
 dsn         needs-gda-to-be-useful
 classdir    ./test-classdir
-#hostname    101.101.101.1
-username    andrewm
+#hostname    gedi
+username    gedi
 unixsocket  /var/run/mysqld/mysqld.sock
-#password   "none used"
+#password   demo
 dbname      test
+
+# pgsql version 
+#database gedi
+#description "A little test database"
+#provider    gda-not-done-yet
+#dsn         needs-gda-to-be-useful
+#classdir    ./test-classdir
+#hostname    gedi
+#username    gedi
+#unixsocket  /var/run/mysqld/mysqld.sock
+#password   demo
+#dbname      test
+
Index: gnue/objectserver/server/impl-support.c
diff -u gnue/objectserver/server/impl-support.c:1.3 
gnue/objectserver/server/impl-support.c:1.4
--- gnue/objectserver/server/impl-support.c:1.3 Thu Sep 21 17:21:07 2000
+++ gnue/objectserver/server/impl-support.c     Thu Sep 21 21:45:20 2000
@@ -11,6 +11,11 @@
 #include <dmalloc.h>
 #endif
 
+#ifdef USE_POSTGRESQL
+#include "libpq-fe.h"
+#endif
+
+
 database_connection *
 get_database_connection(impl_POA_GEDI_DataObject * servant)
    {
@@ -162,6 +167,75 @@
    /* return list of classname/ID pairs */
    free(query);
 #else ifdef USE_POSTGRESQL
+   char *classname = query->classptr->classname;
+   PGresult *result;
+   gint current_record;
+   gint records_found;
+
+   result = PQexec(connection->handle, query->string->str);
+   if (PQresultStatus(result) != PGRES_TUPLES_OK)
+     {
+       make_ServerError_exception(ev, "query failed: %s",   
+                                 PQerrorMessage(connection->handle));
+       PQclear(result);
+       free(query);
+       return (CORBA_OBJECT_NIL);
+     }
+
+   records_found = PQntuples(result);
+   for (current_record = 0; current_record <  records_found; current_record++)
+    {
+      int count;
+      GList *l;
+      GEDI_ReferenceID ID = strtoul(PQgetvalue(result,current_record,0),
+                                   NULL, 0);
+      ObjectData obj;
+
+
+      // printf("adding object: %s[%ld]\n", classname, ID);
+      add_object(connection->objectlist, classname, ID);
+      obj = find_object(connection->objectlist, classname, ID);
+      rlist = g_list_append(rlist, alloc_classid(classname, ID));
+      // printf("%d entries\n", count_entries(connection->objectlist));
+      l = find_class(connection->classdefs, classname)->basic_fields;
+
+      /* record basic fields */
+      count = 1;
+      while (l)
+       {
+         set_object_field(connection->objectlist, obj,
+                          ((basic_field *) l->data)->fieldname,
+                          PQgetvalue(result,current_record,count++));
+         /* printf("set: [%s/%ld] %s = %s\n", classname, ID, *
+            ((basic_field *) l->data)->fieldname, 
PQgetvalue(result,current_record,count - 1); */
+         l = l->next;
+        }
+
+      /* lookup fields */
+      l = find_class(connection->classdefs, classname)->lookup_fields;
+      while (l)
+       {
+         if (((lookup_field *) l->data)->type == LF_LOOKUP)
+          {
+            set_object_field(connection->objectlist, obj,
+                             ((basic_field *) l->data)->fieldname,
+                             PQgetvalue(result,current_record,count++));
+
+            // printf("set: [%s/%ld] %s = %s\n", classname, ID,
+            // ((basic_field *) l->data)->fieldname, 
+           //      PQgetvalue(result,current_record,count - 1);
+          }
+         l = l->next;
+        }
+
+      /* note that the object has been stored in the database */
+      object_saved(connection->objectlist, obj);
+    }
+
+   PQclear(result);
+   free(query);
+
+   /*jst */
 #endif
    return (rlist);
    }
@@ -290,7 +364,9 @@
 #ifdef USE_MYSQL
    int err;
 #endif
-
+#ifdef USE_POSTGRESQL
+   PGresult *err;
+#endif
    if (obj == NULL)
       {
       printf("error: NULL object being written : %s\n", __PRETTY_FUNCTION__);
@@ -312,6 +388,13 @@
             return (FALSE);
             }      
 #else ifdef USE_POSTGRESQL
+        err = PQexec(con->handle, query->string->str);
+        if (PQresultStatus(err) !=  PGRES_COMMAND_OK )
+          {
+            printf("write failed: %s\n", PQerrorMessage(con->handle));
+            PQclear(err);
+            return (FALSE);
+          }
 #endif
          }
       free_query(query);
@@ -336,6 +419,13 @@
          return (FALSE);
          }
 #else ifdef USE_POSTGRESQL
+       err = PQexec(con->handle, query->string->str);
+       if (PQresultStatus(err) != PGRES_TUPLES_OK)
+        {
+          printf("write failed: %s\n", PQerrorMessage(con->handle));
+          PQclear(err);
+          return (FALSE);
+        }
 #endif
       free_query(query);
       }
Index: gnue/objectserver/server/unique.dat
diff -u gnue/objectserver/server/unique.dat:1.2 
gnue/objectserver/server/unique.dat:1.3
--- gnue/objectserver/server/unique.dat:1.2     Thu Sep 21 19:05:00 2000
+++ gnue/objectserver/server/unique.dat Thu Sep 21 21:45:20 2000
@@ -1 +1 @@
-33
\ No newline at end of file
+38
\ No newline at end of file


reply via email to

[Prev in Thread] Current Thread [Next in Thread]