commit-gnue
[Top][All Lists]
Advanced

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

gnue/geas/src/objectstore postgresql_access.h


From: James Thompson
Subject: gnue/geas/src/objectstore postgresql_access.h
Date: Mon, 19 Feb 2001 12:12:02 -0800

CVSROOT:        /cvs
Module name:    gnue
Changes by:     James Thompson <address@hidden> 01/02/19 12:12:02

Modified files:
        geas/src/objectstore: postgresql_access.h 

Log message:
        New code for getting field types from a postgresql database

CVSWeb URLs:
http://subversions.gnu.org/cgi-bin/cvsweb/gnue/geas/src/objectstore/postgresql_access.h.diff?r1=1.6&r2=1.7

Patches:
Index: gnue/geas/src/objectstore/postgresql_access.h
diff -u gnue/geas/src/objectstore/postgresql_access.h:1.6 
gnue/geas/src/objectstore/postgresql_access.h:1.7
--- gnue/geas/src/objectstore/postgresql_access.h:1.6   Sun Feb 18 19:22:02 2001
+++ gnue/geas/src/objectstore/postgresql_access.h       Mon Feb 19 12:12:01 2001
@@ -446,41 +446,37 @@
       int err;
 
       /* get list of fields and types */
-      buf = g_strdup_printf("SHOW COLUMNS FROM %s", tab->name);
+      buf = g_strdup_printf("select a.attname, t.typname"
+                           "from pg_class c, pg_attribute a, pg_type t"
+                           "where c.relname = 'school' and"
+                           "a.attnum > 0 and"
+                           "a.attrelid = c.oid and"
+                           "a.atttypid = t.oid", tab->name);
       res = PQexec(handle, buf);
       g_free(buf);
-      if (!res)
+      if (PQresultStatus(res) != PGRES_TUPLES_OK)
          {
          errormsg
          ("Failed to get postgresql table %s definition from database %s.",
           tab->name, hnd->name);
-         mysql_close(handle);
+         PQclear(res);
          free_database_definition(db);
          return (NULL);
          }
-      if(PQnfields(res)<=0)
+      if(PQntuples(res)<=0)
          message("Warning: no fields in table %s in database %s",
                  tab->name, hnd->name);
-      for(j=0;j<PQnfields(res);j++)
-       {
-       Oid pgtype;
-       /* hmm does this work */
-       pgtype = PQftype(res,j);
-         /* information only, type is ignored */
-         /* ie: accuracy is not critical */
-         /* except when display will be too confusing */
-/*         if (g_strcasecmp(row[1], "char") == 0)
+
+      for (row = 0; row <  PQntuples(res); row++)
+       {
+         if (g_strcasecmp(PQgetvalue(res,row,1),"char") == 0)
             type = DT_char;
-         else if (g_strcasecmp(row[1], "int") == 0)
+         else if (g_strcasecmp(PQgetvalue(res,row,1), "int") == 0)
             type = DT_int;
-         else
+         else
             type = DT_unknown;
-*/
-                       /* TODO: work out type of field.
-                       
-                       */
-                       add_database_column(tab,PQfname(res,j),pgtype); 
-                       }
+         add_database_column(tab,PQgetvalue(res,row,0),type); 
+       }
       PQclear(res);
       }
    /* close the database */



reply via email to

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