]> granicus.if.org Git - postgresql/blobdiff - src/bin/pg_dump/pg_dumpall.c
Add full path in error report for version mismatch of binaries.
[postgresql] / src / bin / pg_dump / pg_dumpall.c
index f05623186d28e5faf819cda139dd6e807bc5a09f..1b26ebb4dc938070c36040972a194ee821ae9a29 100644 (file)
@@ -2,11 +2,11 @@
  *
  * pg_dumpall
  *
- * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2004, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.48 2004/08/08 06:58:00 momjian Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dumpall.c,v 1.53 2004/10/15 04:32:28 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -59,7 +59,7 @@ static PGconn *connectDatabase(const char *dbname, const char *pghost, const cha
                                const char *pguser, bool require_password);
 static PGresult *executeQuery(PGconn *conn, const char *query);
 
-char       pg_dump_bin[MAXPGPATH];
+char           pg_dump_bin[MAXPGPATH];
 PQExpBuffer pgdumpopts;
 bool           output_clean = false;
 bool           skip_acls = false;
@@ -67,9 +67,9 @@ bool          verbose = false;
 int                    server_version;
 
 /* flags for -X long options */
-int    disable_dollar_quoting = 0;
-int    disable_triggers = 0;
-int    use_setsessauth = 0;
+int                    disable_dollar_quoting = 0;
+int                    disable_triggers = 0;
+int                    use_setsessauth = 0;
 
 int
 main(int argc, char *argv[])
@@ -82,7 +82,8 @@ main(int argc, char *argv[])
        bool            globals_only = false;
        bool            schema_only = false;
        PGconn     *conn;
-       int                     c, ret;
+       int                     c,
+                               ret;
 
        static struct option long_options[] = {
                {"data-only", no_argument, NULL, 'a'},
@@ -138,18 +139,24 @@ main(int argc, char *argv[])
        if ((ret = find_other_exec(argv[0], "pg_dump", PG_VERSIONSTR,
                                                           pg_dump_bin)) < 0)
        {
+               char full_path[MAXPGPATH];
+
+               if (find_my_exec(argv[0], full_path) < 0)
+                       StrNCpy(full_path, progname, MAXPGPATH);
+
                if (ret == -1)
                        fprintf(stderr,
-                                               _("The program \"pg_dump\" is needed by %s "
-                                               "but was not found in the same directory as \"%s\".\n"
-                                               "Check your installation.\n"),
-                                               progname, progname);
+                                       _("The program \"pg_dump\" is needed by %s "
+                                         "but was not found in the\n"
+                                         "same directory as \"%s\".\n"
+                                         "Check your installation.\n"),
+                                       progname, full_path);
                else
                        fprintf(stderr,
-                                               _("The program \"pg_dump\" was found by %s "
-                                               "but was not the same version as \"%s\".\n"
-                                               "Check your installation.\n"),
-                                               progname, progname);
+                                       _("The program \"pg_dump\" was found by \"%s\"\n"
+                                         "but was not the same version as %s.\n"
+                                         "Check your installation.\n"),
+                                       full_path, progname);
                exit(1);
        }
 
@@ -179,9 +186,16 @@ main(int argc, char *argv[])
 
                        case 'h':
                                pghost = optarg;
+#ifndef WIN32
                                appendPQExpBuffer(pgdumpopts, " -h '%s'", pghost);
+#else
+                                appendPQExpBuffer(pgdumpopts, " -h \"%s\"", pghost);
+#endif
+
                                break;
 
+
+
                        case 'i':
                        case 'o':
                                appendPQExpBuffer(pgdumpopts, " -%c", c);
@@ -193,7 +207,11 @@ main(int argc, char *argv[])
 
                        case 'p':
                                pgport = optarg;
+#ifndef WIN32
                                appendPQExpBuffer(pgdumpopts, " -p '%s'", pgport);
+#else
+                                appendPQExpBuffer(pgdumpopts, " -p \"%s\"", pgport);
+#endif
                                break;
 
                        case 's':
@@ -202,12 +220,20 @@ main(int argc, char *argv[])
                                break;
 
                        case 'S':
+#ifndef WIN32
                                appendPQExpBuffer(pgdumpopts, " -S '%s'", optarg);
+#else
+                                appendPQExpBuffer(pgdumpopts, " -S \"%s\"", optarg);
+#endif
                                break;
 
                        case 'U':
                                pguser = optarg;
+#ifndef WIN32
                                appendPQExpBuffer(pgdumpopts, " -U '%s'", pguser);
+#else
+                                appendPQExpBuffer(pgdumpopts, " -U \"%s\"", pguser);
+#endif
                                break;
 
                        case 'v':
@@ -231,7 +257,7 @@ main(int argc, char *argv[])
                                else if (strcmp(optarg, "disable-triggers") == 0)
                                        appendPQExpBuffer(pgdumpopts, " -X disable-triggers");
                                else if (strcmp(optarg, "use-set-session-authorization") == 0)
-                                       /* no-op, still allowed for compatibility */ ;
+                                        /* no-op, still allowed for compatibility */ ;
                                else
                                {
                                        fprintf(stderr,
@@ -251,14 +277,14 @@ main(int argc, char *argv[])
                }
        }
 
-       /*  Add long options to the pg_dump argument list */
+       /* Add long options to the pg_dump argument list */
        if (disable_dollar_quoting)
                appendPQExpBuffer(pgdumpopts, " -X disable-dollar-quoting");
        if (disable_triggers)
                appendPQExpBuffer(pgdumpopts, " -X disable-triggers");
        if (use_setsessauth)
                appendPQExpBuffer(pgdumpopts, " -X use-set-session-authorization");
-               
+
        if (optind < argc)
        {
                fprintf(stderr, _("%s: too many command-line arguments (first is \"%s\")\n"),
@@ -273,7 +299,7 @@ main(int argc, char *argv[])
 
        printf("--\n-- PostgreSQL database cluster dump\n--\n\n");
        if (verbose)
-                       dumpTimestamp("Started on");
+               dumpTimestamp("Started on");
 
        printf("\\connect \"template1\"\n\n");
 
@@ -330,7 +356,7 @@ help(void)
        printf(_("  -X disable-dollar-quoting, --disable-dollar-quoting\n"
                         "                           disable dollar quoting, use SQL standard quoting\n"));
        printf(_("  -X disable-triggers, --disable-triggers\n"
-                "                           disable triggers during data-only restore\n"));
+                        "                           disable triggers during data-only restore\n"));
        printf(_("  -X use-set-session-authorization, --use-set-session-authorization\n"
                         "                           use SESSION AUTHORIZATION commands instead of\n"
                         "                           OWNER TO commands\n"));
@@ -378,15 +404,20 @@ dumpUsers(PGconn *conn, bool initdbonly)
        for (i = 0; i < PQntuples(res); i++)
        {
                const char *username;
-               bool clusterowner;
+               bool            clusterowner;
                PQExpBuffer buf = createPQExpBuffer();
+
                username = PQgetvalue(res, i, 0);
                clusterowner = (strcmp(PQgetvalue(res, i, 6), "t") == 0);
 
                /* Check which pass we're on */
-               if ((initdbonly && !clusterowner) || (!initdbonly && clusterowner)) continue;
+               if ((initdbonly && !clusterowner) || (!initdbonly && clusterowner))
+                       continue;
 
-               /* Dump ALTER USER for the cluster owner and CREATE USER for all other users */
+               /*
+                * Dump ALTER USER for the cluster owner and CREATE USER for all
+                * other users
+                */
                if (!clusterowner)
                        appendPQExpBuffer(buf, "CREATE USER %s WITH SYSID %s",
                                                          fmtId(username),
@@ -502,22 +533,22 @@ dumpTablespaces(PGconn *conn)
         * pg_xxx)
         */
        res = executeQuery(conn, "SELECT spcname, "
-                                          "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, "
+                                        "pg_catalog.pg_get_userbyid(spcowner) AS spcowner, "
                                           "spclocation, spcacl "
                                           "FROM pg_catalog.pg_tablespace "
                                           "WHERE spcname NOT LIKE 'pg\\_%'");
-       
+
        if (PQntuples(res) > 0)
                printf("--\n-- Tablespaces\n--\n\n");
 
        for (i = 0; i < PQntuples(res); i++)
        {
                PQExpBuffer buf = createPQExpBuffer();
-               char    *spcname = PQgetvalue(res, i, 0);
-               char    *spcowner = PQgetvalue(res, i, 1);
-               char    *spclocation = PQgetvalue(res, i, 2);
-               char    *spcacl = PQgetvalue(res, i, 3);
-               char    *fspcname;
+               char       *spcname = PQgetvalue(res, i, 0);
+               char       *spcowner = PQgetvalue(res, i, 1);
+               char       *spclocation = PQgetvalue(res, i, 2);
+               char       *spcacl = PQgetvalue(res, i, 3);
+               char       *fspcname;
 
                /* needed for buildACLCommands() */
                fspcname = strdup(fmtId(spcname));
@@ -778,11 +809,15 @@ makeAlterConfigCommand(const char *arrayitem, const char *type, const char *name
        *pos = 0;
        appendPQExpBuffer(buf, "ALTER %s %s ", type, fmtId(name));
        appendPQExpBuffer(buf, "SET %s TO ", fmtId(mine));
-       /* Some GUC variable names are 'LIST' type and hence must not be quoted. */
+
+       /*
+        * Some GUC variable names are 'LIST' type and hence must not be
+        * quoted.
+        */
        if (strcasecmp(mine, "DateStyle") == 0
-                       || strcasecmp(mine, "search_path") == 0)
+               || strcasecmp(mine, "search_path") == 0)
                appendPQExpBuffer(buf, "%s", pos + 1);
-       else 
+       else
                appendStringLiteral(buf, pos + 1, false);
        appendPQExpBuffer(buf, ";\n");
 
@@ -841,10 +876,10 @@ runPgDump(const char *dbname)
        int                     ret;
 
        /*
-        *      Win32 has to use double-quotes for args, rather than single quotes.
-        *      Strangely enough, this is the only place we pass a database name
-        *      on the command line, except template1 that doesn't need quoting.
-        */     
+        * Win32 has to use double-quotes for args, rather than single quotes.
+        * Strangely enough, this is the only place we pass a database name on
+        * the command line, except template1 that doesn't need quoting.
+        */
 #ifndef WIN32
        appendPQExpBuffer(cmd, "%s\"%s\" %s -Fp '", SYSTEMQUOTE, pg_dump_bin,
 #else
@@ -870,9 +905,10 @@ runPgDump(const char *dbname)
        appendPQExpBufferChar(cmd, '\'');
 #else
        appendPQExpBufferChar(cmd, '"');
-       appendPQExpBuffer(cmd, SYSTEMQUOTE);
 #endif
-       
+
+       appendPQExpBuffer(cmd, "%s", SYSTEMQUOTE);
+
        if (verbose)
                fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data);
 
@@ -993,8 +1029,8 @@ executeQuery(PGconn *conn, const char *query)
 static void
 dumpTimestamp(char *msg)
 {
-       char buf[256];
-       time_t now = time(NULL);
+       char            buf[256];
+       time_t          now = time(NULL);
 
        if (strftime(buf, 256, "%Y-%m-%d %H:%M:%S %Z", localtime(&now)) != 0)
                printf("-- %s %s\n\n", msg, buf);