Commit c828ec88 authored by Peter Eisentraut's avatar Peter Eisentraut

Make pg_dump output more portable and more pleasing to look at.

The -n and -N options were removed.  Quoting is now smart enough to
supply quotes if and only if necessary.

Numerical types are now printed without quotes, except in cases of
special values such as NaN.

Boolean values printed as true and false.

Most string literals now do not escape whitespace characters (newlines,
etc.) for portability.

SET SESSION AUTHORIZATION argument is a string literal, to follow SQL.

Made commands output by pg_dump use consistent spacing and indentation.
parent 41298cf8
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.47 2002/08/10 16:57:31 petere Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/ref/pg_dump.sgml,v 1.48 2002/08/18 09:36:25 petere Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -29,7 +29,6 @@ PostgreSQL documentation ...@@ -29,7 +29,6 @@ PostgreSQL documentation
<arg>-f <replaceable>file</replaceable></arg> <arg>-f <replaceable>file</replaceable></arg>
<arg>-F <replaceable>format</replaceable></arg> <arg>-F <replaceable>format</replaceable></arg>
<arg>-i</arg> <arg>-i</arg>
<group> <arg>-n</arg> <arg>-N</arg> </group>
<arg>-o</arg> <arg>-o</arg>
<arg>-O</arg> <arg>-O</arg>
<arg>-R</arg> <arg>-R</arg>
...@@ -302,31 +301,6 @@ PostgreSQL documentation ...@@ -302,31 +301,6 @@ PostgreSQL documentation
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><option>-n</></term>
<term><option>--no-quotes</></term>
<listitem>
<para>
Suppress double quotes around identifiers unless absolutely necessary.
This may cause trouble loading this dumped data if there are reserved words
used for identifiers.
This was the default behavior for
<command>pg_dump</command> prior to version 6.4.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><option>-N</></term>
<term><option>--quotes</></term>
<listitem>
<para>
Include double quotes around identifiers.
This is the default.
</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><option>-o</></term> <term><option>-o</></term>
<term><option>--oids</></term> <term><option>--oids</></term>
......
<!-- <!--
$Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.146 2002/08/11 21:17:34 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/release.sgml,v 1.147 2002/08/18 09:36:25 petere Exp $
--> -->
<appendix id="release"> <appendix id="release">
...@@ -24,6 +24,7 @@ CDATA means the content is "SGML-free", so you can write without ...@@ -24,6 +24,7 @@ CDATA means the content is "SGML-free", so you can write without
worries about funny characters. worries about funny characters.
--> -->
<literallayout><![CDATA[ <literallayout><![CDATA[
pg_dump -n and -N options have been removed. The new behavior is like -n but knows about key words.
CLUSTER is no longer hazardous to your schema CLUSTER is no longer hazardous to your schema
COPY accepts a list of columns to copy COPY accepts a list of columns to copy
ALTER TABLE DROP COLUMN ALTER TABLE DROP COLUMN
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.124 2002/08/06 05:40:45 ishii Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/keywords.c,v 1.125 2002/08/18 09:36:25 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "parser/keywords.h" #include "parser/keywords.h"
#include "parser/parse.h" #include "parser/parse.h"
/* NB: This file is also used by pg_dump. */
/* /*
* List of (keyword-name, keyword-token-value) pairs. * List of (keyword-name, keyword-token-value) pairs.
* *
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* back to source text * back to source text
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.116 2002/08/16 23:01:19 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.117 2002/08/18 09:36:25 petere Exp $
* *
* This software is copyrighted by Jan Wieck - Hamburg. * This software is copyrighted by Jan Wieck - Hamburg.
* *
...@@ -2529,14 +2529,42 @@ get_const_expr(Const *constval, deparse_context *context) ...@@ -2529,14 +2529,42 @@ get_const_expr(Const *constval, deparse_context *context)
{ {
case INT2OID: case INT2OID:
case INT4OID: case INT4OID:
case OIDOID: /* int types */ case INT8OID:
case OIDOID:
case FLOAT4OID: case FLOAT4OID:
case FLOAT8OID: /* float types */ case FLOAT8OID:
/* These types are printed without quotes */ case NUMERICOID:
{
/*
* These types are printed without quotes unless they
* contain values that aren't accepted by the scanner
* unquoted (e.g., 'NaN'). Note that strtod() and friends
* might accept NaN, so we can't use that to test.
*
* In reality we only need to defend against infinity and
* NaN, so we need not get too crazy about pattern
* matching here.
*/
if (strspn(extval, "0123456789 +-eE.") == strlen(extval))
appendStringInfo(buf, extval); appendStringInfo(buf, extval);
else
appendStringInfo(buf, "'%s'", extval);
}
break;
case BITOID:
case VARBITOID:
appendStringInfo(buf, "B'%s'", extval);
break; break;
default:
case BOOLOID:
if (strcmp(extval, "t")==0)
appendStringInfo(buf, "true");
else
appendStringInfo(buf, "false");
break;
default:
/* /*
* We must quote any funny characters in the constant's * We must quote any funny characters in the constant's
* representation. XXX Any MULTIBYTE considerations here? * representation. XXX Any MULTIBYTE considerations here?
...@@ -2564,6 +2592,7 @@ get_const_expr(Const *constval, deparse_context *context) ...@@ -2564,6 +2592,7 @@ get_const_expr(Const *constval, deparse_context *context)
switch (constval->consttype) switch (constval->consttype)
{ {
case BOOLOID:
case INT4OID: case INT4OID:
case FLOAT8OID: case FLOAT8OID:
case UNKNOWNOID: case UNKNOWNOID:
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
# Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group # Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
# Portions Copyright (c) 1994, Regents of the University of California # Portions Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.36 2002/07/27 20:10:05 petere Exp $ # $Header: /cvsroot/pgsql/src/bin/pg_dump/Makefile,v 1.37 2002/08/18 09:36:25 petere Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -16,15 +16,18 @@ include $(top_builddir)/src/Makefile.global ...@@ -16,15 +16,18 @@ include $(top_builddir)/src/Makefile.global
OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \ OBJS= pg_backup_archiver.o pg_backup_db.o pg_backup_custom.o \
pg_backup_files.o pg_backup_null.o pg_backup_tar.o sprompt.o pg_backup_files.o pg_backup_null.o pg_backup_tar.o sprompt.o
EXTRA_OBJS = $(top_builddir)/src/backend/parser/keywords.o
override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS) override CPPFLAGS := -I$(libpq_srcdir) $(CPPFLAGS)
all: submake-libpq submake-libpgport pg_dump pg_restore pg_dumpall
all: submake-libpq submake-libpgport submake-backend pg_dump pg_restore pg_dumpall
pg_dump: pg_dump.o common.o $(OBJS) $(libpq_builddir)/libpq.a pg_dump: pg_dump.o common.o $(OBJS) $(libpq_builddir)/libpq.a
$(CC) $(CFLAGS) pg_dump.o common.o $(OBJS) $(libpq) $(LDFLAGS) $(LIBS) -o $@ $(CC) $(CFLAGS) pg_dump.o common.o $(OBJS) $(EXTRA_OBJS) $(libpq) $(LDFLAGS) $(LIBS) -o $@
pg_restore: pg_restore.o $(OBJS) $(libpq_builddir)/libpq.a pg_restore: pg_restore.o $(OBJS) $(libpq_builddir)/libpq.a
$(CC) $(CFLAGS) pg_restore.o $(OBJS) $(libpq) $(LDFLAGS) $(LIBS) -o $@ $(CC) $(CFLAGS) pg_restore.o $(OBJS) $(EXTRA_OBJS) $(libpq) $(LDFLAGS) $(LIBS) -o $@
pg_dumpall: pg_dumpall.sh pg_dumpall: pg_dumpall.sh
sed -e 's,@VERSION@,$(VERSION),g' \ sed -e 's,@VERSION@,$(VERSION),g' \
...@@ -33,6 +36,11 @@ pg_dumpall: pg_dumpall.sh ...@@ -33,6 +36,11 @@ pg_dumpall: pg_dumpall.sh
$< >$@ $< >$@
chmod a+x $@ chmod a+x $@
.PHONY: submake-backend
submake-backend:
$(MAKE) -C $(top_builddir)/src/backend/parser
install: all installdirs install: all installdirs
$(INSTALL_PROGRAM) pg_dump$(X) $(DESTDIR)$(bindir)/pg_dump$(X) $(INSTALL_PROGRAM) pg_dump$(X) $(DESTDIR)$(bindir)/pg_dump$(X)
$(INSTALL_PROGRAM) pg_restore$(X) $(DESTDIR)$(bindir)/pg_restore$(X) $(INSTALL_PROGRAM) pg_restore$(X) $(DESTDIR)$(bindir)/pg_restore$(X)
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.20 2002/07/04 15:35:07 momjian Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup.h,v 1.21 2002/08/18 09:36:25 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "postgres_fe.h" #include "postgres_fe.h"
#include "libpq-fe.h" #include "libpq-fe.h"
#include "pqexpbuffer.h"
#define atooid(x) ((Oid) strtoul((x), NULL, 10)) #define atooid(x) ((Oid) strtoul((x), NULL, 10))
#define oidcmp(x,y) ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) ) #define oidcmp(x,y) ( ((x) < (y) ? -1 : ((x) > (y)) ? 1 : 0) )
...@@ -119,7 +120,9 @@ __attribute__((format(printf, 3, 4))); ...@@ -119,7 +120,9 @@ __attribute__((format(printf, 3, 4)));
extern char *simple_prompt(const char *prompt, int maxlen, bool echo); extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
extern const char *fmtId(const char *identifier, bool force_quotes); extern const char *fmtId(const char *identifier);
extern void appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll);
/* Lets the archive know we have a DB connection to shutdown if it dies */ /* Lets the archive know we have a DB connection to shutdown if it dies */
......
...@@ -15,12 +15,13 @@ ...@@ -15,12 +15,13 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.53 2002/08/10 16:57:31 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.54 2002/08/18 09:36:25 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
#include "pg_backup.h" #include "pg_backup.h"
#include "pg_dump.h"
#include "pg_backup_archiver.h" #include "pg_backup_archiver.h"
#include "pg_backup_db.h" #include "pg_backup_db.h"
...@@ -30,6 +31,8 @@ ...@@ -30,6 +31,8 @@
#include "pqexpbuffer.h" #include "pqexpbuffer.h"
#include "libpq/libpq-fs.h" #include "libpq/libpq-fs.h"
#include "parser/keywords.h"
typedef enum _teReqs_ typedef enum _teReqs_
{ {
...@@ -45,7 +48,7 @@ static ArchiveHandle *_allocAH(const char *FileSpec, const ArchiveFormat fmt, ...@@ -45,7 +48,7 @@ static ArchiveHandle *_allocAH(const char *FileSpec, const ArchiveFormat fmt,
const int compression, ArchiveMode mode); const int compression, ArchiveMode mode);
static int _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData); static int _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData);
static void _doSetSessionAuth(ArchiveHandle *AH, const char *autharg); static void _doSetSessionAuth(ArchiveHandle *AH, const char *user);
static void _reconnectAsOwner(ArchiveHandle *AH, const char *dbname, TocEntry *te); static void _reconnectAsOwner(ArchiveHandle *AH, const char *dbname, TocEntry *te);
static void _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user); static void _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user);
static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName); static void _selectOutputSchema(ArchiveHandle *AH, const char *schemaName);
...@@ -202,7 +205,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -202,7 +205,7 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
if (ropt->filename || ropt->compression) if (ropt->filename || ropt->compression)
sav = SetOutput(AH, ropt->filename, ropt->compression); sav = SetOutput(AH, ropt->filename, ropt->compression);
ahprintf(AH, "--\n-- Selected TOC Entries:\n--\n"); ahprintf(AH, "--\n-- PostgreSQL database dump\n--\n\n");
/* /*
* Drop the items at the start, in reverse order * Drop the items at the start, in reverse order
...@@ -233,7 +236,6 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt) ...@@ -233,7 +236,6 @@ RestoreArchive(Archive *AHX, RestoreOptions *ropt)
te = AH->toc->next; te = AH->toc->next;
while (te != AH->toc) while (te != AH->toc)
{ {
/* Work out what, if anything, we want from this entry */ /* Work out what, if anything, we want from this entry */
reqs = _tocEntryRequired(te, ropt); reqs = _tocEntryRequired(te, ropt);
...@@ -464,7 +466,7 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop ...@@ -464,7 +466,7 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop
} }
else if (AH->ropt->use_setsessauth) else if (AH->ropt->use_setsessauth)
{ {
_doSetSessionAuth(AH, "DEFAULT"); _doSetSessionAuth(AH, NULL);
} }
ahlog(AH, 1, "disabling triggers\n"); ahlog(AH, 1, "disabling triggers\n");
...@@ -482,7 +484,7 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop ...@@ -482,7 +484,7 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop
if (te && te->tag && strlen(te->tag) > 0) if (te && te->tag && strlen(te->tag) > 0)
ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = 0 " ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = 0 "
"WHERE oid = '%s'::pg_catalog.regclass;\n\n", "WHERE oid = '%s'::pg_catalog.regclass;\n\n",
fmtId(te->tag, false)); fmtId(te->tag));
else else
ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = 0 FROM pg_catalog.pg_namespace " ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = 0 FROM pg_catalog.pg_namespace "
"WHERE relnamespace = pg_namespace.oid AND nspname !~ '^pg_';\n\n"); "WHERE relnamespace = pg_namespace.oid AND nspname !~ '^pg_';\n\n");
...@@ -498,7 +500,7 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop ...@@ -498,7 +500,7 @@ _disableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *rop
} }
else if (AH->ropt->use_setsessauth) else if (AH->ropt->use_setsessauth)
{ {
_doSetSessionAuth(AH, fmtId(oldUser, false)); _doSetSessionAuth(AH, oldUser);
} }
free(oldUser); free(oldUser);
free(oldSchema); free(oldSchema);
...@@ -531,7 +533,7 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt ...@@ -531,7 +533,7 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt
} }
else if (AH->ropt->use_setsessauth) else if (AH->ropt->use_setsessauth)
{ {
_doSetSessionAuth(AH, "DEFAULT"); _doSetSessionAuth(AH, NULL);
} }
ahlog(AH, 1, "enabling triggers\n"); ahlog(AH, 1, "enabling triggers\n");
...@@ -550,7 +552,7 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt ...@@ -550,7 +552,7 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt
ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = " ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = "
"(SELECT pg_catalog.count(*) FROM pg_catalog.pg_trigger where pg_class.oid = tgrelid) " "(SELECT pg_catalog.count(*) FROM pg_catalog.pg_trigger where pg_class.oid = tgrelid) "
"WHERE oid = '%s'::pg_catalog.regclass;\n\n", "WHERE oid = '%s'::pg_catalog.regclass;\n\n",
fmtId(te->tag, false)); fmtId(te->tag));
else else
ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = " ahprintf(AH, "UPDATE pg_catalog.pg_class SET reltriggers = "
"(SELECT pg_catalog.count(*) FROM pg_catalog.pg_trigger where pg_class.oid = tgrelid) " "(SELECT pg_catalog.count(*) FROM pg_catalog.pg_trigger where pg_class.oid = tgrelid) "
...@@ -568,7 +570,7 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt ...@@ -568,7 +570,7 @@ _enableTriggersIfNecessary(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt
} }
else if (AH->ropt->use_setsessauth) else if (AH->ropt->use_setsessauth)
{ {
_doSetSessionAuth(AH, fmtId(oldUser, false)); _doSetSessionAuth(AH, oldUser);
} }
free(oldUser); free(oldUser);
free(oldSchema); free(oldSchema);
...@@ -1942,29 +1944,38 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt) ...@@ -1942,29 +1944,38 @@ _tocEntryRequired(TocEntry *te, RestoreOptions *ropt)
/* /*
* Issue a SET SESSION AUTHORIZATION command. Caller is responsible * Issue a SET SESSION AUTHORIZATION command. Caller is responsible
* for updating state if appropriate. Note that caller must also quote * for updating state if appropriate. If user is NULL, the
* the argument if it's a username (it might be DEFAULT, too). * specification DEFAULT will be used.
*/ */
static void static void
_doSetSessionAuth(ArchiveHandle *AH, const char *autharg) _doSetSessionAuth(ArchiveHandle *AH, const char *user)
{ {
PQExpBuffer cmd = createPQExpBuffer();
appendPQExpBuffer(cmd, "SET SESSION AUTHORIZATION ");
if (user)
/* SQL requires a string literal here. Might as well be
* correct. */
appendStringLiteral(cmd, user, false);
else
appendPQExpBuffer(cmd, "DEFAULT");
appendPQExpBuffer(cmd, ";");
if (RestoringToDB(AH)) if (RestoringToDB(AH))
{ {
PQExpBuffer qry = createPQExpBuffer();
PGresult *res; PGresult *res;
appendPQExpBuffer(qry, "SET SESSION AUTHORIZATION %s;", autharg); res = PQexec(AH->connection, cmd->data);
res = PQexec(AH->connection, qry->data);
if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
die_horribly(AH, modulename, "could not set session user to %s: %s", die_horribly(AH, modulename, "could not set session user to %s: %s",
autharg, PQerrorMessage(AH->connection)); user, PQerrorMessage(AH->connection));
PQclear(res); PQclear(res);
destroyPQExpBuffer(qry);
} }
else else
ahprintf(AH, "SET SESSION AUTHORIZATION %s;\n\n", autharg); ahprintf(AH, "%s\n\n", cmd->data);
destroyPQExpBuffer(cmd);
} }
...@@ -1991,7 +2002,7 @@ _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user) ...@@ -1991,7 +2002,7 @@ _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user)
*/ */
if (!dbname && AH->ropt->use_setsessauth) if (!dbname && AH->ropt->use_setsessauth)
{ {
_doSetSessionAuth(AH, fmtId(user, false)); _doSetSessionAuth(AH, user);
} }
else if (AH->ropt && AH->ropt->noReconnect) else if (AH->ropt && AH->ropt->noReconnect)
{ {
...@@ -2005,9 +2016,9 @@ _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user) ...@@ -2005,9 +2016,9 @@ _reconnectAsUser(ArchiveHandle *AH, const char *dbname, const char *user)
PQExpBuffer qry = createPQExpBuffer(); PQExpBuffer qry = createPQExpBuffer();
appendPQExpBuffer(qry, "\\connect %s", appendPQExpBuffer(qry, "\\connect %s",
dbname ? fmtId(dbname, false) : "-"); dbname ? fmtId(dbname) : "-");
appendPQExpBuffer(qry, " %s\n\n", appendPQExpBuffer(qry, " %s\n\n",
fmtId(user, false)); fmtId(user));
ahprintf(AH, qry->data); ahprintf(AH, qry->data);
...@@ -2061,7 +2072,7 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName) ...@@ -2061,7 +2072,7 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
qry = createPQExpBuffer(); qry = createPQExpBuffer();
appendPQExpBuffer(qry, "SET search_path = %s", appendPQExpBuffer(qry, "SET search_path = %s",
fmtId(schemaName, false)); fmtId(schemaName));
if (strcmp(schemaName, "pg_catalog") != 0) if (strcmp(schemaName, "pg_catalog") != 0)
appendPQExpBuffer(qry, ", pg_catalog"); appendPQExpBuffer(qry, ", pg_catalog");
...@@ -2089,48 +2100,48 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName) ...@@ -2089,48 +2100,48 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
/* /*
* fmtId * Quotes input string if it's not a legitimate SQL identifier as-is.
*
* Quotes input string if it's not a legitimate SQL identifier as-is,
* or all the time if force_quotes is true.
* *
* Note that the returned string must be used before calling fmtId again, * Note that the returned string must be used before calling fmtId again,
* since we re-use the same return buffer each time. Non-reentrant but * since we re-use the same return buffer each time. Non-reentrant but
* avoids memory leakage. * avoids memory leakage.
*/ */
const char * const char *
fmtId(const char *rawid, bool force_quotes) fmtId(const char *rawid)
{ {
static PQExpBuffer id_return = NULL; static PQExpBuffer id_return = NULL;
const char *cp; const char *cp;
bool need_quotes = false;
if (id_return) /* first time through? */ if (id_return) /* first time through? */
resetPQExpBuffer(id_return); resetPQExpBuffer(id_return);
else else
id_return = createPQExpBuffer(); id_return = createPQExpBuffer();
if (!force_quotes) /* These checks need to match the identifier production in scan.l.
{ * Don't use islower() etc. */
/* do a quick check on the first character... */
if (!islower((unsigned char) *rawid) && *rawid != '_') if (ScanKeywordLookup(rawid))
force_quotes = true; need_quotes = true;
/* slightly different rules for first character */
else if (!((rawid[0] >= 'a' && rawid[0] <= 'z') || rawid[0] == '_'))
need_quotes = true;
else else
{ {
/* otherwise check the entire string */ /* otherwise check the entire string */
for (cp = rawid; *cp; cp++) for (cp = rawid; *cp; cp++)
{ {
if (!(islower((unsigned char) *cp) || if (!((*cp >= 'a' && *cp <= 'z')
isdigit((unsigned char) *cp) || || (*cp >= '0' && *cp <= '9')
(*cp == '_'))) || (*cp == '_')))
{ {
force_quotes = true; need_quotes = true;
break; break;
} }
} }
} }
}
if (!force_quotes) if (!need_quotes)
{ {
/* no quoting needed */ /* no quoting needed */
appendPQExpBufferStr(id_return, rawid); appendPQExpBufferStr(id_return, rawid);
...@@ -2156,6 +2167,50 @@ fmtId(const char *rawid, bool force_quotes) ...@@ -2156,6 +2167,50 @@ fmtId(const char *rawid, bool force_quotes)
} }
/*
* Convert a string value to an SQL string literal and append it to
* the given buffer.
*
* Special characters are escaped. Quote mark ' goes to '' per SQL
* standard, other stuff goes to \ sequences. If escapeAll is false,
* whitespace characters are not escaped (tabs, newlines, etc.). This
* is appropriate for dump file output.
*/
void
appendStringLiteral(PQExpBuffer buf, const char *str, bool escapeAll)
{
appendPQExpBufferChar(buf, '\'');
while (*str)
{
char ch = *str++;
if (ch == '\\' || ch == '\'')
{
appendPQExpBufferChar(buf, ch); /* double these */
appendPQExpBufferChar(buf, ch);
}
else if ((unsigned char) ch < (unsigned char) ' ' &&
(escapeAll
|| (ch != '\t' && ch != '\n' && ch != '\v' && ch != '\f' && ch != '\r')
))
{
/*
* generate octal escape for control chars other than
* whitespace
*/
appendPQExpBufferChar(buf, '\\');
appendPQExpBufferChar(buf, ((ch >> 6) & 3) + '0');
appendPQExpBufferChar(buf, ((ch >> 3) & 7) + '0');
appendPQExpBufferChar(buf, (ch & 7) + '0');
}
else
appendPQExpBufferChar(buf, ch);
}
appendPQExpBufferChar(buf, '\'');
}
static int static int
_printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData) _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isData)
{ {
...@@ -2170,7 +2225,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat ...@@ -2170,7 +2225,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
else else
pfx = ""; pfx = "";
ahprintf(AH, "--\n-- %sTOC Entry ID %d (OID %s)\n--\n-- Name: %s Type: %s Schema: %s Owner: %s\n", ahprintf(AH, "--\n-- %sTOC entry %d (OID %s)\n-- Name: %s; Type: %s; Schema: %s; Owner: %s\n",
pfx, te->id, te->oid, te->tag, te->desc, pfx, te->id, te->oid, te->tag, te->desc,
te->namespace ? te->namespace : "-", te->namespace ? te->namespace : "-",
te->owner); te->owner);
...@@ -2178,7 +2233,8 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat ...@@ -2178,7 +2233,8 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
(*AH->PrintExtraTocPtr) (AH, te); (*AH->PrintExtraTocPtr) (AH, te);
ahprintf(AH, "--\n\n"); ahprintf(AH, "--\n\n");
ahprintf(AH, "%s\n", te->defn); if (strlen(te->defn) > 0)
ahprintf(AH, "%s\n\n", te->defn);
return 1; return 1;
} }
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Implements the basic DB functions used by the archiver. * Implements the basic DB functions used by the archiver.
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.36 2002/08/10 16:57:31 petere Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_backup_db.c,v 1.37 2002/08/18 09:36:25 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -590,9 +590,9 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te) ...@@ -590,9 +590,9 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te)
if (te->namespace && strlen(te->namespace) > 0) if (te->namespace && strlen(te->namespace) > 0)
appendPQExpBuffer(tblName, "%s.", appendPQExpBuffer(tblName, "%s.",
fmtId(te->namespace, false)); fmtId(te->namespace));
appendPQExpBuffer(tblName, "%s", appendPQExpBuffer(tblName, "%s",
fmtId(te->tag, false)); fmtId(te->tag));
appendPQExpBuffer(tblQry, appendPQExpBuffer(tblQry,
"SELECT a.attname FROM " "SELECT a.attname FROM "
...@@ -624,13 +624,13 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te) ...@@ -624,13 +624,13 @@ FixupBlobRefs(ArchiveHandle *AH, TocEntry *te)
/* Can't use fmtId twice in one call... */ /* Can't use fmtId twice in one call... */
appendPQExpBuffer(tblQry, appendPQExpBuffer(tblQry,
"UPDATE %s SET %s = %s.newOid", "UPDATE %s SET %s = %s.newOid",
tblName->data, fmtId(attr, false), tblName->data, fmtId(attr),
BLOB_XREF_TABLE); BLOB_XREF_TABLE);
appendPQExpBuffer(tblQry, appendPQExpBuffer(tblQry,
" FROM %s WHERE %s.oldOid = %s.%s", " FROM %s WHERE %s.oldOid = %s.%s",
BLOB_XREF_TABLE, BLOB_XREF_TABLE,
BLOB_XREF_TABLE, BLOB_XREF_TABLE,
tblName->data, fmtId(attr, false)); tblName->data, fmtId(attr));
ahlog(AH, 10, "SQL: %s\n", tblQry->data); ahlog(AH, 10, "SQL: %s\n", tblQry->data);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.284 2002/08/16 23:01:19 tgl Exp $ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.285 2002/08/18 09:36:25 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
*/ */
#include "postgres.h" #include "postgres.h"
#include <unistd.h> /* for getopt() */ #include <unistd.h>
#include <ctype.h> #include <ctype.h>
#ifdef ENABLE_NLS #ifdef ENABLE_NLS
#include <locale.h> #include <locale.h>
...@@ -65,16 +65,6 @@ ...@@ -65,16 +65,6 @@
#include "pg_backup_archiver.h" #include "pg_backup_archiver.h"
typedef enum _formatLiteralOptions
{
CONV_ALL = 0,
PASS_LFTAB = 3 /* NOTE: 1 and 2 are reserved in case we
* want to make a mask. */
/* We could make this a bit mask for control chars, but I don't */
/* see any value in making it more complex...the current code */
/* only checks for 'opts == CONV_ALL' anyway. */
} formatLiteralOptions;
typedef struct _dumpContext typedef struct _dumpContext
{ {
TableInfo *tblinfo; TableInfo *tblinfo;
...@@ -111,8 +101,6 @@ static void dumpACL(Archive *fout, const char *type, const char *name, ...@@ -111,8 +101,6 @@ static void dumpACL(Archive *fout, const char *type, const char *name,
static void dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables); static void dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables);
static void dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables); static void dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables);
static void dumpRules(Archive *fout, TableInfo *tblinfo, int numTables); static void dumpRules(Archive *fout, TableInfo *tblinfo, int numTables);
static void formatStringLiteral(PQExpBuffer buf, const char *str,
const formatLiteralOptions opts);
static char *format_function_signature(FuncInfo *finfo, bool honor_quotes); static char *format_function_signature(FuncInfo *finfo, bool honor_quotes);
static void dumpOneFunc(Archive *fout, FuncInfo *finfo); static void dumpOneFunc(Archive *fout, FuncInfo *finfo);
static void dumpOneOpr(Archive *fout, OprInfo *oprinfo, static void dumpOneOpr(Archive *fout, OprInfo *oprinfo,
...@@ -149,7 +137,6 @@ Archive *g_fout; /* the script file */ ...@@ -149,7 +137,6 @@ Archive *g_fout; /* the script file */
PGconn *g_conn; /* the database connection */ PGconn *g_conn; /* the database connection */
/* various user-settable parameters */ /* various user-settable parameters */
bool force_quotes; /* User wants to suppress double-quotes */
bool dumpData; /* dump data using proper insert strings */ bool dumpData; /* dump data using proper insert strings */
bool attrNames; /* put attr names into insert strings */ bool attrNames; /* put attr names into insert strings */
bool schemaOnly; bool schemaOnly;
...@@ -214,8 +201,6 @@ main(int argc, char **argv) ...@@ -214,8 +201,6 @@ main(int argc, char **argv)
{"host", required_argument, NULL, 'h'}, {"host", required_argument, NULL, 'h'},
{"ignore-version", no_argument, NULL, 'i'}, {"ignore-version", no_argument, NULL, 'i'},
{"no-reconnect", no_argument, NULL, 'R'}, {"no-reconnect", no_argument, NULL, 'R'},
{"no-quotes", no_argument, NULL, 'n'},
{"quotes", no_argument, NULL, 'N'},
{"oids", no_argument, NULL, 'o'}, {"oids", no_argument, NULL, 'o'},
{"no-owner", no_argument, NULL, 'O'}, {"no-owner", no_argument, NULL, 'O'},
{"port", required_argument, NULL, 'p'}, {"port", required_argument, NULL, 'p'},
...@@ -250,7 +235,6 @@ main(int argc, char **argv) ...@@ -250,7 +235,6 @@ main(int argc, char **argv)
#endif #endif
g_verbose = false; g_verbose = false;
force_quotes = true;
strcpy(g_comment_start, "-- "); strcpy(g_comment_start, "-- ");
g_comment_end[0] = '\0'; g_comment_end[0] = '\0';
...@@ -285,9 +269,9 @@ main(int argc, char **argv) ...@@ -285,9 +269,9 @@ main(int argc, char **argv)
} }
#ifdef HAVE_GETOPT_LONG #ifdef HAVE_GETOPT_LONG
while ((c = getopt_long(argc, argv, "abcCdDf:F:h:inNoOp:RsS:t:uU:vWxX:zZ:V?", long_options, &optindex)) != -1) while ((c = getopt_long(argc, argv, "abcCdDf:F:h:ioOp:RsS:t:uU:vWxX:zZ:V?", long_options, &optindex)) != -1)
#else #else
while ((c = getopt(argc, argv, "abcCdDf:F:h:inNoOp:RsS:t:uU:vWxX:zZ:V?-")) != -1) while ((c = getopt(argc, argv, "abcCdDf:F:h:ioOp:RsS:t:uU:vWxX:zZ:V?-")) != -1)
#endif #endif
{ {
...@@ -337,15 +321,6 @@ main(int argc, char **argv) ...@@ -337,15 +321,6 @@ main(int argc, char **argv)
ignore_version = true; ignore_version = true;
break; break;
case 'n': /* Do not force double-quotes on
* identifiers */
force_quotes = false;
break;
case 'N': /* Force double-quotes on identifiers */
force_quotes = true;
break;
case 'o': /* Dump oids */ case 'o': /* Dump oids */
oids = true; oids = true;
break; break;
...@@ -962,7 +937,7 @@ dumpClasses_nodumpData(Archive *fout, char *oid, void *dctxv) ...@@ -962,7 +937,7 @@ dumpClasses_nodumpData(Archive *fout, char *oid, void *dctxv)
* save the 'last sleep time'. * save the 'last sleep time'.
*/ */
} }
archprintf(fout, "\\.\n"); archprintf(fout, "\\.\n\n\n");
ret = PQendcopy(g_conn); ret = PQendcopy(g_conn);
if (ret != 0) if (ret != 0)
...@@ -1038,7 +1013,7 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv) ...@@ -1038,7 +1013,7 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
for (tuple = 0; tuple < PQntuples(res); tuple++) for (tuple = 0; tuple < PQntuples(res); tuple++)
{ {
archprintf(fout, "INSERT INTO %s ", fmtId(classname, force_quotes)); archprintf(fout, "INSERT INTO %s ", fmtId(classname));
if (attrNames == true) if (attrNames == true)
{ {
resetPQExpBuffer(q); resetPQExpBuffer(q);
...@@ -1046,8 +1021,8 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv) ...@@ -1046,8 +1021,8 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
for (field = 0; field < PQnfields(res); field++) for (field = 0; field < PQnfields(res); field++)
{ {
if (field > 0) if (field > 0)
appendPQExpBuffer(q, ","); appendPQExpBuffer(q, ", ");
appendPQExpBuffer(q, fmtId(PQfname(res, field), force_quotes)); appendPQExpBuffer(q, fmtId(PQfname(res, field)));
} }
appendPQExpBuffer(q, ") "); appendPQExpBuffer(q, ") ");
archprintf(fout, "%s", q->data); archprintf(fout, "%s", q->data);
...@@ -1056,37 +1031,62 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv) ...@@ -1056,37 +1031,62 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
for (field = 0; field < PQnfields(res); field++) for (field = 0; field < PQnfields(res); field++)
{ {
if (field > 0) if (field > 0)
archprintf(fout, ","); archprintf(fout, ", ");
if (PQgetisnull(res, tuple, field)) if (PQgetisnull(res, tuple, field))
{ {
archprintf(fout, "NULL"); archprintf(fout, "NULL");
continue; continue;
} }
/* XXX This code is partially duplicated in ruleutils.c */
switch (PQftype(res, field)) switch (PQftype(res, field))
{ {
case INT2OID: case INT2OID:
case INT4OID: case INT4OID:
case OIDOID: /* int types */ case INT8OID:
case OIDOID:
case FLOAT4OID: case FLOAT4OID:
case FLOAT8OID: /* float types */ case FLOAT8OID:
/* These types are printed without quotes */ case NUMERICOID:
archprintf(fout, "%s", {
PQgetvalue(res, tuple, field)); /*
* These types are printed without quotes
* unless they contain values that aren't
* accepted by the scanner unquoted (e.g.,
* 'NaN'). Note that strtod() and friends
* might accept NaN, so we can't use that to
* test.
*
* In reality we only need to defend against
* infinity and NaN, so we need not get too
* crazy about pattern matching here.
*/
const char *s = PQgetvalue(res, tuple, field);
if (strspn(s, "0123456789 +-eE.") == strlen(s))
archprintf(fout, "%s", s);
else
archprintf(fout, "'%s'", s);
}
break; break;
case BITOID: case BITOID:
case VARBITOID: case VARBITOID:
archprintf(fout, "B'%s'", archprintf(fout, "B'%s'",
PQgetvalue(res, tuple, field)); PQgetvalue(res, tuple, field));
break; break;
default:
/* case BOOLOID:
* All other types are printed as string literals, if (strcmp(PQgetvalue(res, tuple, field), "t")==0)
* with appropriate escaping of special archprintf(fout, "true");
* characters. else
*/ archprintf(fout, "false");
break;
default:
/* All other types are printed as string literals. */
resetPQExpBuffer(q); resetPQExpBuffer(q);
formatStringLiteral(q, PQgetvalue(res, tuple, field), CONV_ALL); appendStringLiteral(q, PQgetvalue(res, tuple, field), false);
archprintf(fout, "%s", q->data); archprintf(fout, "%s", q->data);
break; break;
} }
...@@ -1095,6 +1095,8 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv) ...@@ -1095,6 +1095,8 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
} }
} while (PQntuples(res) > 0); } while (PQntuples(res) > 0);
archprintf(fout, "\n\n");
PQclear(res); PQclear(res);
res = PQexec(g_conn, "CLOSE _pg_dump_cursor"); res = PQexec(g_conn, "CLOSE _pg_dump_cursor");
...@@ -1112,45 +1114,6 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv) ...@@ -1112,45 +1114,6 @@ dumpClasses_dumpData(Archive *fout, char *oid, void *dctxv)
return 1; return 1;
} }
/*
* Convert a string value to an SQL string literal,
* with appropriate escaping of special characters.
* Quote mark ' goes to '' per SQL standard, other
* stuff goes to \ sequences.
* The literal is appended to the given PQExpBuffer.
*/
static void
formatStringLiteral(PQExpBuffer buf, const char *str, const formatLiteralOptions opts)
{
appendPQExpBufferChar(buf, '\'');
while (*str)
{
char ch = *str++;
if (ch == '\\' || ch == '\'')
{
appendPQExpBufferChar(buf, ch); /* double these */
appendPQExpBufferChar(buf, ch);
}
else if ((unsigned char) ch < (unsigned char) ' ' &&
(opts == CONV_ALL
|| (ch != '\n' && ch != '\t')
))
{
/*
* generate octal escape for control chars other than
* whitespace
*/
appendPQExpBufferChar(buf, '\\');
appendPQExpBufferChar(buf, ((ch >> 6) & 3) + '0');
appendPQExpBufferChar(buf, ((ch >> 3) & 7) + '0');
appendPQExpBufferChar(buf, (ch & 7) + '0');
}
else
appendPQExpBufferChar(buf, ch);
}
appendPQExpBufferChar(buf, '\'');
}
/* /*
* DumpClasses - * DumpClasses -
...@@ -1200,7 +1163,7 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout, ...@@ -1200,7 +1163,7 @@ dumpClasses(const TableInfo *tblinfo, const int numTables, Archive *fout,
dumpFn = dumpClasses_nodumpData; dumpFn = dumpClasses_nodumpData;
column_list = fmtCopyColumnList(&(tblinfo[i])); column_list = fmtCopyColumnList(&(tblinfo[i]));
sprintf(copyBuf, "COPY %s %s %sFROM stdin;\n", sprintf(copyBuf, "COPY %s %s %sFROM stdin;\n",
fmtId(tblinfo[i].relname, force_quotes), fmtId(tblinfo[i].relname),
column_list, column_list,
(oids && tblinfo[i].hasoids) ? "WITH OIDS " : ""); (oids && tblinfo[i].hasoids) ? "WITH OIDS " : "");
copyStmt = copyBuf; copyStmt = copyBuf;
...@@ -1253,7 +1216,7 @@ dumpDatabase(Archive *AH) ...@@ -1253,7 +1216,7 @@ dumpDatabase(Archive *AH)
appendPQExpBuffer(dbQry, "select (select usename from pg_user where usesysid = datdba) as dba," appendPQExpBuffer(dbQry, "select (select usename from pg_user where usesysid = datdba) as dba,"
" encoding, datpath from pg_database" " encoding, datpath from pg_database"
" where datname = "); " where datname = ");
formatStringLiteral(dbQry, datname, CONV_ALL); appendStringLiteral(dbQry, datname, true);
res = PQexec(g_conn, dbQry->data); res = PQexec(g_conn, dbQry->data);
if (!res || if (!res ||
...@@ -1289,7 +1252,7 @@ dumpDatabase(Archive *AH) ...@@ -1289,7 +1252,7 @@ dumpDatabase(Archive *AH)
datpath = PQgetvalue(res, 0, i_datpath); datpath = PQgetvalue(res, 0, i_datpath);
appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0", appendPQExpBuffer(creaQry, "CREATE DATABASE %s WITH TEMPLATE = template0",
fmtId(datname, force_quotes)); fmtId(datname));
if (strlen(encoding) > 0) if (strlen(encoding) > 0)
appendPQExpBuffer(creaQry, " ENCODING = %s", encoding); appendPQExpBuffer(creaQry, " ENCODING = %s", encoding);
if (strlen(datpath) > 0) if (strlen(datpath) > 0)
...@@ -1297,7 +1260,7 @@ dumpDatabase(Archive *AH) ...@@ -1297,7 +1260,7 @@ dumpDatabase(Archive *AH)
appendPQExpBuffer(creaQry, ";\n"); appendPQExpBuffer(creaQry, ";\n");
appendPQExpBuffer(delQry, "DROP DATABASE %s;\n", appendPQExpBuffer(delQry, "DROP DATABASE %s;\n",
fmtId(datname, force_quotes)); fmtId(datname));
ArchiveEntry(AH, "0", /* OID */ ArchiveEntry(AH, "0", /* OID */
datname, /* Name */ datname, /* Name */
...@@ -2628,8 +2591,7 @@ dumpComment(Archive *fout, const char *target, ...@@ -2628,8 +2591,7 @@ dumpComment(Archive *fout, const char *target,
i_description = PQfnumber(res, "description"); i_description = PQfnumber(res, "description");
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "COMMENT ON %s IS ", target); appendPQExpBuffer(query, "COMMENT ON %s IS ", target);
formatStringLiteral(query, PQgetvalue(res, 0, i_description), appendStringLiteral(query, PQgetvalue(res, 0, i_description), false);
PASS_LFTAB);
appendPQExpBuffer(query, ";\n"); appendPQExpBuffer(query, ";\n");
ArchiveEntry(fout, oid, target, namespace, owner, ArchiveEntry(fout, oid, target, namespace, owner,
...@@ -2720,11 +2682,11 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, ...@@ -2720,11 +2682,11 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
{ {
resetPQExpBuffer(target); resetPQExpBuffer(target);
appendPQExpBuffer(target, "%s %s", reltypename, appendPQExpBuffer(target, "%s %s", reltypename,
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
formatStringLiteral(query, descr, PASS_LFTAB); appendStringLiteral(query, descr, false);
appendPQExpBuffer(query, ";\n"); appendPQExpBuffer(query, ";\n");
ArchiveEntry(fout, tbinfo->oid, target->data, ArchiveEntry(fout, tbinfo->oid, target->data,
...@@ -2736,14 +2698,13 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, ...@@ -2736,14 +2698,13 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
{ {
resetPQExpBuffer(target); resetPQExpBuffer(target);
appendPQExpBuffer(target, "COLUMN %s.", appendPQExpBuffer(target, "COLUMN %s.",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
appendPQExpBuffer(target, "%s", appendPQExpBuffer(target, "%s",
fmtId(tbinfo->attnames[objsubid-1], fmtId(tbinfo->attnames[objsubid-1]));
force_quotes));
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
formatStringLiteral(query, descr, PASS_LFTAB); appendStringLiteral(query, descr, false);
appendPQExpBuffer(query, ";\n"); appendPQExpBuffer(query, ";\n");
ArchiveEntry(fout, tbinfo->oid, target->data, ArchiveEntry(fout, tbinfo->oid, target->data,
...@@ -2778,7 +2739,7 @@ dumpDBComment(Archive *fout) ...@@ -2778,7 +2739,7 @@ dumpDBComment(Archive *fout)
query = createPQExpBuffer(); query = createPQExpBuffer();
appendPQExpBuffer(query, "SELECT oid FROM pg_database WHERE datname = "); appendPQExpBuffer(query, "SELECT oid FROM pg_database WHERE datname = ");
formatStringLiteral(query, PQdb(g_conn), CONV_ALL); appendStringLiteral(query, PQdb(g_conn), true);
/*** Execute query ***/ /*** Execute query ***/
...@@ -2796,7 +2757,7 @@ dumpDBComment(Archive *fout) ...@@ -2796,7 +2757,7 @@ dumpDBComment(Archive *fout)
{ {
i_oid = PQfnumber(res, "oid"); i_oid = PQfnumber(res, "oid");
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "DATABASE %s", fmtId(PQdb(g_conn), force_quotes)); appendPQExpBuffer(query, "DATABASE %s", fmtId(PQdb(g_conn)));
dumpComment(fout, query->data, NULL, "", dumpComment(fout, query->data, NULL, "",
PQgetvalue(res, 0, i_oid), "pg_database", 0, NULL); PQgetvalue(res, 0, i_oid), "pg_database", 0, NULL);
} }
...@@ -2829,7 +2790,7 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces) ...@@ -2829,7 +2790,7 @@ dumpNamespaces(Archive *fout, NamespaceInfo *nsinfo, int numNamespaces)
if (strlen(nspinfo->nspname) == 0) if (strlen(nspinfo->nspname) == 0)
continue; continue;
qnspname = strdup(fmtId(nspinfo->nspname, force_quotes)); qnspname = strdup(fmtId(nspinfo->nspname));
/* /*
* If it's the PUBLIC namespace, don't emit a CREATE SCHEMA * If it's the PUBLIC namespace, don't emit a CREATE SCHEMA
...@@ -2998,36 +2959,36 @@ dumpOneBaseType(Archive *fout, TypeInfo *tinfo, ...@@ -2998,36 +2959,36 @@ dumpOneBaseType(Archive *fout, TypeInfo *tinfo,
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP TYPE %s.", appendPQExpBuffer(delq, "DROP TYPE %s.",
fmtId(tinfo->typnamespace->nspname, force_quotes)); fmtId(tinfo->typnamespace->nspname));
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
fmtId(tinfo->typname, force_quotes)); fmtId(tinfo->typname));
appendPQExpBuffer(q, appendPQExpBuffer(q,
"CREATE TYPE %s " "CREATE TYPE %s (\n"
"( internallength = %s,", " INTERNALLENGTH = %s,\n",
fmtId(tinfo->typname, force_quotes), fmtId(tinfo->typname),
(strcmp(typlen, "-1") == 0) ? "variable" : typlen); (strcmp(typlen, "-1") == 0) ? "variable" : typlen);
if (fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
/* regproc result is correctly quoted in 7.3 */ /* regproc result is correctly quoted in 7.3 */
appendPQExpBuffer(q, " input = %s, output = %s", appendPQExpBuffer(q, " INPUT = %s,\n OUTPUT = %s",
typinput, typoutput); typinput, typoutput);
} }
else else
{ {
/* regproc delivers an unquoted name before 7.3 */ /* regproc delivers an unquoted name before 7.3 */
/* cannot combine these because fmtId uses static result area */ /* cannot combine these because fmtId uses static result area */
appendPQExpBuffer(q, " input = %s,", appendPQExpBuffer(q, " INPUT = %s,\n",
fmtId(typinput, force_quotes)); fmtId(typinput));
appendPQExpBuffer(q, " output = %s", appendPQExpBuffer(q, " OUTPUT = %s",
fmtId(typoutput, force_quotes)); fmtId(typoutput));
} }
if (typdefault != NULL) if (typdefault != NULL)
{ {
appendPQExpBuffer(q, ", default = "); appendPQExpBuffer(q, ",\n DEFAULT = ");
formatStringLiteral(q, typdefault, CONV_ALL); appendStringLiteral(q, typdefault, true);
} }
if (tinfo->isArray) if (tinfo->isArray)
...@@ -3037,35 +2998,35 @@ dumpOneBaseType(Archive *fout, TypeInfo *tinfo, ...@@ -3037,35 +2998,35 @@ dumpOneBaseType(Archive *fout, TypeInfo *tinfo,
/* reselect schema in case changed by function dump */ /* reselect schema in case changed by function dump */
selectSourceSchema(tinfo->typnamespace->nspname); selectSourceSchema(tinfo->typnamespace->nspname);
elemType = getFormattedTypeName(tinfo->typelem, zeroAsOpaque); elemType = getFormattedTypeName(tinfo->typelem, zeroAsOpaque);
appendPQExpBuffer(q, ", element = %s, delimiter = ", elemType); appendPQExpBuffer(q, ",\n ELEMENT = %s,\n DELIMITER = ", elemType);
formatStringLiteral(q, typdelim, CONV_ALL); appendStringLiteral(q, typdelim, true);
free(elemType); free(elemType);
(*deps)[depIdx++] = strdup(tinfo->typelem); (*deps)[depIdx++] = strdup(tinfo->typelem);
} }
if (strcmp(typalign, "c") == 0) if (strcmp(typalign, "c") == 0)
appendPQExpBuffer(q, ", alignment = char"); appendPQExpBuffer(q, ",\n ALIGNMENT = char");
else if (strcmp(typalign, "s") == 0) else if (strcmp(typalign, "s") == 0)
appendPQExpBuffer(q, ", alignment = int2"); appendPQExpBuffer(q, ",\n ALIGNMENT = int2");
else if (strcmp(typalign, "i") == 0) else if (strcmp(typalign, "i") == 0)
appendPQExpBuffer(q, ", alignment = int4"); appendPQExpBuffer(q, ",\n ALIGNMENT = int4");
else if (strcmp(typalign, "d") == 0) else if (strcmp(typalign, "d") == 0)
appendPQExpBuffer(q, ", alignment = double"); appendPQExpBuffer(q, ",\n ALIGNMENT = double");
if (strcmp(typstorage, "p") == 0) if (strcmp(typstorage, "p") == 0)
appendPQExpBuffer(q, ", storage = plain"); appendPQExpBuffer(q, ",\n STORAGE = plain");
else if (strcmp(typstorage, "e") == 0) else if (strcmp(typstorage, "e") == 0)
appendPQExpBuffer(q, ", storage = external"); appendPQExpBuffer(q, ",\n STORAGE = external");
else if (strcmp(typstorage, "x") == 0) else if (strcmp(typstorage, "x") == 0)
appendPQExpBuffer(q, ", storage = extended"); appendPQExpBuffer(q, ",\n STORAGE = extended");
else if (strcmp(typstorage, "m") == 0) else if (strcmp(typstorage, "m") == 0)
appendPQExpBuffer(q, ", storage = main"); appendPQExpBuffer(q, ",\n STORAGE = main");
if (strcmp(typbyval, "t") == 0) if (strcmp(typbyval, "t") == 0)
appendPQExpBuffer(q, ", passedbyvalue);\n"); appendPQExpBuffer(q, ",\n PASSEDBYVALUE");
else
appendPQExpBuffer(q, ");\n"); appendPQExpBuffer(q, "\n);\n");
(*deps)[depIdx++] = NULL; /* End of List */ (*deps)[depIdx++] = NULL; /* End of List */
...@@ -3077,7 +3038,7 @@ dumpOneBaseType(Archive *fout, TypeInfo *tinfo, ...@@ -3077,7 +3038,7 @@ dumpOneBaseType(Archive *fout, TypeInfo *tinfo,
/*** Dump Type Comments ***/ /*** Dump Type Comments ***/
resetPQExpBuffer(q); resetPQExpBuffer(q);
appendPQExpBuffer(q, "TYPE %s", fmtId(tinfo->typname, force_quotes)); appendPQExpBuffer(q, "TYPE %s", fmtId(tinfo->typname));
dumpComment(fout, q->data, dumpComment(fout, q->data,
tinfo->typnamespace->nspname, tinfo->usename, tinfo->typnamespace->nspname, tinfo->usename,
tinfo->oid, "pg_type", 0, NULL); tinfo->oid, "pg_type", 0, NULL);
...@@ -3149,13 +3110,13 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo) ...@@ -3149,13 +3110,13 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo)
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP DOMAIN %s.", appendPQExpBuffer(delq, "DROP DOMAIN %s.",
fmtId(tinfo->typnamespace->nspname, force_quotes)); fmtId(tinfo->typnamespace->nspname));
appendPQExpBuffer(delq, "%s RESTRICT;\n", appendPQExpBuffer(delq, "%s RESTRICT;\n",
fmtId(tinfo->typname, force_quotes)); fmtId(tinfo->typname));
appendPQExpBuffer(q, appendPQExpBuffer(q,
"CREATE DOMAIN %s AS %s", "CREATE DOMAIN %s AS %s",
fmtId(tinfo->typname, force_quotes), fmtId(tinfo->typname),
typdefn); typdefn);
/* Depends on the base type */ /* Depends on the base type */
...@@ -3179,7 +3140,7 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo) ...@@ -3179,7 +3140,7 @@ dumpOneDomain(Archive *fout, TypeInfo *tinfo)
/*** Dump Domain Comments ***/ /*** Dump Domain Comments ***/
resetPQExpBuffer(q); resetPQExpBuffer(q);
appendPQExpBuffer(q, "DOMAIN %s", fmtId(tinfo->typname, force_quotes)); appendPQExpBuffer(q, "DOMAIN %s", fmtId(tinfo->typname));
dumpComment(fout, q->data, dumpComment(fout, q->data,
tinfo->typnamespace->nspname, tinfo->usename, tinfo->typnamespace->nspname, tinfo->usename,
tinfo->oid, "pg_type", 0, NULL); tinfo->oid, "pg_type", 0, NULL);
...@@ -3244,13 +3205,13 @@ dumpOneCompositeType(Archive *fout, TypeInfo *tinfo) ...@@ -3244,13 +3205,13 @@ dumpOneCompositeType(Archive *fout, TypeInfo *tinfo)
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP TYPE %s.", appendPQExpBuffer(delq, "DROP TYPE %s.",
fmtId(tinfo->typnamespace->nspname, force_quotes)); fmtId(tinfo->typnamespace->nspname));
appendPQExpBuffer(delq, "%s RESTRICT;\n", appendPQExpBuffer(delq, "%s RESTRICT;\n",
fmtId(tinfo->typname, force_quotes)); fmtId(tinfo->typname));
appendPQExpBuffer(q, appendPQExpBuffer(q,
"CREATE TYPE %s AS (", "CREATE TYPE %s AS (",
fmtId(tinfo->typname, force_quotes)); fmtId(tinfo->typname));
for (i = 0; i < ntups; i++) for (i = 0; i < ntups; i++)
{ {
...@@ -3278,7 +3239,7 @@ dumpOneCompositeType(Archive *fout, TypeInfo *tinfo) ...@@ -3278,7 +3239,7 @@ dumpOneCompositeType(Archive *fout, TypeInfo *tinfo)
/*** Dump Type Comments ***/ /*** Dump Type Comments ***/
resetPQExpBuffer(q); resetPQExpBuffer(q);
appendPQExpBuffer(q, "TYPE %s", fmtId(tinfo->typname, force_quotes)); appendPQExpBuffer(q, "TYPE %s", fmtId(tinfo->typname));
dumpComment(fout, q->data, dumpComment(fout, q->data,
tinfo->typnamespace->nspname, tinfo->usename, tinfo->typnamespace->nspname, tinfo->usename,
tinfo->oid, "pg_type", 0, NULL); tinfo->oid, "pg_type", 0, NULL);
...@@ -3440,24 +3401,23 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs) ...@@ -3440,24 +3401,23 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs)
(*deps)[depIdx++] = strdup(lanplcallfoid); (*deps)[depIdx++] = strdup(lanplcallfoid);
appendPQExpBuffer(delqry, "DROP PROCEDURAL LANGUAGE %s;\n", appendPQExpBuffer(delqry, "DROP PROCEDURAL LANGUAGE %s;\n",
fmtId(lanname, force_quotes)); fmtId(lanname));
appendPQExpBuffer(defqry, "CREATE %sPROCEDURAL LANGUAGE %s", appendPQExpBuffer(defqry, "CREATE %sPROCEDURAL LANGUAGE %s",
(PQgetvalue(res, i, i_lanpltrusted)[0] == 't') ? (PQgetvalue(res, i, i_lanpltrusted)[0] == 't') ?
"TRUSTED " : "", "TRUSTED " : "",
fmtId(lanname, force_quotes)); fmtId(lanname));
appendPQExpBuffer(defqry, " HANDLER %s", appendPQExpBuffer(defqry, " HANDLER %s",
fmtId(finfo[fidx].proname, force_quotes)); fmtId(finfo[fidx].proname));
if (strcmp(lanvalidator, "0")!=0) if (strcmp(lanvalidator, "0")!=0)
{ {
appendPQExpBuffer(defqry, " VALIDATOR "); appendPQExpBuffer(defqry, " VALIDATOR ");
/* Cope with possibility that validator is in different schema */ /* Cope with possibility that validator is in different schema */
if (finfo[vidx].pronamespace != finfo[fidx].pronamespace) if (finfo[vidx].pronamespace != finfo[fidx].pronamespace)
appendPQExpBuffer(defqry, "%s.", appendPQExpBuffer(defqry, "%s.",
fmtId(finfo[vidx].pronamespace->nspname, fmtId(finfo[vidx].pronamespace->nspname));
force_quotes));
appendPQExpBuffer(defqry, "%s", appendPQExpBuffer(defqry, "%s",
fmtId(finfo[vidx].proname, force_quotes)); fmtId(finfo[vidx].proname));
(*deps)[depIdx++] = strdup(lanvalidator); (*deps)[depIdx++] = strdup(lanvalidator);
} }
appendPQExpBuffer(defqry, ";\n"); appendPQExpBuffer(defqry, ";\n");
...@@ -3471,7 +3431,7 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs) ...@@ -3471,7 +3431,7 @@ dumpProcLangs(Archive *fout, FuncInfo finfo[], int numFuncs)
if (!aclsSkip) if (!aclsSkip)
{ {
char *tmp = strdup(fmtId(lanname, force_quotes)); char *tmp = strdup(fmtId(lanname));
dumpACL(fout, "LANGUAGE", tmp, lanname, dumpACL(fout, "LANGUAGE", tmp, lanname,
finfo[fidx].pronamespace->nspname, finfo[fidx].pronamespace->nspname,
NULL, lanacl, lanoid); NULL, lanacl, lanoid);
...@@ -3521,16 +3481,16 @@ format_function_signature(FuncInfo *finfo, bool honor_quotes) ...@@ -3521,16 +3481,16 @@ format_function_signature(FuncInfo *finfo, bool honor_quotes)
initPQExpBuffer(&fn); initPQExpBuffer(&fn);
if (honor_quotes) if (honor_quotes)
appendPQExpBuffer(&fn, "%s(", fmtId(finfo->proname, force_quotes)); appendPQExpBuffer(&fn, "%s (", fmtId(finfo->proname));
else else
appendPQExpBuffer(&fn, "%s(", finfo->proname); appendPQExpBuffer(&fn, "%s (", finfo->proname);
for (j = 0; j < finfo->nargs; j++) for (j = 0; j < finfo->nargs; j++)
{ {
char *typname; char *typname;
typname = getFormattedTypeName(finfo->argtypes[j], zeroAsOpaque); typname = getFormattedTypeName(finfo->argtypes[j], zeroAsOpaque);
appendPQExpBuffer(&fn, "%s%s", appendPQExpBuffer(&fn, "%s%s",
(j > 0) ? "," : "", (j > 0) ? ", " : "",
typname); typname);
free(typname); free(typname);
} }
...@@ -3655,11 +3615,11 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo) ...@@ -3655,11 +3615,11 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
if (strcmp(probin, "-") != 0) if (strcmp(probin, "-") != 0)
{ {
appendPQExpBuffer(asPart, "AS "); appendPQExpBuffer(asPart, "AS ");
formatStringLiteral(asPart, probin, CONV_ALL); appendStringLiteral(asPart, probin, true);
if (strcmp(prosrc, "-") != 0) if (strcmp(prosrc, "-") != 0)
{ {
appendPQExpBuffer(asPart, ", "); appendPQExpBuffer(asPart, ", ");
formatStringLiteral(asPart, prosrc, PASS_LFTAB); appendStringLiteral(asPart, prosrc, false);
} }
} }
else else
...@@ -3667,7 +3627,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo) ...@@ -3667,7 +3627,7 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
if (strcmp(prosrc, "-") != 0) if (strcmp(prosrc, "-") != 0)
{ {
appendPQExpBuffer(asPart, "AS "); appendPQExpBuffer(asPart, "AS ");
formatStringLiteral(asPart, prosrc, PASS_LFTAB); appendStringLiteral(asPart, prosrc, false);
} }
} }
...@@ -3676,17 +3636,17 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo) ...@@ -3676,17 +3636,17 @@ dumpOneFunc(Archive *fout, FuncInfo *finfo)
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delqry, "DROP FUNCTION %s.%s;\n", appendPQExpBuffer(delqry, "DROP FUNCTION %s.%s;\n",
fmtId(finfo->pronamespace->nspname, force_quotes), fmtId(finfo->pronamespace->nspname),
funcsig); funcsig);
rettypename = getFormattedTypeName(finfo->prorettype, zeroAsOpaque); rettypename = getFormattedTypeName(finfo->prorettype, zeroAsOpaque);
appendPQExpBuffer(q, "CREATE FUNCTION %s ", funcsig); appendPQExpBuffer(q, "CREATE FUNCTION %s ", funcsig);
appendPQExpBuffer(q, "RETURNS %s%s %s LANGUAGE %s", appendPQExpBuffer(q, "RETURNS %s%s\n %s\n LANGUAGE %s",
(proretset[0] == 't') ? "SETOF " : "", (proretset[0] == 't') ? "SETOF " : "",
rettypename, rettypename,
asPart->data, asPart->data,
fmtId(lanname, force_quotes)); fmtId(lanname));
free(rettypename); free(rettypename);
...@@ -4006,7 +3966,7 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo, ...@@ -4006,7 +3966,7 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo,
oprltcmpop = PQgetvalue(res, 0, i_oprltcmpop); oprltcmpop = PQgetvalue(res, 0, i_oprltcmpop);
oprgtcmpop = PQgetvalue(res, 0, i_oprgtcmpop); oprgtcmpop = PQgetvalue(res, 0, i_oprgtcmpop);
appendPQExpBuffer(details, "PROCEDURE = %s ", appendPQExpBuffer(details, " PROCEDURE = %s",
convertRegProcReference(oprcode)); convertRegProcReference(oprcode));
appendPQExpBuffer(oprid, "%s (", appendPQExpBuffer(oprid, "%s (",
...@@ -4022,8 +3982,8 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo, ...@@ -4022,8 +3982,8 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo,
if (g_fout->remoteVersion >= 70100) if (g_fout->remoteVersion >= 70100)
name = oprleft; name = oprleft;
else else
name = fmtId(oprleft, force_quotes); name = fmtId(oprleft);
appendPQExpBuffer(details, ",\n\tLEFTARG = %s ", name); appendPQExpBuffer(details, ",\n LEFTARG = %s", name);
appendPQExpBuffer(oprid, "%s", name); appendPQExpBuffer(oprid, "%s", name);
} }
else else
...@@ -4035,8 +3995,8 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo, ...@@ -4035,8 +3995,8 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo,
if (g_fout->remoteVersion >= 70100) if (g_fout->remoteVersion >= 70100)
name = oprright; name = oprright;
else else
name = fmtId(oprright, force_quotes); name = fmtId(oprright);
appendPQExpBuffer(details, ",\n\tRIGHTARG = %s ", name); appendPQExpBuffer(details, ",\n RIGHTARG = %s", name);
appendPQExpBuffer(oprid, ", %s)", name); appendPQExpBuffer(oprid, ", %s)", name);
} }
else else
...@@ -4044,45 +4004,45 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo, ...@@ -4044,45 +4004,45 @@ dumpOneOpr(Archive *fout, OprInfo *oprinfo,
name = convertOperatorReference(oprcom, g_oprinfo, numOperators); name = convertOperatorReference(oprcom, g_oprinfo, numOperators);
if (name) if (name)
appendPQExpBuffer(details, ",\n\tCOMMUTATOR = %s ", name); appendPQExpBuffer(details, ",\n COMMUTATOR = %s", name);
name = convertOperatorReference(oprnegate, g_oprinfo, numOperators); name = convertOperatorReference(oprnegate, g_oprinfo, numOperators);
if (name) if (name)
appendPQExpBuffer(details, ",\n\tNEGATOR = %s ", name); appendPQExpBuffer(details, ",\n NEGATOR = %s", name);
if (strcmp(oprcanhash, "t") == 0) if (strcmp(oprcanhash, "t") == 0)
appendPQExpBuffer(details, ",\n\tHASHES"); appendPQExpBuffer(details, ",\n HASHES");
name = convertRegProcReference(oprrest); name = convertRegProcReference(oprrest);
if (name) if (name)
appendPQExpBuffer(details, ",\n\tRESTRICT = %s ", name); appendPQExpBuffer(details, ",\n RESTRICT = %s", name);
name = convertRegProcReference(oprjoin); name = convertRegProcReference(oprjoin);
if (name) if (name)
appendPQExpBuffer(details, ",\n\tJOIN = %s ", name); appendPQExpBuffer(details, ",\n JOIN = %s", name);
name = convertOperatorReference(oprlsortop, g_oprinfo, numOperators); name = convertOperatorReference(oprlsortop, g_oprinfo, numOperators);
if (name) if (name)
appendPQExpBuffer(details, ",\n\tSORT1 = %s ", name); appendPQExpBuffer(details, ",\n SORT1 = %s", name);
name = convertOperatorReference(oprrsortop, g_oprinfo, numOperators); name = convertOperatorReference(oprrsortop, g_oprinfo, numOperators);
if (name) if (name)
appendPQExpBuffer(details, ",\n\tSORT2 = %s ", name); appendPQExpBuffer(details, ",\n SORT2 = %s", name);
name = convertOperatorReference(oprltcmpop, g_oprinfo, numOperators); name = convertOperatorReference(oprltcmpop, g_oprinfo, numOperators);
if (name) if (name)
appendPQExpBuffer(details, ",\n\tLTCMP = %s ", name); appendPQExpBuffer(details, ",\n LTCMP = %s", name);
name = convertOperatorReference(oprgtcmpop, g_oprinfo, numOperators); name = convertOperatorReference(oprgtcmpop, g_oprinfo, numOperators);
if (name) if (name)
appendPQExpBuffer(details, ",\n\tGTCMP = %s ", name); appendPQExpBuffer(details, ",\n GTCMP = %s", name);
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP OPERATOR %s.%s;\n", appendPQExpBuffer(delq, "DROP OPERATOR %s.%s;\n",
fmtId(oprinfo->oprnamespace->nspname, force_quotes), fmtId(oprinfo->oprnamespace->nspname),
oprid->data); oprid->data);
appendPQExpBuffer(q, "CREATE OPERATOR %s (%s);\n", appendPQExpBuffer(q, "CREATE OPERATOR %s (\n%s\n);\n",
oprinfo->oprname, details->data); oprinfo->oprname, details->data);
ArchiveEntry(fout, oprinfo->oid, oprinfo->oprname, ArchiveEntry(fout, oprinfo->oid, oprinfo->oprname,
...@@ -4146,7 +4106,7 @@ convertRegProcReference(const char *proc) ...@@ -4146,7 +4106,7 @@ convertRegProcReference(const char *proc)
} }
/* REGPROC before 7.3 does not quote its result */ /* REGPROC before 7.3 does not quote its result */
return fmtId(proc, false); return fmtId(proc);
} }
/* /*
...@@ -4300,26 +4260,26 @@ dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -4300,26 +4260,26 @@ dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo)
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP OPERATOR CLASS %s", appendPQExpBuffer(delq, "DROP OPERATOR CLASS %s",
fmtId(opcinfo->opcnamespace->nspname, force_quotes)); fmtId(opcinfo->opcnamespace->nspname));
appendPQExpBuffer(delq, ".%s", appendPQExpBuffer(delq, ".%s",
fmtId(opcinfo->opcname, force_quotes)); fmtId(opcinfo->opcname));
appendPQExpBuffer(delq, " USING %s;\n", appendPQExpBuffer(delq, " USING %s;\n",
fmtId(amname, force_quotes)); fmtId(amname));
/* Build the fixed portion of the CREATE command */ /* Build the fixed portion of the CREATE command */
appendPQExpBuffer(q, "CREATE OPERATOR CLASS %s\n\t", appendPQExpBuffer(q, "CREATE OPERATOR CLASS %s\n ",
fmtId(opcinfo->opcname, force_quotes)); fmtId(opcinfo->opcname));
if (strcmp(opcdefault, "t") == 0) if (strcmp(opcdefault, "t") == 0)
appendPQExpBuffer(q, "DEFAULT "); appendPQExpBuffer(q, "DEFAULT ");
appendPQExpBuffer(q, "FOR TYPE %s USING %s AS\n\t", appendPQExpBuffer(q, "FOR TYPE %s USING %s AS\n ",
opcintype, opcintype,
fmtId(amname, force_quotes)); fmtId(amname));
needComma = false; needComma = false;
if (strcmp(opckeytype, "-") != 0) if (strcmp(opckeytype, "-") != 0)
{ {
appendPQExpBuffer(q, "STORAGE\t%s", appendPQExpBuffer(q, "STORAGE %s",
opckeytype); opckeytype);
needComma = true; needComma = true;
} }
...@@ -4359,12 +4319,12 @@ dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -4359,12 +4319,12 @@ dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo)
amopopr = PQgetvalue(res, i, i_amopopr); amopopr = PQgetvalue(res, i, i_amopopr);
if (needComma) if (needComma)
appendPQExpBuffer(q, " ,\n\t"); appendPQExpBuffer(q, " ,\n ");
appendPQExpBuffer(q, "OPERATOR\t%s\t%s", appendPQExpBuffer(q, "OPERATOR %s %s",
amopstrategy, amopopr); amopstrategy, amopopr);
if (strcmp(amopreqcheck, "t") == 0) if (strcmp(amopreqcheck, "t") == 0)
appendPQExpBuffer(q, "\tRECHECK"); appendPQExpBuffer(q, " RECHECK");
needComma = true; needComma = true;
} }
...@@ -4402,9 +4362,9 @@ dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -4402,9 +4362,9 @@ dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo)
amproc = PQgetvalue(res, i, i_amproc); amproc = PQgetvalue(res, i, i_amproc);
if (needComma) if (needComma)
appendPQExpBuffer(q, " ,\n\t"); appendPQExpBuffer(q, " ,\n ");
appendPQExpBuffer(q, "FUNCTION\t%s\t%s", appendPQExpBuffer(q, "FUNCTION %s %s",
amprocnum, amproc); amprocnum, amproc);
needComma = true; needComma = true;
...@@ -4412,7 +4372,7 @@ dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -4412,7 +4372,7 @@ dumpOneOpclass(Archive *fout, OpclassInfo *opcinfo)
PQclear(res); PQclear(res);
appendPQExpBuffer(q, " ;\n"); appendPQExpBuffer(q, ";\n");
ArchiveEntry(fout, opcinfo->oid, opcinfo->opcname, ArchiveEntry(fout, opcinfo->oid, opcinfo->opcname,
opcinfo->opcnamespace->nspname, opcinfo->usename, opcinfo->opcnamespace->nspname, opcinfo->usename,
...@@ -4463,7 +4423,7 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes) ...@@ -4463,7 +4423,7 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
if (honor_quotes) if (honor_quotes)
appendPQExpBuffer(&buf, "%s", appendPQExpBuffer(&buf, "%s",
fmtId(agginfo->aggname, force_quotes)); fmtId(agginfo->aggname));
else else
appendPQExpBuffer(&buf, "%s", agginfo->aggname); appendPQExpBuffer(&buf, "%s", agginfo->aggname);
...@@ -4483,7 +4443,7 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes) ...@@ -4483,7 +4443,7 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
appendPQExpBuffer(&buf, "(*)"); appendPQExpBuffer(&buf, "(*)");
else else
appendPQExpBuffer(&buf, "(%s)", appendPQExpBuffer(&buf, "(%s)",
fmtId(agginfo->fmtbasetype, force_quotes)); fmtId(agginfo->fmtbasetype));
} }
return buf.data; return buf.data;
...@@ -4630,7 +4590,7 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo) ...@@ -4630,7 +4590,7 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
if (g_fout->remoteVersion >= 70300) if (g_fout->remoteVersion >= 70300)
{ {
/* If using 7.3's regproc or regtype, data is already quoted */ /* If using 7.3's regproc or regtype, data is already quoted */
appendPQExpBuffer(details, "BASETYPE = %s, SFUNC = %s, STYPE = %s", appendPQExpBuffer(details, " BASETYPE = %s,\n SFUNC = %s,\n STYPE = %s",
anybasetype ? "'any'" : agginfo->fmtbasetype, anybasetype ? "'any'" : agginfo->fmtbasetype,
aggtransfn, aggtransfn,
aggtranstype); aggtranstype);
...@@ -4638,42 +4598,42 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo) ...@@ -4638,42 +4598,42 @@ dumpOneAgg(Archive *fout, AggInfo *agginfo)
else if (g_fout->remoteVersion >= 70100) else if (g_fout->remoteVersion >= 70100)
{ {
/* format_type quotes, regproc does not */ /* format_type quotes, regproc does not */
appendPQExpBuffer(details, "BASETYPE = %s, SFUNC = %s, STYPE = %s", appendPQExpBuffer(details, " BASETYPE = %s,\n SFUNC = %s,\n STYPE = %s",
anybasetype ? "'any'" : agginfo->fmtbasetype, anybasetype ? "'any'" : agginfo->fmtbasetype,
fmtId(aggtransfn, force_quotes), fmtId(aggtransfn),
aggtranstype); aggtranstype);
} }
else else
{ {
/* need quotes all around */ /* need quotes all around */
appendPQExpBuffer(details, "BASETYPE = %s, ", appendPQExpBuffer(details, " BASETYPE = %s,\n",
anybasetype ? "'any'" : anybasetype ? "'any'" :
fmtId(agginfo->fmtbasetype, force_quotes)); fmtId(agginfo->fmtbasetype));
appendPQExpBuffer(details, "SFUNC = %s, ", appendPQExpBuffer(details, " SFUNC = %s,\n",
fmtId(aggtransfn, force_quotes)); fmtId(aggtransfn));
appendPQExpBuffer(details, "STYPE = %s", appendPQExpBuffer(details, " STYPE = %s",
fmtId(aggtranstype, force_quotes)); fmtId(aggtranstype));
} }
if (!PQgetisnull(res, 0, i_agginitval)) if (!PQgetisnull(res, 0, i_agginitval))
{ {
appendPQExpBuffer(details, ", INITCOND = "); appendPQExpBuffer(details, ",\n INITCOND = ");
formatStringLiteral(details, agginitval, CONV_ALL); appendStringLiteral(details, agginitval, true);
} }
if (strcmp(aggfinalfn, "-") != 0) if (strcmp(aggfinalfn, "-") != 0)
{ {
appendPQExpBuffer(details, ", FINALFUNC = %s", appendPQExpBuffer(details, ",\n FINALFUNC = %s",
aggfinalfn); aggfinalfn);
} }
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n", appendPQExpBuffer(delq, "DROP AGGREGATE %s.%s;\n",
fmtId(agginfo->aggnamespace->nspname, force_quotes), fmtId(agginfo->aggnamespace->nspname),
aggsig); aggsig);
appendPQExpBuffer(q, "CREATE AGGREGATE %s ( %s );\n", appendPQExpBuffer(q, "CREATE AGGREGATE %s (\n%s\n);\n",
fmtId(agginfo->aggname, force_quotes), fmtId(agginfo->aggname),
details->data); details->data);
ArchiveEntry(fout, agginfo->oid, aggsig_tag, ArchiveEntry(fout, agginfo->oid, aggsig_tag,
...@@ -4859,10 +4819,10 @@ dumpACL(Archive *fout, const char *type, const char *name, ...@@ -4859,10 +4819,10 @@ dumpACL(Archive *fout, const char *type, const char *name,
/* NB: only one fmtId per appendPQExpBuffer! */ /* NB: only one fmtId per appendPQExpBuffer! */
appendPQExpBuffer(sql, "REVOKE ALL ON %s %s FROM ", appendPQExpBuffer(sql, "REVOKE ALL ON %s %s FROM ",
type, name); type, name);
appendPQExpBuffer(sql, "%s;\n", fmtId(tok, force_quotes)); appendPQExpBuffer(sql, "%s;\n", fmtId(tok));
appendPQExpBuffer(sql, "GRANT %s ON %s %s TO ", appendPQExpBuffer(sql, "GRANT %s ON %s %s TO ",
priv, type, name); priv, type, name);
appendPQExpBuffer(sql, "%s;\n", fmtId(tok, force_quotes)); appendPQExpBuffer(sql, "%s;\n", fmtId(tok));
} }
} }
else else
...@@ -4879,10 +4839,9 @@ dumpACL(Archive *fout, const char *type, const char *name, ...@@ -4879,10 +4839,9 @@ dumpACL(Archive *fout, const char *type, const char *name,
} }
else if (strncmp(tok, "group ", strlen("group ")) == 0) else if (strncmp(tok, "group ", strlen("group ")) == 0)
appendPQExpBuffer(sql, "GROUP %s;\n", appendPQExpBuffer(sql, "GROUP %s;\n",
fmtId(tok + strlen("group "), fmtId(tok + strlen("group ")));
force_quotes));
else else
appendPQExpBuffer(sql, "%s;\n", fmtId(tok, force_quotes)); appendPQExpBuffer(sql, "%s;\n", fmtId(tok));
} }
} }
else else
...@@ -4897,10 +4856,9 @@ dumpACL(Archive *fout, const char *type, const char *name, ...@@ -4897,10 +4856,9 @@ dumpACL(Archive *fout, const char *type, const char *name,
} }
else if (strncmp(tok, "group ", strlen("group ")) == 0) else if (strncmp(tok, "group ", strlen("group ")) == 0)
appendPQExpBuffer(sql, "GROUP %s;\n", appendPQExpBuffer(sql, "GROUP %s;\n",
fmtId(tok + strlen("group "), fmtId(tok + strlen("group ")));
force_quotes));
else else
appendPQExpBuffer(sql, "%s;\n", fmtId(tok, force_quotes)); appendPQExpBuffer(sql, "%s;\n", fmtId(tok));
} }
free(priv); free(priv);
} }
...@@ -4912,7 +4870,7 @@ dumpACL(Archive *fout, const char *type, const char *name, ...@@ -4912,7 +4870,7 @@ dumpACL(Archive *fout, const char *type, const char *name,
{ {
appendPQExpBuffer(sql, "REVOKE ALL ON %s %s FROM ", appendPQExpBuffer(sql, "REVOKE ALL ON %s %s FROM ",
type, name); type, name);
appendPQExpBuffer(sql, "%s;\n", fmtId(usename, force_quotes)); appendPQExpBuffer(sql, "%s;\n", fmtId(usename));
} }
ArchiveEntry(fout, objoid, tag, nspname, usename ? usename : "", ArchiveEntry(fout, objoid, tag, nspname, usename ? usename : "",
...@@ -4926,7 +4884,7 @@ dumpACL(Archive *fout, const char *type, const char *name, ...@@ -4926,7 +4884,7 @@ dumpACL(Archive *fout, const char *type, const char *name,
static void static void
dumpTableACL(Archive *fout, TableInfo *tbinfo) dumpTableACL(Archive *fout, TableInfo *tbinfo)
{ {
char *tmp = strdup(fmtId(tbinfo->relname, force_quotes)); char *tmp = strdup(fmtId(tbinfo->relname));
dumpACL(fout, "TABLE", tmp, tbinfo->relname, dumpACL(fout, "TABLE", tmp, tbinfo->relname,
tbinfo->relnamespace->nspname, tbinfo->usename, tbinfo->relacl, tbinfo->relnamespace->nspname, tbinfo->usename, tbinfo->relacl,
tbinfo->viewoid != NULL ? tbinfo->viewoid : tbinfo->oid); tbinfo->viewoid != NULL ? tbinfo->viewoid : tbinfo->oid);
...@@ -5028,7 +4986,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5028,7 +4986,7 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
"(select oid from pg_rewrite where " "(select oid from pg_rewrite where "
" rulename=('_RET' || viewname)::name) as view_oid" " rulename=('_RET' || viewname)::name) as view_oid"
" from pg_views where viewname = "); " from pg_views where viewname = ");
formatStringLiteral(query, tbinfo->relname, CONV_ALL); appendStringLiteral(query, tbinfo->relname, true);
appendPQExpBuffer(query, ";"); appendPQExpBuffer(query, ";");
} }
...@@ -5074,12 +5032,12 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5074,12 +5032,12 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP VIEW %s.", appendPQExpBuffer(delq, "DROP VIEW %s.",
fmtId(tbinfo->relnamespace->nspname, force_quotes)); fmtId(tbinfo->relnamespace->nspname));
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
appendPQExpBuffer(q, "CREATE VIEW %s AS %s\n", appendPQExpBuffer(q, "CREATE VIEW %s AS\n %s\n",
fmtId(tbinfo->relname, force_quotes), viewdef); fmtId(tbinfo->relname), viewdef);
PQclear(res); PQclear(res);
...@@ -5093,9 +5051,9 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5093,9 +5051,9 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
if (tbinfo->adef_expr[j] != NULL && !tbinfo->inhAttrDef[j]) if (tbinfo->adef_expr[j] != NULL && !tbinfo->inhAttrDef[j])
{ {
appendPQExpBuffer(q, "ALTER TABLE %s ", appendPQExpBuffer(q, "ALTER TABLE %s ",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
appendPQExpBuffer(q, "ALTER COLUMN %s SET DEFAULT %s;\n", appendPQExpBuffer(q, "ALTER COLUMN %s SET DEFAULT %s;\n",
fmtId(tbinfo->attnames[j], force_quotes), fmtId(tbinfo->attnames[j]),
tbinfo->adef_expr[j]); tbinfo->adef_expr[j]);
} }
} }
...@@ -5114,12 +5072,12 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5114,12 +5072,12 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP TABLE %s.", appendPQExpBuffer(delq, "DROP TABLE %s.",
fmtId(tbinfo->relnamespace->nspname, force_quotes)); fmtId(tbinfo->relnamespace->nspname));
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
appendPQExpBuffer(q, "CREATE TABLE %s (\n\t", appendPQExpBuffer(q, "CREATE TABLE %s (",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
actual_atts = 0; actual_atts = 0;
for (j = 0; j < tbinfo->numatts; j++) for (j = 0; j < tbinfo->numatts; j++)
{ {
...@@ -5128,11 +5086,12 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5128,11 +5086,12 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
{ {
/* Format properly if not first attr */ /* Format properly if not first attr */
if (actual_atts > 0) if (actual_atts > 0)
appendPQExpBuffer(q, ",\n\t"); appendPQExpBuffer(q, ",");
appendPQExpBuffer(q, "\n ");
/* Attr name & type */ /* Attr name & type */
appendPQExpBuffer(q, "%s ", appendPQExpBuffer(q, "%s ",
fmtId(tbinfo->attnames[j], force_quotes)); fmtId(tbinfo->attnames[j]));
/* If no format_type, fake it */ /* If no format_type, fake it */
if (g_fout->remoteVersion >= 70100) if (g_fout->remoteVersion >= 70100)
...@@ -5232,11 +5191,11 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5232,11 +5191,11 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
const char *expr = PQgetvalue(res2, j, i_consrc); const char *expr = PQgetvalue(res2, j, i_consrc);
if (actual_atts + j > 0) if (actual_atts + j > 0)
appendPQExpBuffer(q, ",\n\t"); appendPQExpBuffer(q, ",\n ");
if (name[0] != '$') if (name[0] != '$')
appendPQExpBuffer(q, "CONSTRAINT %s ", appendPQExpBuffer(q, "CONSTRAINT %s ",
fmtId(name, force_quotes)); fmtId(name));
appendPQExpBuffer(q, "CHECK (%s)", expr); appendPQExpBuffer(q, "CHECK (%s)", expr);
} }
PQclear(res2); PQclear(res2);
...@@ -5265,10 +5224,9 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5265,10 +5224,9 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
appendPQExpBuffer(q, ", "); appendPQExpBuffer(q, ", ");
if (parentRel->relnamespace != tbinfo->relnamespace) if (parentRel->relnamespace != tbinfo->relnamespace)
appendPQExpBuffer(q, "%s.", appendPQExpBuffer(q, "%s.",
fmtId(parentRel->relnamespace->nspname, fmtId(parentRel->relnamespace->nspname));
force_quotes));
appendPQExpBuffer(q, "%s", appendPQExpBuffer(q, "%s",
fmtId(parentRel->relname, force_quotes)); fmtId(parentRel->relname));
} }
appendPQExpBuffer(q, ")"); appendPQExpBuffer(q, ")");
} }
...@@ -5289,9 +5247,9 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo) ...@@ -5289,9 +5247,9 @@ dumpOneTable(Archive *fout, TableInfo *tbinfo, TableInfo *g_tblinfo)
!tbinfo->attisdropped[j]) !tbinfo->attisdropped[j])
{ {
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
appendPQExpBuffer(q, "ALTER COLUMN %s ", appendPQExpBuffer(q, "ALTER COLUMN %s ",
fmtId(tbinfo->attnames[j], force_quotes)); fmtId(tbinfo->attnames[j]));
appendPQExpBuffer(q, "SET STATISTICS %d;\n", appendPQExpBuffer(q, "SET STATISTICS %d;\n",
tbinfo->attstattarget[j]); tbinfo->attstattarget[j]);
} }
...@@ -5476,10 +5434,10 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -5476,10 +5434,10 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
parseNumericArray(PQgetvalue(res, j, i_indkey), parseNumericArray(PQgetvalue(res, j, i_indkey),
indkeys, indnkeys); indkeys, indnkeys);
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", appendPQExpBuffer(q, "ALTER TABLE ONLY %s\n",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
appendPQExpBuffer(q, "ADD CONSTRAINT %s %s (", appendPQExpBuffer(q, " ADD CONSTRAINT %s %s (",
fmtId(indexrelname, force_quotes), fmtId(indexrelname),
contype == 'p' ? "PRIMARY KEY" : "UNIQUE"); contype == 'p' ? "PRIMARY KEY" : "UNIQUE");
for (k = 0; k < indnkeys; k++) for (k = 0; k < indnkeys; k++)
...@@ -5493,18 +5451,18 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -5493,18 +5451,18 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
appendPQExpBuffer(q, "%s%s", appendPQExpBuffer(q, "%s%s",
(k == 0) ? "" : ", ", (k == 0) ? "" : ", ",
fmtId(attname, force_quotes)); fmtId(attname));
} }
appendPQExpBuffer(q, ");\n"); appendPQExpBuffer(q, ");\n");
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.", appendPQExpBuffer(delq, "ALTER TABLE ONLY %s.",
fmtId(tbinfo->relnamespace->nspname, force_quotes)); fmtId(tbinfo->relnamespace->nspname));
appendPQExpBuffer(delq, "%s ", appendPQExpBuffer(delq, "%s ",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n", appendPQExpBuffer(delq, "DROP CONSTRAINT %s;\n",
fmtId(indexrelname, force_quotes)); fmtId(indexrelname));
ArchiveEntry(fout, indexreloid, ArchiveEntry(fout, indexreloid,
indexrelname, indexrelname,
...@@ -5525,9 +5483,9 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -5525,9 +5483,9 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delq, "DROP INDEX %s.", appendPQExpBuffer(delq, "DROP INDEX %s.",
fmtId(tbinfo->relnamespace->nspname, force_quotes)); fmtId(tbinfo->relnamespace->nspname));
appendPQExpBuffer(delq, "%s;\n", appendPQExpBuffer(delq, "%s;\n",
fmtId(indexrelname, force_quotes)); fmtId(indexrelname));
ArchiveEntry(fout, indexreloid, ArchiveEntry(fout, indexreloid,
indexrelname, indexrelname,
...@@ -5541,7 +5499,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -5541,7 +5499,7 @@ dumpIndexes(Archive *fout, TableInfo *tblinfo, int numTables)
/* Dump Index Comments */ /* Dump Index Comments */
resetPQExpBuffer(q); resetPQExpBuffer(q);
appendPQExpBuffer(q, "INDEX %s", appendPQExpBuffer(q, "INDEX %s",
fmtId(indexrelname, force_quotes)); fmtId(indexrelname));
dumpComment(fout, q->data, dumpComment(fout, q->data,
tbinfo->relnamespace->nspname, tbinfo->relnamespace->nspname,
tbinfo->usename, tbinfo->usename,
...@@ -5630,7 +5588,7 @@ findLastBuiltinOid_V71(const char *dbname) ...@@ -5630,7 +5588,7 @@ findLastBuiltinOid_V71(const char *dbname)
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT datlastsysoid from pg_database where datname = "); appendPQExpBuffer(query, "SELECT datlastsysoid from pg_database where datname = ");
formatStringLiteral(query, dbname, CONV_ALL); appendStringLiteral(query, dbname, true);
res = PQexec(g_conn, query->data); res = PQexec(g_conn, query->data);
if (res == NULL || if (res == NULL ||
...@@ -5715,7 +5673,7 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo, ...@@ -5715,7 +5673,7 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo,
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT sequence_name, last_value, increment_by, max_value, " "SELECT sequence_name, last_value, increment_by, max_value, "
"min_value, cache_value, is_cycled, is_called from %s", "min_value, cache_value, is_cycled, is_called from %s",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
res = PQexec(g_conn, query->data); res = PQexec(g_conn, query->data);
if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
...@@ -5764,18 +5722,18 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo, ...@@ -5764,18 +5722,18 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo,
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delqry, "DROP SEQUENCE %s.", appendPQExpBuffer(delqry, "DROP SEQUENCE %s.",
fmtId(tbinfo->relnamespace->nspname, force_quotes)); fmtId(tbinfo->relnamespace->nspname));
appendPQExpBuffer(delqry, "%s;\n", appendPQExpBuffer(delqry, "%s;\n",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, appendPQExpBuffer(query,
"CREATE SEQUENCE %s start %s increment %s " "CREATE SEQUENCE %s\n START %s\n INCREMENT %s\n"
"maxvalue %s minvalue %s cache %s%s;\n", " MAXVALUE %s\n MINVALUE %s\n CACHE %s%s;\n",
fmtId(tbinfo->relname, force_quotes), fmtId(tbinfo->relname),
(called ? minv : last), (called ? minv : last),
incby, maxv, minv, cache, incby, maxv, minv, cache,
(cycled ? " cycle" : "")); (cycled ? "\n CYCLE" : ""));
ArchiveEntry(fout, tbinfo->oid, tbinfo->relname, ArchiveEntry(fout, tbinfo->oid, tbinfo->relname,
tbinfo->relnamespace->nspname, tbinfo->usename, tbinfo->relnamespace->nspname, tbinfo->usename,
...@@ -5788,7 +5746,7 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo, ...@@ -5788,7 +5746,7 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo,
{ {
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT pg_catalog.setval ("); appendPQExpBuffer(query, "SELECT pg_catalog.setval (");
formatStringLiteral(query, fmtId(tbinfo->relname, force_quotes), CONV_ALL); appendStringLiteral(query, fmtId(tbinfo->relname), true);
appendPQExpBuffer(query, ", %s, %s);\n", appendPQExpBuffer(query, ", %s, %s);\n",
last, (called ? "true" : "false")); last, (called ? "true" : "false"));
...@@ -5804,7 +5762,7 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo, ...@@ -5804,7 +5762,7 @@ dumpOneSequence(Archive *fout, TableInfo *tbinfo,
/* Dump Sequence Comments */ /* Dump Sequence Comments */
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "SEQUENCE %s", fmtId(tbinfo->relname, force_quotes)); appendPQExpBuffer(query, "SEQUENCE %s", fmtId(tbinfo->relname));
dumpComment(fout, query->data, dumpComment(fout, query->data,
tbinfo->relnamespace->nspname, tbinfo->usename, tbinfo->relnamespace->nspname, tbinfo->usename,
tbinfo->oid, "pg_class", 0, NULL); tbinfo->oid, "pg_class", 0, NULL);
...@@ -5887,20 +5845,20 @@ dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -5887,20 +5845,20 @@ dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables)
const char *conDef = PQgetvalue(res, j, i_condef); const char *conDef = PQgetvalue(res, j, i_condef);
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "ALTER TABLE ONLY %s ", appendPQExpBuffer(query, "ALTER TABLE ONLY %s\n",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
appendPQExpBuffer(query, "ADD CONSTRAINT %s %s;\n", appendPQExpBuffer(query, " ADD CONSTRAINT %s %s;\n",
fmtId(conName, force_quotes), fmtId(conName),
conDef); conDef);
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
resetPQExpBuffer(delqry); resetPQExpBuffer(delqry);
appendPQExpBuffer(delqry, "ALTER TABLE ONLY %s.", appendPQExpBuffer(delqry, "ALTER TABLE ONLY %s.",
fmtId(tbinfo->relnamespace->nspname, force_quotes)); fmtId(tbinfo->relnamespace->nspname));
appendPQExpBuffer(delqry, "%s ", appendPQExpBuffer(delqry, "%s ",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
appendPQExpBuffer(delqry, "DROP CONSTRAINT %s;\n", appendPQExpBuffer(delqry, "DROP CONSTRAINT %s;\n",
fmtId(conName, force_quotes)); fmtId(conName));
ArchiveEntry(fout, conOid, ArchiveEntry(fout, conOid,
conName, conName,
...@@ -5912,9 +5870,9 @@ dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -5912,9 +5870,9 @@ dumpConstraints(Archive *fout, TableInfo *tblinfo, int numTables)
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "CONSTRAINT %s ", appendPQExpBuffer(query, "CONSTRAINT %s ",
fmtId(conName, force_quotes)); fmtId(conName));
appendPQExpBuffer(query, "ON %s", appendPQExpBuffer(query, "ON %s",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
dumpComment(fout, query->data, dumpComment(fout, query->data,
tbinfo->relnamespace->nspname, tbinfo->usename, tbinfo->relnamespace->nspname, tbinfo->usename,
...@@ -6061,24 +6019,24 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -6061,24 +6019,24 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables)
resetPQExpBuffer(delqry); resetPQExpBuffer(delqry);
/* DROP must be fully qualified in case same name appears in pg_catalog */ /* DROP must be fully qualified in case same name appears in pg_catalog */
appendPQExpBuffer(delqry, "DROP TRIGGER %s ", appendPQExpBuffer(delqry, "DROP TRIGGER %s ",
fmtId(tgname, force_quotes)); fmtId(tgname));
appendPQExpBuffer(delqry, "ON %s.", appendPQExpBuffer(delqry, "ON %s.",
fmtId(tbinfo->relnamespace->nspname, force_quotes)); fmtId(tbinfo->relnamespace->nspname));
appendPQExpBuffer(delqry, "%s;\n", appendPQExpBuffer(delqry, "%s;\n",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
resetPQExpBuffer(query); resetPQExpBuffer(query);
if (tgisconstraint) if (tgisconstraint)
{ {
appendPQExpBuffer(query, "CREATE CONSTRAINT TRIGGER "); appendPQExpBuffer(query, "CREATE CONSTRAINT TRIGGER ");
appendPQExpBuffer(query, fmtId(PQgetvalue(res, j, i_tgconstrname), force_quotes)); appendPQExpBuffer(query, fmtId(PQgetvalue(res, j, i_tgconstrname)));
} }
else else
{ {
appendPQExpBuffer(query, "CREATE TRIGGER "); appendPQExpBuffer(query, "CREATE TRIGGER ");
appendPQExpBuffer(query, fmtId(tgname, force_quotes)); appendPQExpBuffer(query, fmtId(tgname));
} }
appendPQExpBufferChar(query, ' '); appendPQExpBuffer(query, "\n ");
/* Trigger type */ /* Trigger type */
findx = 0; findx = 0;
if (TRIGGER_FOR_BEFORE(tgtype)) if (TRIGGER_FOR_BEFORE(tgtype))
...@@ -6105,8 +6063,8 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -6105,8 +6063,8 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables)
else else
appendPQExpBuffer(query, " UPDATE"); appendPQExpBuffer(query, " UPDATE");
} }
appendPQExpBuffer(query, " ON %s ", appendPQExpBuffer(query, " ON %s\n",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
if (tgisconstraint) if (tgisconstraint)
{ {
...@@ -6124,30 +6082,30 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -6124,30 +6082,30 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables)
/* If we are using regclass, name is already quoted */ /* If we are using regclass, name is already quoted */
if (g_fout->remoteVersion >= 70300) if (g_fout->remoteVersion >= 70300)
appendPQExpBuffer(query, " FROM %s", appendPQExpBuffer(query, " FROM %s\n ",
PQgetvalue(res, j, i_tgconstrrelname)); PQgetvalue(res, j, i_tgconstrrelname));
else else
appendPQExpBuffer(query, " FROM %s", appendPQExpBuffer(query, " FROM %s\n ",
fmtId(PQgetvalue(res, j, i_tgconstrrelname), force_quotes)); fmtId(PQgetvalue(res, j, i_tgconstrrelname)));
} }
if (!tgdeferrable) if (!tgdeferrable)
appendPQExpBuffer(query, " NOT"); appendPQExpBuffer(query, "NOT ");
appendPQExpBuffer(query, " DEFERRABLE INITIALLY "); appendPQExpBuffer(query, "DEFERRABLE INITIALLY ");
if (tginitdeferred) if (tginitdeferred)
appendPQExpBuffer(query, "DEFERRED"); appendPQExpBuffer(query, "DEFERRED\n");
else else
appendPQExpBuffer(query, "IMMEDIATE"); appendPQExpBuffer(query, "IMMEDIATE\n");
} }
appendPQExpBuffer(query, " FOR EACH ROW"); appendPQExpBuffer(query, " FOR EACH ROW\n ");
/* In 7.3, result of regproc is already quoted */ /* In 7.3, result of regproc is already quoted */
if (g_fout->remoteVersion >= 70300) if (g_fout->remoteVersion >= 70300)
appendPQExpBuffer(query, " EXECUTE PROCEDURE %s (", appendPQExpBuffer(query, "EXECUTE PROCEDURE %s (",
tgfname); tgfname);
else else
appendPQExpBuffer(query, " EXECUTE PROCEDURE %s (", appendPQExpBuffer(query, "EXECUTE PROCEDURE %s (",
fmtId(tgfname, force_quotes)); fmtId(tgfname));
for (findx = 0; findx < tgnargs; findx++) for (findx = 0; findx < tgnargs; findx++)
{ {
const char *s; const char *s;
...@@ -6196,9 +6154,9 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -6196,9 +6154,9 @@ dumpTriggers(Archive *fout, TableInfo *tblinfo, int numTables)
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "TRIGGER %s ", appendPQExpBuffer(query, "TRIGGER %s ",
fmtId(tgname, force_quotes)); fmtId(tgname));
appendPQExpBuffer(query, "ON %s", appendPQExpBuffer(query, "ON %s",
fmtId(tbinfo->relname, force_quotes)); fmtId(tbinfo->relname));
dumpComment(fout, query->data, dumpComment(fout, query->data,
tbinfo->relnamespace->nspname, tbinfo->usename, tbinfo->relnamespace->nspname, tbinfo->usename,
...@@ -6221,6 +6179,7 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -6221,6 +6179,7 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables)
int i, int i,
t; t;
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer();
PQExpBuffer cmd = createPQExpBuffer();
int i_definition; int i_definition;
int i_oid; int i_oid;
int i_rulename; int i_rulename;
...@@ -6267,7 +6226,7 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -6267,7 +6226,7 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables)
" pg_rewrite.oid, pg_rewrite.rulename " " pg_rewrite.oid, pg_rewrite.rulename "
"FROM pg_rewrite, pg_class, pg_rules " "FROM pg_rewrite, pg_class, pg_rules "
"WHERE pg_class.relname = "); "WHERE pg_class.relname = ");
formatStringLiteral(query, tbinfo->relname, CONV_ALL); appendStringLiteral(query, tbinfo->relname, true);
appendPQExpBuffer(query, appendPQExpBuffer(query,
" AND pg_rewrite.ev_class = pg_class.oid " " AND pg_rewrite.ev_class = pg_class.oid "
" AND pg_rules.tablename = pg_class.relname " " AND pg_rules.tablename = pg_class.relname "
...@@ -6295,20 +6254,21 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -6295,20 +6254,21 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables)
for (i = 0; i < nrules; i++) for (i = 0; i < nrules; i++)
{ {
printfPQExpBuffer(cmd, "%s\n", PQgetvalue(res, i, i_definition));
ArchiveEntry(fout, PQgetvalue(res, i, i_oid), ArchiveEntry(fout, PQgetvalue(res, i, i_oid),
PQgetvalue(res, i, i_rulename), PQgetvalue(res, i, i_rulename),
tbinfo->relnamespace->nspname, tbinfo->relnamespace->nspname,
tbinfo->usename, tbinfo->usename,
"RULE", NULL, "RULE", NULL,
PQgetvalue(res, i, i_definition), cmd->data,
"", /* Del */ "", /* Del */
NULL, NULL, NULL); NULL, NULL, NULL);
/* Dump rule comments */ /* Dump rule comments */
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "RULE %s", fmtId(PQgetvalue(res, i, i_rulename), force_quotes)); appendPQExpBuffer(query, "RULE %s", fmtId(PQgetvalue(res, i, i_rulename)));
appendPQExpBuffer(query, " ON %s", fmtId(tbinfo->relname, force_quotes)); appendPQExpBuffer(query, " ON %s", fmtId(tbinfo->relname));
dumpComment(fout, query->data, dumpComment(fout, query->data,
tbinfo->relnamespace->nspname, tbinfo->relnamespace->nspname,
tbinfo->usename, tbinfo->usename,
...@@ -6320,6 +6280,7 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables) ...@@ -6320,6 +6280,7 @@ dumpRules(Archive *fout, TableInfo *tblinfo, int numTables)
} }
destroyPQExpBuffer(query); destroyPQExpBuffer(query);
destroyPQExpBuffer(cmd);
} }
/* /*
...@@ -6353,7 +6314,7 @@ selectSourceSchema(const char *schemaName) ...@@ -6353,7 +6314,7 @@ selectSourceSchema(const char *schemaName)
query = createPQExpBuffer(); query = createPQExpBuffer();
appendPQExpBuffer(query, "SET search_path = %s", appendPQExpBuffer(query, "SET search_path = %s",
fmtId(schemaName, force_quotes)); fmtId(schemaName));
if (strcmp(schemaName, "pg_catalog") != 0) if (strcmp(schemaName, "pg_catalog") != 0)
appendPQExpBuffer(query, ", pg_catalog"); appendPQExpBuffer(query, ", pg_catalog");
res = PQexec(g_conn, query->data); res = PQexec(g_conn, query->data);
...@@ -6444,7 +6405,7 @@ getFormattedTypeName(const char *oid, OidOptions opts) ...@@ -6444,7 +6405,7 @@ getFormattedTypeName(const char *oid, OidOptions opts)
else else
{ {
/* may need to quote it */ /* may need to quote it */
result = strdup(fmtId(PQgetvalue(res, 0, 0), false)); result = strdup(fmtId(PQgetvalue(res, 0, 0)));
} }
PQclear(res); PQclear(res);
...@@ -6499,14 +6460,10 @@ myFormatType(const char *typname, int32 typmod) ...@@ -6499,14 +6460,10 @@ myFormatType(const char *typname, int32 typmod)
* char is an internal single-byte data type; Let's make sure we force * char is an internal single-byte data type; Let's make sure we force
* it through with quotes. - thomas 1998-12-13 * it through with quotes. - thomas 1998-12-13
*/ */
else if (!strcmp(typname, "char")) else if (strcmp(typname, "char")==0)
{ appendPQExpBuffer(buf, "\"char\"");
appendPQExpBuffer(buf, "%s", fmtId(typname, true));
}
else else
{ appendPQExpBuffer(buf, "%s", fmtId(typname));
appendPQExpBuffer(buf, "%s", fmtId(typname, false));
}
result = strdup(buf->data); result = strdup(buf->data);
destroyPQExpBuffer(buf); destroyPQExpBuffer(buf);
...@@ -6534,10 +6491,10 @@ fmtQualifiedId(const char *schema, const char *id) ...@@ -6534,10 +6491,10 @@ fmtQualifiedId(const char *schema, const char *id)
if (g_fout->remoteVersion >= 70300 && schema && *schema) if (g_fout->remoteVersion >= 70300 && schema && *schema)
{ {
appendPQExpBuffer(id_return, "%s.", appendPQExpBuffer(id_return, "%s.",
fmtId(schema, force_quotes)); fmtId(schema));
} }
appendPQExpBuffer(id_return, "%s", appendPQExpBuffer(id_return, "%s",
fmtId(id, force_quotes)); fmtId(id));
return id_return->data; return id_return->data;
} }
...@@ -6574,8 +6531,8 @@ fmtCopyColumnList(const TableInfo* ti) ...@@ -6574,8 +6531,8 @@ fmtCopyColumnList(const TableInfo* ti)
if (attisdropped[i]) if (attisdropped[i])
continue; continue;
if (needComma) if (needComma)
appendPQExpBuffer(q, ","); appendPQExpBuffer(q, ", ");
appendPQExpBuffer(q, "%s", fmtId(attnames[i], force_quotes)); appendPQExpBuffer(q, "%s", fmtId(attnames[i]));
needComma = true; needComma = true;
} }
appendPQExpBuffer(q, ")"); appendPQExpBuffer(q, ")");
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: pg_dump.h,v 1.95 2002/08/15 16:36:06 momjian Exp $ * $Id: pg_dump.h,v 1.96 2002/08/18 09:36:26 petere Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#define PG_DUMP_H #define PG_DUMP_H
#include "pg_backup.h" #include "pg_backup.h"
#include "pqexpbuffer.h"
/* /*
* The data structures used to store system catalog information * The data structures used to store system catalog information
......
...@@ -1314,7 +1314,7 @@ SELECT tablename, rulename, definition FROM pg_rules ...@@ -1314,7 +1314,7 @@ SELECT tablename, rulename, definition FROM pg_rules
tablename | rulename | definition tablename | rulename | definition
---------------+-----------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ---------------+-----------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
pg_settings | pg_settings_n | CREATE RULE pg_settings_n AS ON UPDATE TO pg_settings DO INSTEAD NOTHING; pg_settings | pg_settings_n | CREATE RULE pg_settings_n AS ON UPDATE TO pg_settings DO INSTEAD NOTHING;
pg_settings | pg_settings_u | CREATE RULE pg_settings_u AS ON UPDATE TO pg_settings WHERE (new.name = old.name) DO SELECT set_config(old.name, new.setting, 'f'::boolean) AS set_config; pg_settings | pg_settings_u | CREATE RULE pg_settings_u AS ON UPDATE TO pg_settings WHERE (new.name = old.name) DO SELECT set_config(old.name, new.setting, false) AS set_config;
rtest_emp | rtest_emp_del | CREATE RULE rtest_emp_del AS ON DELETE TO rtest_emp DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (old.ename, "current_user"(), 'fired '::bpchar, '$0.00'::money, old.salary); rtest_emp | rtest_emp_del | CREATE RULE rtest_emp_del AS ON DELETE TO rtest_emp DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (old.ename, "current_user"(), 'fired '::bpchar, '$0.00'::money, old.salary);
rtest_emp | rtest_emp_ins | CREATE RULE rtest_emp_ins AS ON INSERT TO rtest_emp DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (new.ename, "current_user"(), 'hired '::bpchar, new.salary, '$0.00'::money); rtest_emp | rtest_emp_ins | CREATE RULE rtest_emp_ins AS ON INSERT TO rtest_emp DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (new.ename, "current_user"(), 'hired '::bpchar, new.salary, '$0.00'::money);
rtest_emp | rtest_emp_upd | CREATE RULE rtest_emp_upd AS ON UPDATE TO rtest_emp WHERE (new.salary <> old.salary) DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (new.ename, "current_user"(), 'honored '::bpchar, new.salary, old.salary); rtest_emp | rtest_emp_upd | CREATE RULE rtest_emp_upd AS ON UPDATE TO rtest_emp WHERE (new.salary <> old.salary) DO INSERT INTO rtest_emplog (ename, who, "action", newsal, oldsal) VALUES (new.ename, "current_user"(), 'honored '::bpchar, new.salary, old.salary);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment