]> granicus.if.org Git - postgresql/commitdiff
> Please find attached a submission to add a "exit on error" option to
authorBruce Momjian <bruce@momjian.us>
Fri, 20 Aug 2004 04:20:23 +0000 (04:20 +0000)
committerBruce Momjian <bruce@momjian.us>
Fri, 20 Aug 2004 04:20:23 +0000 (04:20 +0000)
> pg_restore, as it seems that some people have scripts that rely on the
> previous "abort on error" default behavior when restoring data with a
> direct connection.
>
> Fabien Coelho

doc/src/sgml/ref/pg_restore.sgml
src/bin/pg_dump/pg_backup.h
src/bin/pg_dump/pg_backup_archiver.c
src/bin/pg_dump/pg_restore.c

index 533bdd9c0b8f5cad926e875a7ba8e9acd18a3ab2..6ffad3b5384be8ad8fc55b1cafc85da433dabf21 100644 (file)
@@ -1,4 +1,4 @@
-<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.47 2004/07/13 02:59:49 momjian Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/ref/pg_restore.sgml,v 1.48 2004/08/20 04:20:22 momjian Exp $ -->
 
 <refentry id="APP-PGRESTORE">
  <refmeta>
       </listitem>
      </varlistentry>
 
+     <varlistentry>
+      <term><option>-e</option></term>
+      <term><option>--exit-on-error</option></term>
+      <listitem>
+       <para>
+        Exit if an error is encountered while sending SQL commands to
+        the database. The default is to continue and to display a count of 
+        errors at the end of the restoration.
+       </para>
+      </listitem>
+     </varlistentry>
+
      <varlistentry>
       <term><option>-f <replaceable>filename</replaceable></option></term>
       <term><option>--file=<replaceable>filename</replaceable></option></term>
index 4957ea9a14763e40aa697da99fee7266d92c7eac..7723203df7fda0c604b39d726be4307ab4bcd92d 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.31 2004/07/13 03:00:17 momjian Exp $
+ *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup.h,v 1.32 2004/08/20 04:20:22 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -59,7 +59,7 @@ typedef struct _Archive
        int                     maxRemoteVersion;
 
        /* error handling */
-       bool            die_on_errors;  /* whether to die on sql errors... */
+       bool            exit_on_error;  /* whether to exit on SQL errors... */
        int                     n_errors;               /* number of errors (if no die) */
 
        /* The rest is private */
@@ -103,6 +103,7 @@ typedef struct _restoreOptions
        char       *username;
        int                     ignoreVersion;
        int                     requirePassword;
+       int                     exit_on_error;
 
        bool       *idWanted;
        bool            limitToList;
index d528d2df57870804c9c533e980d05c714f4f68e8..5c610f962bce5eaa1b405213d433fca0db4a7366 100644 (file)
@@ -15,7 +15,7 @@
  *
  *
  * IDENTIFICATION
- *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.92 2004/08/13 21:37:28 tgl Exp $
+ *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.93 2004/08/20 04:20:22 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -457,6 +457,7 @@ NewRestoreOptions(void)
 
        opts->format = archUnknown;
        opts->suppressDumpWarnings = false;
+       opts->exit_on_error = false;
 
        return opts;
 }
@@ -1227,7 +1228,7 @@ warn_or_die_horribly(ArchiveHandle *AH,
 {
        va_list ap;
        va_start(ap, fmt);
-       if (AH->public.die_on_errors)
+       if (AH->public.exit_on_error)
        {
                _die_horribly(AH, modulename, fmt, ap);
        }
@@ -1693,7 +1694,7 @@ _allocAH(const char *FileSpec, const ArchiveFormat fmt,
        }
 
        /* sql error handling */
-       AH->public.die_on_errors = true;
+       AH->public.exit_on_error = true;
        AH->public.n_errors = 0;
 
        return AH;
index eef86a25e57626ba04b5a02190017c5c974f47df..918a93a656872ca905905b04459695238b6753c4 100644 (file)
@@ -34,7 +34,7 @@
  *
  *
  * IDENTIFICATION
- *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.59 2004/07/13 03:00:17 momjian Exp $
+ *             $PostgreSQL: pgsql/src/bin/pg_dump/pg_restore.c,v 1.60 2004/08/20 04:20:23 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -90,6 +90,7 @@ main(int argc, char **argv)
                {"create", 0, NULL, 'C'},
                {"data-only", 0, NULL, 'a'},
                {"dbname", 1, NULL, 'd'},
+               {"exit-on-error", 0, NULL, 'e'},
                {"file", 1, NULL, 'f'},
                {"format", 1, NULL, 'F'},
                {"function", 1, NULL, 'P'},
@@ -141,7 +142,7 @@ main(int argc, char **argv)
                }
        }
 
-       while ((c = getopt_long(argc, argv, "acCd:f:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:",
+       while ((c = getopt_long(argc, argv, "acCd:ef:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:",
                                                        cmdopts, NULL)) != -1)
        {
                switch (c)
@@ -159,6 +160,9 @@ main(int argc, char **argv)
                        case 'd':
                                opts->dbname = strdup(optarg);
                                break;
+                       case 'e':
+                               opts->exit_on_error = true;
+                               break;
                        case 'f':                       /* output file name */
                                opts->filename = strdup(optarg);
                                break;
@@ -321,10 +325,10 @@ main(int argc, char **argv)
        /* Let the archiver know how noisy to be */
        AH->verbose = opts->verbose;
 
-       /* restore keeps submitting sql commands as "pg_restore ... | psql ... "
-        * this behavior choice could be turned into an option.
+       /*
+        *      Whether to keep submitting sql commands as "pg_restore ... | psql ... "
         */
-       AH->die_on_errors = false;
+       AH->exit_on_error = opts->exit_on_error;
 
        if (opts->tocFile)
                SortTocFromFile(AH, opts);
@@ -391,6 +395,7 @@ usage(const char *progname)
        printf(_("  -p, --port=PORT          database server port number\n"));
        printf(_("  -U, --username=NAME      connect as specified database user\n"));
        printf(_("  -W, --password           force password prompt (should happen automatically)\n"));
+       printf(_("  -e, --exit-on-error      exit on error, default is to continue\n"));
 
        printf(_("\nIf no input file name is supplied, then standard input is used.\n\n"));
        printf(_("Report bugs to <pgsql-bugs@postgresql.org>.\n"));