Make psql version aware; hide tablespace from older versions - Mailing list pgsql-patches

From Greg Sabino Mullane
Subject Make psql version aware; hide tablespace from older versions
Date
Msg-id 239c3671c8ae5708c9af33b65cc808fa@biglumber.com
Whole thread Raw
Responses Re: Make psql version aware; hide tablespace from older versions
List pgsql-patches
Index: describe.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/describe.c,v
retrieving revision 1.103
diff -c -r1.103 describe.c
*** describe.c    15 Jul 2004 03:56:06 -0000    1.103
--- describe.c    7 Aug 2004 22:15:03 -0000
***************
*** 112,117 ****
--- 112,123 ----
      PGresult   *res;
      printQueryOpt myopt = pset.popt;

+     if (pset.version < 700500000) {
+             fprintf(stderr, _("This server version (%d) does not support tablespaces.\n"),
+                             pset.version);
+             return true;
+     }
+
      initPQExpBuffer(&buf);

      printfPQExpBuffer(&buf,
***************
*** 706,713 ****
      /* Get general table info */
      printfPQExpBuffer(&buf,
       "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n"
!                     "relhasoids, reltablespace \n"
                        "FROM pg_catalog.pg_class WHERE oid = '%s'",
                        oid);
      res = PSQLexec(buf.data, false);
      if (!res)
--- 712,720 ----
      /* Get general table info */
      printfPQExpBuffer(&buf,
       "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules, \n"
!                     "relhasoids%s \n"
                        "FROM pg_catalog.pg_class WHERE oid = '%s'",
+                                         pset.version >= 700500000 ? ", reltablespace" : "",
                        oid);
      res = PSQLexec(buf.data, false);
      if (!res)
***************
*** 729,735 ****
      tableinfo.hasindex = strcmp(PQgetvalue(res, 0, 0), "t") == 0;
      tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 4), "t") == 0;
      tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
!     tableinfo.tablespace = atooid(PQgetvalue(res, 0, 6));
      PQclear(res);

      headers[0] = _("Column");
--- 736,743 ----
      tableinfo.hasindex = strcmp(PQgetvalue(res, 0, 0), "t") == 0;
      tableinfo.hasrules = strcmp(PQgetvalue(res, 0, 4), "t") == 0;
      tableinfo.hasoids = strcmp(PQgetvalue(res, 0, 5), "t") == 0;
!     tableinfo.tablespace = (pset.version >= 700500000) ?
!             atooid(PQgetvalue(res, 0, 6)) : 0;
      PQclear(res);

      headers[0] = _("Column");
Index: settings.h
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/settings.h,v
retrieving revision 1.18
diff -c -r1.18 settings.h
*** settings.h    12 May 2004 13:38:45 -0000    1.18
--- settings.h    7 Aug 2004 22:15:03 -0000
***************
*** 41,47 ****
      FILE       *cur_cmd_source; /* describe the status of the current main
                                   * loop */
      bool        cur_cmd_interactive;
!
      const char *progname;        /* in case you renamed psql */
      char       *inputfile;        /* for error reporting */
      unsigned    lineno;            /* also for error reporting */
--- 41,47 ----
      FILE       *cur_cmd_source; /* describe the status of the current main
                                   * loop */
      bool        cur_cmd_interactive;
!     int version;
      const char *progname;        /* in case you renamed psql */
      char       *inputfile;        /* for error reporting */
      unsigned    lineno;            /* also for error reporting */
Index: startup.c
===================================================================
RCS file: /projects/cvsroot/pgsql-server/src/bin/psql/startup.c,v
retrieving revision 1.95
diff -c -r1.95 startup.c
*** startup.c    3 Jun 2004 00:07:37 -0000    1.95
--- startup.c    7 Aug 2004 22:15:03 -0000
***************
*** 217,222 ****
--- 217,248 ----

      SyncVariables();

+     /* Grab the server version */
+     PGresult   *result;
+     result = PQexec(pset.db, "SELECT version()");
+     pset.version = 0;
+     if (result && PGRES_TUPLES_OK == PQresultStatus(result) && PQntuples(result)>=1)
+     {
+             const char *versionstring;
+             int x, y;
+             versionstring = PQgetvalue(result,0,0);
+             if (strlen(versionstring)>25) {
+                     versionstring+=11;
+                     for (y=1000000; y; y/=1000) {
+                             x = atoi(versionstring);
+                             if (x>0) {
+                                     if (x<10) { x*=(y*100); versionstring+=2; }
+                                     else if (x<100) { x*=(y*10); versionstring+=3; }
+                                     else if (x < 1000) { x*=y;  versionstring+=4; }
+                                     else { break; } /* should never get here */
+                                     pset.version += x;
+                             }
+                     }
+             }
+     }
+     result = NULL;
+     PQclear(result);
+
      if (options.action == ACT_LIST_DB)
      {
          int            success = listAllDbs(false);




pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: Patch for Array min() / max()
Next
From: "Serguei Mokhov"
Date:
Subject: Russian translation updates for 8.0