*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.79.2.1 2004/01/04 04:02:22 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.79.2.2 2004/02/24 03:35:43 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
*/
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;
return res;
}
+/*
+ * 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,
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
- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.355.2.2 2004/01/22 19:09:48 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.355.2.3 2004/02/24 03:35:45 tgl Exp $
*
*-------------------------------------------------------------------------
*/
static const char *fmtQualifiedId(const char *schema, const char *id);
static int dumpBlobs(Archive *AH, char *, void *);
static int dumpDatabase(Archive *AH);
+static void dumpEncoding(Archive *AH);
static const char *getAttrName(int attrnum, TableInfo *tblInfo);
static const char *fmtCopyColumnList(const TableInfo *ti);
write_msg(NULL, "last built-in OID is %u\n", g_last_builtin_oid);
}
+ /* First the special encoding entry. */
+ dumpEncoding(g_fout);
+
/* Dump the database definition */
if (!dataOnly)
dumpDatabase(g_fout);
}
+/*
+ * 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);
+ if (!res ||
+ PQresultStatus(res) != PGRES_TUPLES_OK ||
+ PQntuples(res) != 1)
+ {
+ write_msg(NULL, "SQL command failed\n");
+ write_msg(NULL, "Error message from server: %s", PQerrorMessage(g_conn));
+ write_msg(NULL, "The command was: %s\n", qry->data);
+ exit_nicely();
+ }
+
+ resetPQExpBuffer(qry);
+
+ appendPQExpBuffer(qry, "SET client_encoding = ");
+ appendStringLiteral(qry, PQgetvalue(res, 0, 0), true);
+ appendPQExpBuffer(qry, ";\n");
+
+ ArchiveEntry(AH, "0", /* OID */
+ "ENCODING", /* Name */
+ NULL, /* Namespace */
+ "", /* Owner */
+ "ENCODING", /* Desc */
+ NULL, /* Deps */
+ qry->data, /* Create */
+ "", /* Del */
+ NULL, /* Copy */
+ NULL, /* Dumper */
+ NULL); /* Dumper Arg */
+
+ PQclear(res);
+
+ destroyPQExpBuffer(qry);
+}
+
+
/*
* dumpBlobs:
* dump all blobs