Dear patchers,
please find attached a small patch so that pg_restore ignores some sql
errors. This is the second submission, which integrates Tom comments about
localisation and exit code. I also added some comments about one sql
command which is not ignored.
I tested it.
Have a nice day,
--
Fabien Coelho - [EMAIL PROTECTED]*** ./src/bin/pg_dump/pg_backup.h.orig Wed Mar 24 17:19:43 2004
--- ./src/bin/pg_dump/pg_backup.h Sat Apr 10 13:04:21 2004
***
*** 57,62
--- 57,67
int remoteVersion;
int minRemoteVersion;
int maxRemoteVersion;
+
+ /* error handling */
+ bool die_on_errors; /* whether to die on sql errors... */
+ int n_errors; /* number of errors (if no
die) */
+
/* The rest is private */
} Archive;
*** ./src/bin/pg_dump/pg_backup_archiver.c.orig Wed Mar 24 17:19:43 2004
--- ./src/bin/pg_dump/pg_backup_archiver.c Sat Apr 10 13:09:55 2004
***
*** 1197,1202
--- 1197,1220
va_end(ap);
}
+ /* on some error, we may decide to go on... */
+ void
+ warn_or_die_horribly(ArchiveHandle *AH,
+const char *modulename, const char *fmt, ...)
+ {
+ va_list ap;
+ va_start(ap, fmt);
+ if (AH-public.die_on_errors)
+ {
+ _die_horribly(AH, modulename, fmt, ap);
+ }
+ else
+ {
+ _write_msg(modulename, fmt, ap);
+ AH-public.n_errors++;
+ }
+ va_end(ap);
+ }
static void
_moveAfter(ArchiveHandle *AH, TocEntry *pos, TocEntry *te)
***
*** 1651,1656
--- 1669,1678
die_horribly(AH, modulename, unrecognized file format
\%d\\n, fmt);
}
+ /* sql error handling */
+ AH-public.die_on_errors = true;
+ AH-public.n_errors = 0;
+
return AH;
}
***
*** 2011,2016
--- 2033,2039
res = PQexec(AH-connection, cmd-data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
+ /* NOT warn_or_die_horribly... use -O instead to skip this. */
die_horribly(AH, modulename, could not set session user to
\%s\: %s,
user, PQerrorMessage(AH-connection));
***
*** 2042,2049
res = PQexec(AH-connection, cmd-data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
! die_horribly(AH, modulename, could not set default_with_oids:
%s,
!PQerrorMessage(AH-connection));
PQclear(res);
}
--- 2065,2073
res = PQexec(AH-connection, cmd-data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
! warn_or_die_horribly(AH, modulename,
!could not set
default_with_oids: %s,
!
PQerrorMessage(AH-connection));
PQclear(res);
}
***
*** 2181,2188
res = PQexec(AH-connection, qry-data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
! die_horribly(AH, modulename, could not set search_path to
\%s\: %s,
!schemaName,
PQerrorMessage(AH-connection));
PQclear(res);
}
--- 2205,2213
res = PQexec(AH-connection, qry-data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
! warn_or_die_horribly(AH, modulename,
!could not set
search_path to \%s\: %s,
!schemaName,
PQerrorMessage(AH-connection));
PQclear(res);
}
*** ./src/bin/pg_dump/pg_backup_archiver.h.orig Wed Mar 24 17:19:43 2004
--- ./src/bin/pg_dump/pg_backup_archiver.h Sat Apr 10 13:04:21 2004
***
*** 281,286
--- 281,287
extern const char *progname;
extern void die_horribly(ArchiveHandle *AH, const char *modulename, const char
*fmt,...) __attribute__((format(printf, 3, 4)));
+ extern void warn_or_die_horribly(ArchiveHandle *AH, const char *modulename, const
char *fmt,...) __attribute__((format(printf, 3, 4)));
extern void write_msg(const char *modulename, const char *fmt,...)
__attribute__((format(printf, 2, 3)));
extern void WriteTOC(ArchiveHandle *AH);
*** ./src/bin/pg_dump/pg_backup_db.c.orig Wed Mar 3 22:28:54 2004
--- ./src/bin/pg_dump/pg_backup_db.cSat Apr 10 13:04:21 2004
***
*** 316,323