Use libpq's new logic to get the server version, instead of doing it ourselves.
authorTom Lane <tgl@sss.pgh.pa.us>
Sun, 22 Jun 2003 00:56:58 +0000 (00:56 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Sun, 22 Jun 2003 00:56:58 +0000 (00:56 +0000)
src/bin/pg_dump/pg_backup_db.c
src/bin/pg_dump/pg_dumpall.c

index a1545938633e99706ac0440a03bc225a21455963..7c6f5c412885589893b89ebf7900820bba0b0b6b 100644 (file)
@@ -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 = PQgetvalue(res, 0, 0);
-   remoteversion = _parse_version(AH, remoteversion_str + 11);
+   remoteversion_str = PQparameterStatus(AH->connection, "server_version");
+   if (!remoteversion_str)
+       die_horribly(AH, modulename, "could not get server_version from libpq\n");
 
-   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);
index a7b93155ded52db95f15562c1dfa54e8f5bc83e7..ad368a56aeda8fba6028cde115f3de43ee6f2d11 100644 (file)
@@ -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
+   server_version = parse_version(remoteversion_str);
+   if (server_version < 0)
    {
-       char *val = PQgetvalue(res, 0, 0);
-       server_version = parse_version(val + strcspn(val, "0123456789"));
-       if (server_version < 0)
-       {
-           fprintf(stderr, _("%s: could not parse server version \"%s\"\n"), progname, val);
-           exit(1);
-       }
+       fprintf(stderr, _("%s: could not parse server version \"%s\"\n"),
+               progname, remoteversion_str);
+       exit(1);
    }
-   PQclear(res);
 
    return conn;
 }