Version checking when loading psql - Mailing list pgsql-patches

From Greg Sabino Mullane
Subject Version checking when loading psql
Date
Msg-id E165tSR-0008TG-00@mclean.mail.mindspring.net
Whole thread Raw
Responses Re: Version checking when loading psql  (Peter Eisentraut <peter_e@gmx.net>)
List pgsql-patches
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Attached is a little patch that simply verifies that the
version of psql you are running is the same as the version
of postgresql you are attaching to. Handy for those times
when you have multiple versions running on different ports,
then put in the wrong port number and post something to
the hackers list wondering why function x is not working.... :)

It spits out a little warning message if the versions are
different, but other than that lets you continue to shoot
yourself in the foot.

Greg Sabino Mullane
greg@turnstep.com
PGP Key: 0x14964AC8 20011191319

-----BEGIN PGP SIGNATURE-----
Comment: http://www.turnstep.com/pgp.html

iQA/AwUBO/lNKbybkGcUlkrIEQJDegCeLr3mEJp82GoTzcOAgLgN3+x+6i0An2mE
HBN+xFOJx/M5bV+bzgXXpwF2
=aaM4
-----END PGP SIGNATURE-----


*** ./src/bin/psql/startup.c.orig    Mon Nov 19 13:06:15 2001
--- ./src/bin/psql/startup.c    Mon Nov 19 13:06:24 2001
***************
*** 293,298 ****
--- 293,315 ----
  #endif
          }

+
+ /* Warn if connecting to a different version */
+         PGresult   *result;
+
+         /* Temporarily turn off echoing */
+         if (GetVariable(pset.vars, "ECHO_HIDDEN"))
+             DeleteVariable(pset.vars, "ECHO_HIDDEN");
+         result = PSQLexec("SELECT version()");
+         SetVariableBool(pset.vars, "ECHO_HIDDEN");
+         if (result) {
+             char serverversion[12];
+             sscanf(PQgetvalue(result,0,0), "PostgreSQL %s", serverversion);
+             PQclear(result);
+             if (strcmp(PG_VERSION, serverversion))
+                 printf("WARNING! psql version %s does not match server version %s!\n\n", PG_VERSION, serverversion);
+         }
+
          SetVariable(pset.vars, "PROMPT1", DEFAULT_PROMPT1);
          SetVariable(pset.vars, "PROMPT2", DEFAULT_PROMPT2);
          SetVariable(pset.vars, "PROMPT3", DEFAULT_PROMPT3);

pgsql-patches by date:

Previous
From: greg@turnstep.com
Date:
Subject: Improved index support for \d and \di in psql
Next
From: Bruce Momjian
Date:
Subject: Re: Improved index support for \d and \di in psql