From 901b89e37bb8e71224ee76987679010ff3c93c05 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Tue, 26 Mar 2013 15:21:57 +0200 Subject: [PATCH] Get rid of obsolete parse_version helper function. For getting the server's version in numeric form, use PQserverVersion(). It does the exact same parsing as dumputils.c's parse_version(), and has been around in libpq for a long time. For the client's version, just use the PG_VERSION_NUM constant. --- src/bin/pg_dump/dumputils.c | 23 ----------------------- src/bin/pg_dump/dumputils.h | 1 - src/bin/pg_dump/pg_backup_db.c | 22 +++------------------- src/bin/pg_dump/pg_dump.c | 7 +------ src/bin/pg_dump/pg_dumpall.c | 12 +++--------- src/bin/psql/command.c | 2 +- 6 files changed, 8 insertions(+), 59 deletions(-) diff --git a/src/bin/pg_dump/dumputils.c b/src/bin/pg_dump/dumputils.c index 7322f1a825..31e56ef7fb 100644 --- a/src/bin/pg_dump/dumputils.c +++ b/src/bin/pg_dump/dumputils.c @@ -456,29 +456,6 @@ appendByteaLiteral(PQExpBuffer buf, const unsigned char *str, size_t length, } -/* - * Convert backend's version string into a number. - */ -int -parse_version(const char *versionString) -{ - int cnt; - int vmaj, - vmin, - vrev; - - cnt = sscanf(versionString, "%d.%d.%d", &vmaj, &vmin, &vrev); - - if (cnt < 2) - return -1; - - if (cnt == 2) - vrev = 0; - - return (100 * vmaj + vmin) * 100 + vrev; -} - - /* * Deconstruct the text representation of a 1-dimensional Postgres array * into individual items. diff --git a/src/bin/pg_dump/dumputils.h b/src/bin/pg_dump/dumputils.h index 6b82db2adb..5734c33617 100644 --- a/src/bin/pg_dump/dumputils.h +++ b/src/bin/pg_dump/dumputils.h @@ -60,7 +60,6 @@ extern void appendStringLiteralDQ(PQExpBuffer buf, const char *str, extern void appendByteaLiteral(PQExpBuffer buf, const unsigned char *str, size_t length, bool std_strings); -extern int parse_version(const char *versionString); extern bool parsePGArray(const char *atext, char ***itemarray, int *nitems); extern bool buildACLCommands(const char *name, const char *subname, const char *type, const char *acls, const char *owner, diff --git a/src/bin/pg_dump/pg_backup_db.c b/src/bin/pg_dump/pg_backup_db.c index 544d01a4dd..e16c193e3b 100644 --- a/src/bin/pg_dump/pg_backup_db.c +++ b/src/bin/pg_dump/pg_backup_db.c @@ -29,39 +29,23 @@ static void _check_database_version(ArchiveHandle *AH); static PGconn *_connectDB(ArchiveHandle *AH, const char *newdbname, const char *newUser); static void notice_processor(void *arg, const char *message); -static int -_parse_version(const char *versionString) -{ - int v; - - v = parse_version(versionString); - if (v < 0) - exit_horribly(modulename, "could not parse version string \"%s\"\n", versionString); - - return v; -} - static void _check_database_version(ArchiveHandle *AH) { - int myversion; const char *remoteversion_str; int remoteversion; - myversion = _parse_version(PG_VERSION); - remoteversion_str = PQparameterStatus(AH->connection, "server_version"); - if (!remoteversion_str) + remoteversion = PQserverVersion(AH->connection); + if (remoteversion == 0 || !remoteversion_str) exit_horribly(modulename, "could not get server_version from libpq\n"); - remoteversion = _parse_version(remoteversion_str); - AH->public.remoteVersionStr = pg_strdup(remoteversion_str); AH->public.remoteVersion = remoteversion; if (!AH->archiveRemoteVersion) AH->archiveRemoteVersion = AH->public.remoteVersionStr; - if (myversion != remoteversion + if (remoteversion != PG_VERSION_NUM && (remoteversion < AH->public.minRemoteVersion || remoteversion > AH->public.maxRemoteVersion)) { diff --git a/src/bin/pg_dump/pg_dump.c b/src/bin/pg_dump/pg_dump.c index b50e540622..771822dab5 100644 --- a/src/bin/pg_dump/pg_dump.c +++ b/src/bin/pg_dump/pg_dump.c @@ -295,7 +295,6 @@ main(int argc, char **argv) int outputNoOwner = 0; char *outputSuperuser = NULL; char *use_role = NULL; - int my_version; int optindex; RestoreOptions *ropt; ArchiveFormat archiveFormat = archUnknown; @@ -620,16 +619,12 @@ main(int argc, char **argv) /* Let the archiver know how noisy to be */ fout->verbose = g_verbose; - my_version = parse_version(PG_VERSION); - if (my_version < 0) - exit_horribly(NULL, "could not parse version string \"%s\"\n", PG_VERSION); - /* * We allow the server to be back to 7.0, and up to any minor release of * our own major version. (See also version check in pg_dumpall.c.) */ fout->minRemoteVersion = 70000; - fout->maxRemoteVersion = (my_version / 100) * 100 + 99; + fout->maxRemoteVersion = (PG_VERSION_NUM / 100) * 100 + 99; fout->numWorkers = numWorkers; diff --git a/src/bin/pg_dump/pg_dumpall.c b/src/bin/pg_dump/pg_dumpall.c index b26aa99f03..040cd94e5b 100644 --- a/src/bin/pg_dump/pg_dumpall.c +++ b/src/bin/pg_dump/pg_dumpall.c @@ -1873,21 +1873,15 @@ connectDatabase(const char *dbname, const char *connection_string, fprintf(stderr, _("%s: could not get server version\n"), progname); exit_nicely(1); } - server_version = parse_version(remoteversion_str); - if (server_version < 0) + server_version = PQserverVersion(conn); + if (server_version == 0) { fprintf(stderr, _("%s: could not parse server version \"%s\"\n"), progname, remoteversion_str); exit_nicely(1); } - my_version = parse_version(PG_VERSION); - if (my_version < 0) - { - fprintf(stderr, _("%s: could not parse version \"%s\"\n"), - progname, PG_VERSION); - exit_nicely(1); - } + my_version = PG_VERSION_NUM; /* * We allow the server to be back to 7.0, and up to any minor release of diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index c33f9446b2..33bc2a7e4c 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -1708,7 +1708,7 @@ connection_warnings(bool in_startup) { if (!pset.quiet && !pset.notty) { - int client_ver = parse_version(PG_VERSION); + int client_ver = PG_VERSION_NUM; if (pset.sversion != client_ver) {