Version checking when loading psql

Поиск
Список
Период
Сортировка
Искать

Version checking when loading psql

От:
"Greg Sabino Mullane" <greg@turnstep.com>
Дата:
-----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);

Re: Version checking when loading psql

От:
"Greg Sabino Mullane" <greg@turnstep.com>
Дата:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Sorry, sent the wrong version previously. This is the proper 
patch, and remembers the echo setting.


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

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

iQA/AwUBO/pqrLybkGcUlkrIEQI8mQCZAYkehIYbaD6A0Zphpg9/2GOiFJwAn1XY
PNlVXOIO7/B85kwZFi322zAh
=cdxw
-----END PGP SIGNATURE-----
*** ./src/bin/psql/startup.c.orig	Mon Nov 19 13:06:15 2001
--- ./src/bin/psql/startup.c	Tue Nov 20 09:08:44 2001
***************
*** 293,298 ****
--- 293,319 ----
  #endif
  		}
  
+ 	
+ /* Warn if connecting to a different version */
+ 		PGresult   *result;
+ 		bool echo=false;
+ 
+ 		/* Temporarily turn off echoing */
+ 		if (GetVariable(pset.vars, "ECHO_HIDDEN")) {
+ 			DeleteVariable(pset.vars, "ECHO_HIDDEN");
+ 			echo = true;
+ 		}
+ 		result = PSQLexec("SELECT version()");
+ 		if (echo)
+ 			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);

Re: Version checking when loading psql

От:
Peter Eisentraut <peter_e@gmx.net>
Дата:
Greg Sabino Mullane writes:

> 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.

I'm sure this would annoy people.

-- 
Peter Eisentraut   peter_e@gmx.net

Re: Version checking when loading psql

От:
"Colin 't Hart" <cthart@yahoo.com>
Дата:
Why not do like the DBMS that we (partially) emulate :-)
and show the versions of the psql app and the server to
which you are connected?

Does psql have a verbose mode where this could be switched
on?

Cheers,

Colin


FAQ