Pavel Stehule <[EMAIL PROTECTED]> writes:
> I send my first patch for PostgreSQL - maybe ugly patch. This patch
> generate on top of dump file line with setting of current encoding. Its
> useful for languages like czech with more than one wide used encoding.
> We need informations about used encoding.
This patch wouldn't work in the pg_dump/pg_restore case, because it
assumes that the original connection is still accessible when the output
script is being generated. You have to make an ArchiveEntry that can
be recorded in non-text archives. I've applied the attached patch
instead, which I think does things correctly.
regards, tom lane
PS: please send future patches in "diff -c" format. With plain diff
output it's impossible to tell where insertions really go ... especially
since you did not specify what version you made the diff against ...
Index: pg_backup_archiver.c
===
RCS file: /cvsroot/pgsql-server/src/bin/pg_dump/pg_backup_archiver.c,v
retrieving revision 1.79.2.1
diff -c -r1.79.2.1 pg_backup_archiver.c
*** pg_backup_archiver.c4 Jan 2004 04:02:22 - 1.79.2.1
--- pg_backup_archiver.c24 Feb 2004 03:27:04 -
***
*** 48,53
--- 48,54
const int compression, ArchiveMode mode);
static int_printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt,
bool isData);
+ static void _doSetFixedOutputState(ArchiveHandle *AH);
static void _doSetSessionAuth(ArchiveHandle *AH, const char *user);
static void _reconnectToDB(ArchiveHandle *AH, const char *dbname, const char *user);
static void _becomeUser(ArchiveHandle *AH, const char *user);
***
*** 205,210
--- 206,216
ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
/*
+* Establish important parameter values right away.
+*/
+ _doSetFixedOutputState(AH);
+
+ /*
* Drop the items at the start, in reverse order
*/
if (ropt->dropSchema)
***
*** 1703,1709
AH->currUser = strdup(""); /* So it's valid, but we can free() it
* later if necessary
*/
AH->currSchema = strdup("");/* ditto */
- AH->chk_fn_bodies = true; /* assumed default state */
AH->toc = (TocEntry *) calloc(1, sizeof(TocEntry));
if (!AH->toc)
--- 1709,1714
***
*** 1935,1940
--- 1940,1949
{
teReqs res = 3;/* Schema = 1, Data = 2, Both = 3 */
+ /* ENCODING objects are dumped specially, so always reject here */
+ if (strcmp(te->desc, "ENCODING") == 0)
+ return 0;
+
/* If it's an ACL, maybe ignore it */
if (ropt->aclsSkip && strcmp(te->desc, "ACL") == 0)
return 0;
***
*** 2020,2025
--- 2029,2061
}
/*
+ * Issue SET commands for parameters that we want to have set the same way
+ * at all times during execution of a restore script.
+ */
+ static void
+ _doSetFixedOutputState(ArchiveHandle *AH)
+ {
+ TocEntry *te;
+
+ /* If we have an encoding setting, emit that */
+ te = AH->toc->next;
+ while (te != AH->toc)
+ {
+ if (strcmp(te->desc, "ENCODING") == 0)
+ {
+ ahprintf(AH, "%s", te->defn);
+ break;
+ }
+ te = te->next;
+ }
+
+ /* Make sure function checking is disabled */
+ ahprintf(AH, "SET check_function_bodies = false;\n");
+
+ ahprintf(AH, "\n");
+ }
+
+ /*
* Issue a SET SESSION AUTHORIZATION command. Caller is responsible
* for updating state if appropriate. If user is NULL or an empty string,
* the specification DEFAULT will be used.
***
*** 2100,2106
free(AH->currSchema);
AH->currSchema = strdup("");
! AH->chk_fn_bodies = true; /* assumed default state */
}
/*
--- 2136,2143
free(AH->currSchema);
AH->currSchema = strdup("");
! /* re-establish fixed state */
! _doSetFixedOutputState(AH);
}
/*
***
*** 2195,2207
/* Select owner and schema as necessary */
_becomeOwner(AH, te);
_selectOutputSchema(AH, te->namespace);
-
- /* If it's a function, make sure function checking is disabled */
- if (AH->chk_fn_bodies && strcmp(te->desc, "FUNCTION") == 0)
- {
- ahprintf(AH, "SET check_function_bodies = false;\n\n");
- AH->chk_fn_bodies = false;
- }
if (isData)
pfx = "Data for ";
--- 2232,2237
Index: pg_backup_archiver.h
===
RCS file: /cvsroot/pgsql-server/src/bin/pg_dump/pg_backup_archive