Use libpq's new logic to get the server version, instead of doing it ourselves.
This commit is contained in:
parent
e92dc1e199
commit
dd81eee222
@ -5,7 +5,7 @@
|
||||
* Implements the basic DB functions used by the archiver.
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.47 2003/05/14 03:26:02 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.48 2003/06/22 00:56:58 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -53,29 +53,23 @@ _parse_version(ArchiveHandle *AH, const char *versionString)
|
||||
static void
|
||||
_check_database_version(ArchiveHandle *AH, bool ignoreVersion)
|
||||
{
|
||||
PGresult *res;
|
||||
int myversion;
|
||||
const char *remoteversion_str;
|
||||
int remoteversion;
|
||||
PGconn *conn = AH->connection;
|
||||
|
||||
myversion = _parse_version(AH, PG_VERSION);
|
||||
|
||||
res = PQexec(conn, "SELECT version();");
|
||||
if (!res ||
|
||||
PQresultStatus(res) != PGRES_TUPLES_OK ||
|
||||
PQntuples(res) != 1)
|
||||
die_horribly(AH, modulename, "could not get version from server: %s", PQerrorMessage(conn));
|
||||
remoteversion_str = PQparameterStatus(AH->connection, "server_version");
|
||||
if (!remoteversion_str)
|
||||
die_horribly(AH, modulename, "could not get server_version from libpq\n");
|
||||
|
||||
remoteversion_str = PQgetvalue(res, 0, 0);
|
||||
remoteversion = _parse_version(AH, remoteversion_str + 11);
|
||||
|
||||
PQclear(res);
|
||||
remoteversion = _parse_version(AH, remoteversion_str);
|
||||
|
||||
AH->public.remoteVersion = remoteversion;
|
||||
|
||||
if (myversion != remoteversion
|
||||
&& (remoteversion < AH->public.minRemoteVersion || remoteversion > AH->public.maxRemoteVersion))
|
||||
&& (remoteversion < AH->public.minRemoteVersion ||
|
||||
remoteversion > AH->public.maxRemoteVersion))
|
||||
{
|
||||
write_msg(NULL, "server version: %s; %s version: %s\n",
|
||||
remoteversion_str, progname, PG_VERSION);
|
||||
|
@ -6,7 +6,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.21 2003/06/11 05:13:11 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.22 2003/06/22 00:56:58 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -701,7 +701,7 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
|
||||
PGconn *conn;
|
||||
char *password = NULL;
|
||||
bool need_pass = false;
|
||||
PGresult *res;
|
||||
const char *remoteversion_str;
|
||||
|
||||
if (require_password)
|
||||
password = simple_prompt("Password: ", 100, false);
|
||||
@ -745,23 +745,19 @@ connectDatabase(const char *dbname, const char *pghost, const char *pgport,
|
||||
exit(1);
|
||||
}
|
||||
|
||||
res = executeQuery(conn, "SELECT version();");
|
||||
if (PQntuples(res) != 1)
|
||||
remoteversion_str = PQparameterStatus(conn, "server_version");
|
||||
if (!remoteversion_str)
|
||||
{
|
||||
fprintf(stderr, _("%s: could not get server version\n"), progname);
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
{
|
||||
char *val = PQgetvalue(res, 0, 0);
|
||||
server_version = parse_version(val + strcspn(val, "0123456789"));
|
||||
server_version = parse_version(remoteversion_str);
|
||||
if (server_version < 0)
|
||||
{
|
||||
fprintf(stderr, _("%s: could not parse server version \"%s\"\n"), progname, val);
|
||||
fprintf(stderr, _("%s: could not parse server version \"%s\"\n"),
|
||||
progname, remoteversion_str);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
PQclear(res);
|
||||
|
||||
return conn;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user