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.
This commit is contained in:
Heikki Linnakangas 2013-03-26 15:21:57 +02:00
parent ec143f9405
commit 901b89e37b
6 changed files with 8 additions and 59 deletions

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

View 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,

View 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))
{

View 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;

View 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

View 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)
{