Dear patchers,

Please find attached a submission to add a "die on errors" option to
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.

It works for me. Maybe Philip could test that it works for him?

Have a nice day,

-- 
Fabien Coelho - [EMAIL PROTECTED]
*** ./doc/src/sgml/ref/pg_restore.sgml.orig     Thu Jul 15 10:29:00 2004
--- ./doc/src/sgml/ref/pg_restore.sgml  Thu Aug 12 10:29:09 2004
***************
*** 130,135 ****
--- 130,147 ----
       </varlistentry>
  
       <varlistentry>
+       <term><option>-D</option></term>
+       <term><option>--die-on-errors</option></term>
+       <listitem>
+        <para>
+         Die if an error is encountered while sending sql commands into
+         the database. Default is to keep going 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>
        <listitem>
*** ./src/bin/pg_dump/pg_backup.h.orig  Thu Jul 15 10:29:01 2004
--- ./src/bin/pg_dump/pg_backup.h       Thu Aug 12 10:18:43 2004
***************
*** 103,108 ****
--- 103,109 ----
        char       *username;
        int                     ignoreVersion;
        int                     requirePassword;
+       int                     die_on_errors;
  
        bool       *idWanted;
        bool            limitToList;
*** ./src/bin/pg_dump/pg_backup_archiver.c.orig Tue Aug 10 08:29:06 2004
--- ./src/bin/pg_dump/pg_backup_archiver.c      Thu Aug 12 14:41:35 2004
***************
*** 461,466 ****
--- 461,467 ----
  
        opts->format = archUnknown;
        opts->suppressDumpWarnings = false;
+       opts->die_on_errors = false;
  
        return opts;
  }
*** ./src/bin/pg_dump/pg_restore.c.orig Thu Jul 15 10:29:01 2004
--- ./src/bin/pg_dump/pg_restore.c      Thu Aug 12 14:44:13 2004
***************
*** 90,95 ****
--- 90,96 ----
                {"create", 0, NULL, 'C'},
                {"data-only", 0, NULL, 'a'},
                {"dbname", 1, NULL, 'd'},
+               {"die-on-errors", 0, NULL, 'D'},
                {"file", 1, NULL, 'f'},
                {"format", 1, NULL, 'F'},
                {"function", 1, NULL, 'P'},
***************
*** 141,147 ****
                }
        }
  
!       while ((c = getopt_long(argc, argv, "acCd:f:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:",
                                                        cmdopts, NULL)) != -1)
        {
                switch (c)
--- 142,148 ----
                }
        }
  
!       while ((c = getopt_long(argc, argv, "acCd:Df:F:h:iI:lL:Op:P:RsS:t:T:uU:vWxX:",
                                                        cmdopts, NULL)) != -1)
        {
                switch (c)
***************
*** 159,164 ****
--- 160,168 ----
                        case 'd':
                                opts->dbname = strdup(optarg);
                                break;
+                       case 'D':
+                               opts->die_on_errors = true;
+                               break;
                        case 'f':                       /* output file name */
                                opts->filename = strdup(optarg);
                                break;
***************
*** 321,330 ****
        /* 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.
         */
!       AH->die_on_errors = false;
  
        if (opts->tocFile)
                SortTocFromFile(AH, opts);
--- 325,333 ----
        /* Let the archiver know how noisy to be */
        AH->verbose = opts->verbose;
  
!       /* whether to keep submitting sql commands as "pg_restore ... | psql ... "
         */
!       AH->die_on_errors = opts->die_on_errors;
  
        if (opts->tocFile)
                SortTocFromFile(AH, opts);
***************
*** 391,396 ****
--- 394,400 ----
        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(_("  -D, --die-on-errors      die on errors, default is to keep 
going\n"));
  
        printf(_("\nIf no input file name is supplied, then standard input is 
used.\n\n"));
        printf(_("Report bugs to <[EMAIL PROTECTED]>.\n"));
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to