Skip to content

Commit 901b89e

Browse files
committed
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.
1 parent ec143f9 commit 901b89e

File tree

6 files changed

+8
-59
lines changed

6 files changed

+8
-59
lines changed

src/bin/pg_dump/dumputils.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -456,29 +456,6 @@ appendByteaLiteral(PQExpBuffer buf, const unsigned char *str, size_t length,
456456
}
457457

458458

459-
/*
460-
* Convert backend's version string into a number.
461-
*/
462-
int
463-
parse_version(const char *versionString)
464-
{
465-
int cnt;
466-
int vmaj,
467-
vmin,
468-
vrev;
469-
470-
cnt = sscanf(versionString, "%d.%d.%d", &vmaj, &vmin, &vrev);
471-
472-
if (cnt < 2)
473-
return -1;
474-
475-
if (cnt == 2)
476-
vrev = 0;
477-
478-
return (100 * vmaj + vmin) * 100 + vrev;
479-
}
480-
481-
482459
/*
483460
* Deconstruct the text representation of a 1-dimensional Postgres array
484461
* into individual items.

src/bin/pg_dump/dumputils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ extern void appendStringLiteralDQ(PQExpBuffer buf, const char *str,
6060
extern void appendByteaLiteral(PQExpBuffer buf,
6161
const unsigned char *str, size_t length,
6262
bool std_strings);
63-
extern int parse_version(const char *versionString);
6463
extern bool parsePGArray(const char *atext, char ***itemarray, int *nitems);
6564
extern bool buildACLCommands(const char *name, const char *subname,
6665
const char *type, const char *acls, const char *owner,

src/bin/pg_dump/pg_backup_db.c

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,23 @@ static void _check_database_version(ArchiveHandle *AH);
2929
static PGconn *_connectDB(ArchiveHandle *AH, const char *newdbname, const char *newUser);
3030
static void notice_processor(void *arg, const char *message);
3131

32-
static int
33-
_parse_version(const char *versionString)
34-
{
35-
int v;
36-
37-
v = parse_version(versionString);
38-
if (v < 0)
39-
exit_horribly(modulename, "could not parse version string \"%s\"\n", versionString);
40-
41-
return v;
42-
}
43-
4432
static void
4533
_check_database_version(ArchiveHandle *AH)
4634
{
47-
int myversion;
4835
const char *remoteversion_str;
4936
int remoteversion;
5037

51-
myversion = _parse_version(PG_VERSION);
52-
5338
remoteversion_str = PQparameterStatus(AH->connection, "server_version");
54-
if (!remoteversion_str)
39+
remoteversion = PQserverVersion(AH->connection);
40+
if (remoteversion == 0 || !remoteversion_str)
5541
exit_horribly(modulename, "could not get server_version from libpq\n");
5642

57-
remoteversion = _parse_version(remoteversion_str);
58-
5943
AH->public.remoteVersionStr = pg_strdup(remoteversion_str);
6044
AH->public.remoteVersion = remoteversion;
6145
if (!AH->archiveRemoteVersion)
6246
AH->archiveRemoteVersion = AH->public.remoteVersionStr;
6347

64-
if (myversion != remoteversion
48+
if (remoteversion != PG_VERSION_NUM
6549
&& (remoteversion < AH->public.minRemoteVersion ||
6650
remoteversion > AH->public.maxRemoteVersion))
6751
{

src/bin/pg_dump/pg_dump.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,6 @@ main(int argc, char **argv)
295295
int outputNoOwner = 0;
296296
char *outputSuperuser = NULL;
297297
char *use_role = NULL;
298-
int my_version;
299298
int optindex;
300299
RestoreOptions *ropt;
301300
ArchiveFormat archiveFormat = archUnknown;
@@ -620,16 +619,12 @@ main(int argc, char **argv)
620619
/* Let the archiver know how noisy to be */
621620
fout->verbose = g_verbose;
622621

623-
my_version = parse_version(PG_VERSION);
624-
if (my_version < 0)
625-
exit_horribly(NULL, "could not parse version string \"%s\"\n", PG_VERSION);
626-
627622
/*
628623
* We allow the server to be back to 7.0, and up to any minor release of
629624
* our own major version. (See also version check in pg_dumpall.c.)
630625
*/
631626
fout->minRemoteVersion = 70000;
632-
fout->maxRemoteVersion = (my_version / 100) * 100 + 99;
627+
fout->maxRemoteVersion = (PG_VERSION_NUM / 100) * 100 + 99;
633628

634629
fout->numWorkers = numWorkers;
635630

src/bin/pg_dump/pg_dumpall.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,21 +1873,15 @@ connectDatabase(const char *dbname, const char *connection_string,
18731873
fprintf(stderr, _("%s: could not get server version\n"), progname);
18741874
exit_nicely(1);
18751875
}
1876-
server_version = parse_version(remoteversion_str);
1877-
if (server_version < 0)
1876+
server_version = PQserverVersion(conn);
1877+
if (server_version == 0)
18781878
{
18791879
fprintf(stderr, _("%s: could not parse server version \"%s\"\n"),
18801880
progname, remoteversion_str);
18811881
exit_nicely(1);
18821882
}
18831883

1884-
my_version = parse_version(PG_VERSION);
1885-
if (my_version < 0)
1886-
{
1887-
fprintf(stderr, _("%s: could not parse version \"%s\"\n"),
1888-
progname, PG_VERSION);
1889-
exit_nicely(1);
1890-
}
1884+
my_version = PG_VERSION_NUM;
18911885

18921886
/*
18931887
* We allow the server to be back to 7.0, and up to any minor release of

src/bin/psql/command.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1708,7 +1708,7 @@ connection_warnings(bool in_startup)
17081708
{
17091709
if (!pset.quiet && !pset.notty)
17101710
{
1711-
int client_ver = parse_version(PG_VERSION);
1711+
int client_ver = PG_VERSION_NUM;
17121712

17131713
if (pset.sversion != client_ver)
17141714
{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy