]> granicus.if.org Git - postgresql/commitdiff
Get rid of obsolete parse_version helper function.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 26 Mar 2013 13:21:57 +0000 (15:21 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 26 Mar 2013 13:32:02 +0000 (15:32 +0200)
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
src/bin/pg_dump/dumputils.h
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_dump.c
src/bin/pg_dump/pg_dumpall.c
src/bin/psql/command.c

index 7322f1a8257d8f0abb1325724167945f4516fd35..31e56ef7fb524b266e668fda2efbf6b1a8ed0c5c 100644 (file)
@@ -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.
index 6b82db2adb70dce903e7b1deb4e8079071305feb..5734c336178d65f5030ff5a0a8bbbc143aacc92e 100644 (file)
@@ -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,
index 544d01a4ddc69b1678304e21ca1a6ff22d94647b..e16c193e3bedfe405137c53be663aae2aa3068e5 100644 (file)
@@ -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))
        {
index b50e54062283da863785b439e9da3e5bd890b114..771822dab5d4412a8de4eb0bd4406fcbcc162bb1 100644 (file)
@@ -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;
 
index b26aa99f03f1028b6679e36fc96db29587a357c9..040cd94e5b5a743e859f8c9b68eb69dd17bff96a 100644 (file)
@@ -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
index c33f9446b206ea1f6eeb68c63e7be2a2a5414432..33bc2a7e4c54ee0e282f2e770556b7fba2beed1f 100644 (file)
@@ -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)
                {