*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.82 2004/01/04 04:02:15 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.83 2004/02/24 03:35:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
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);
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)
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)
{
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;
}
/*
+ * 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.
free(AH->currSchema);
AH->currSchema = strdup("");
- AH->chk_fn_bodies = true; /* assumed default state */
+ /* re-establish fixed state */
+ _doSetFixedOutputState(AH);
}
/*
_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 ";
else
* by PostgreSQL
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.364 2004/02/12 23:41:03 tgl Exp $
+ * $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.365 2004/02/24 03:35:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static const char *fmtQualifiedId(const char *schema, const char *id);
static int dumpBlobs(Archive *AH, void *arg);
static void dumpDatabase(Archive *AH);
+static void dumpEncoding(Archive *AH);
static const char *getAttrName(int attrnum, TableInfo *tblInfo);
static const char *fmtCopyColumnList(const TableInfo *ti);
static void do_sql_command(PGconn *conn, const char *query);
* in a safe order.
*/
- /* The database item is always first. */
+ /* First the special encoding entry. */
+ dumpEncoding(g_fout);
+
+ /* The database item is always second. */
if (!dataOnly)
dumpDatabase(g_fout);
- /* Max OID is second. */
+ /* Max OID is next. */
if (oids == true)
setMaxOid(g_fout);
dumpDumpableObject(g_fout, dobjs[i]);
}
- /* BLOBs are always last. */
+ /* BLOBs are always last (XXX is this right?) */
if (outputBlobs)
ArchiveEntry(g_fout, nilCatalogId, createDumpId(),
"BLOBS", NULL, "",
/*
+ * dumpEncoding: put the correct encoding into the archive
+ */
+static void
+dumpEncoding(Archive *AH)
+{
+ PQExpBuffer qry;
+ PGresult *res;
+
+ /* Can't read the encoding from pre-7.3 servers (SHOW isn't a query) */
+ if (AH->remoteVersion < 70300)
+ return;
+
+ if (g_verbose)
+ write_msg(NULL, "saving encoding\n");
+
+ qry = createPQExpBuffer();
+
+ appendPQExpBuffer(qry, "SHOW client_encoding");
+
+ res = PQexec(g_conn, qry->data);
+
+ check_sql_result(res, g_conn, qry->data, PGRES_TUPLES_OK);
+
+ resetPQExpBuffer(qry);
+
+ appendPQExpBuffer(qry, "SET client_encoding = ");
+ appendStringLiteral(qry, PQgetvalue(res, 0, 0), true);
+ appendPQExpBuffer(qry, ";\n");
+
+ ArchiveEntry(AH, nilCatalogId, createDumpId(),
+ "ENCODING", NULL, "",
+ "ENCODING", qry->data, "", NULL,
+ NULL, 0,
+ NULL, NULL);
+
+ PQclear(res);
+
+ destroyPQExpBuffer(qry);
+}
+
+
+/*
* dumpBlobs:
* dump all blobs
*