Commit 32ceba3e authored by Heikki Linnakangas's avatar Heikki Linnakangas

Replace appendPQExpBuffer(..., <constant>) with appendPQExpBufferStr

Arguably makes the code a bit more readable, and might give a small
performance gain.

David Rowley
parent f1df4731
...@@ -168,11 +168,11 @@ fmtQualifiedId(int remoteVersion, const char *schema, const char *id) ...@@ -168,11 +168,11 @@ fmtQualifiedId(int remoteVersion, const char *schema, const char *id)
{ {
appendPQExpBuffer(lcl_pqexp, "%s.", fmtId(schema)); appendPQExpBuffer(lcl_pqexp, "%s.", fmtId(schema));
} }
appendPQExpBuffer(lcl_pqexp, "%s", fmtId(id)); appendPQExpBufferStr(lcl_pqexp, fmtId(id));
id_return = getLocalPQExpBuffer(); id_return = getLocalPQExpBuffer();
appendPQExpBuffer(id_return, "%s", lcl_pqexp->data); appendPQExpBufferStr(id_return, lcl_pqexp->data);
destroyPQExpBuffer(lcl_pqexp); destroyPQExpBuffer(lcl_pqexp);
return id_return->data; return id_return->data;
...@@ -625,7 +625,7 @@ buildACLCommands(const char *name, const char *subname, ...@@ -625,7 +625,7 @@ buildACLCommands(const char *name, const char *subname,
appendPQExpBuffer(secondsql, "%sGRANT %s ON %s %s TO ", appendPQExpBuffer(secondsql, "%sGRANT %s ON %s %s TO ",
prefix, privs->data, type, name); prefix, privs->data, type, name);
if (grantee->len == 0) if (grantee->len == 0)
appendPQExpBuffer(secondsql, "PUBLIC;\n"); appendPQExpBufferStr(secondsql, "PUBLIC;\n");
else if (strncmp(grantee->data, "group ", else if (strncmp(grantee->data, "group ",
strlen("group ")) == 0) strlen("group ")) == 0)
appendPQExpBuffer(secondsql, "GROUP %s;\n", appendPQExpBuffer(secondsql, "GROUP %s;\n",
...@@ -638,19 +638,19 @@ buildACLCommands(const char *name, const char *subname, ...@@ -638,19 +638,19 @@ buildACLCommands(const char *name, const char *subname,
appendPQExpBuffer(secondsql, "%sGRANT %s ON %s %s TO ", appendPQExpBuffer(secondsql, "%sGRANT %s ON %s %s TO ",
prefix, privswgo->data, type, name); prefix, privswgo->data, type, name);
if (grantee->len == 0) if (grantee->len == 0)
appendPQExpBuffer(secondsql, "PUBLIC"); appendPQExpBufferStr(secondsql, "PUBLIC");
else if (strncmp(grantee->data, "group ", else if (strncmp(grantee->data, "group ",
strlen("group ")) == 0) strlen("group ")) == 0)
appendPQExpBuffer(secondsql, "GROUP %s", appendPQExpBuffer(secondsql, "GROUP %s",
fmtId(grantee->data + strlen("group "))); fmtId(grantee->data + strlen("group ")));
else else
appendPQExpBuffer(secondsql, "%s", fmtId(grantee->data)); appendPQExpBufferStr(secondsql, fmtId(grantee->data));
appendPQExpBuffer(secondsql, " WITH GRANT OPTION;\n"); appendPQExpBufferStr(secondsql, " WITH GRANT OPTION;\n");
} }
if (grantor->len > 0 if (grantor->len > 0
&& (!owner || strcmp(owner, grantor->data) != 0)) && (!owner || strcmp(owner, grantor->data) != 0))
appendPQExpBuffer(secondsql, "RESET SESSION AUTHORIZATION;\n"); appendPQExpBufferStr(secondsql, "RESET SESSION AUTHORIZATION;\n");
} }
} }
} }
...@@ -947,7 +947,7 @@ AddAcl(PQExpBuffer aclbuf, const char *keyword, const char *subname) ...@@ -947,7 +947,7 @@ AddAcl(PQExpBuffer aclbuf, const char *keyword, const char *subname)
{ {
if (aclbuf->len > 0) if (aclbuf->len > 0)
appendPQExpBufferChar(aclbuf, ','); appendPQExpBufferChar(aclbuf, ',');
appendPQExpBuffer(aclbuf, "%s", keyword); appendPQExpBufferStr(aclbuf, keyword);
if (subname) if (subname)
appendPQExpBuffer(aclbuf, "(%s)", subname); appendPQExpBuffer(aclbuf, "(%s)", subname);
} }
...@@ -1205,7 +1205,7 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer, ...@@ -1205,7 +1205,7 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
" %s IS ", " %s IS ",
fmtId(objname)); fmtId(objname));
appendStringLiteralConn(buffer, label, conn); appendStringLiteralConn(buffer, label, conn);
appendPQExpBuffer(buffer, ";\n"); appendPQExpBufferStr(buffer, ";\n");
} }
} }
......
...@@ -2619,7 +2619,7 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user) ...@@ -2619,7 +2619,7 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user)
{ {
PQExpBuffer cmd = createPQExpBuffer(); PQExpBuffer cmd = createPQExpBuffer();
appendPQExpBuffer(cmd, "SET SESSION AUTHORIZATION "); appendPQExpBufferStr(cmd, "SET SESSION AUTHORIZATION ");
/* /*
* SQL requires a string literal here. Might as well be correct. * SQL requires a string literal here. Might as well be correct.
...@@ -2627,8 +2627,8 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user) ...@@ -2627,8 +2627,8 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user)
if (user && *user) if (user && *user)
appendStringLiteralAHX(cmd, user, AH); appendStringLiteralAHX(cmd, user, AH);
else else
appendPQExpBuffer(cmd, "DEFAULT"); appendPQExpBufferStr(cmd, "DEFAULT");
appendPQExpBuffer(cmd, ";"); appendPQExpBufferChar(cmd, ';');
if (RestoringToDB(AH)) if (RestoringToDB(AH))
{ {
...@@ -2798,7 +2798,7 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName) ...@@ -2798,7 +2798,7 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
appendPQExpBuffer(qry, "SET search_path = %s", appendPQExpBuffer(qry, "SET search_path = %s",
fmtId(schemaName)); fmtId(schemaName));
if (strcmp(schemaName, "pg_catalog") != 0) if (strcmp(schemaName, "pg_catalog") != 0)
appendPQExpBuffer(qry, ", pg_catalog"); appendPQExpBufferStr(qry, ", pg_catalog");
if (RestoringToDB(AH)) if (RestoringToDB(AH))
{ {
...@@ -2853,7 +2853,7 @@ _selectTablespace(ArchiveHandle *AH, const char *tablespace) ...@@ -2853,7 +2853,7 @@ _selectTablespace(ArchiveHandle *AH, const char *tablespace)
if (strcmp(want, "") == 0) if (strcmp(want, "") == 0)
{ {
/* We want the tablespace to be the database's default */ /* We want the tablespace to be the database's default */
appendPQExpBuffer(qry, "SET default_tablespace = ''"); appendPQExpBufferStr(qry, "SET default_tablespace = ''");
} }
else else
{ {
...@@ -3119,7 +3119,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat ...@@ -3119,7 +3119,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
{ {
PQExpBuffer temp = createPQExpBuffer(); PQExpBuffer temp = createPQExpBuffer();
appendPQExpBuffer(temp, "ALTER "); appendPQExpBufferStr(temp, "ALTER ");
_getObjectDescription(temp, te, AH); _getObjectDescription(temp, te, AH);
appendPQExpBuffer(temp, " OWNER TO %s;", fmtId(te->owner)); appendPQExpBuffer(temp, " OWNER TO %s;", fmtId(te->owner));
ahprintf(AH, "%s\n\n", temp->data); ahprintf(AH, "%s\n\n", temp->data);
......
...@@ -1033,7 +1033,7 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role) ...@@ -1033,7 +1033,7 @@ setup_connection(Archive *AH, const char *dumpencoding, char *use_role)
{ {
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer();
appendPQExpBuffer(query, "SET TRANSACTION SNAPSHOT "); appendPQExpBufferStr(query, "SET TRANSACTION SNAPSHOT ");
appendStringLiteralConn(query, AH->sync_snapshot_id, conn); appendStringLiteralConn(query, AH->sync_snapshot_id, conn);
ExecuteSqlStatement(AH, query->data); ExecuteSqlStatement(AH, query->data);
destroyPQExpBuffer(query); destroyPQExpBuffer(query);
...@@ -1127,7 +1127,7 @@ expand_schema_name_patterns(Archive *fout, ...@@ -1127,7 +1127,7 @@ expand_schema_name_patterns(Archive *fout,
for (cell = patterns->head; cell; cell = cell->next) for (cell = patterns->head; cell; cell = cell->next)
{ {
if (cell != patterns->head) if (cell != patterns->head)
appendPQExpBuffer(query, "UNION ALL\n"); appendPQExpBufferStr(query, "UNION ALL\n");
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT oid FROM pg_catalog.pg_namespace n\n"); "SELECT oid FROM pg_catalog.pg_namespace n\n");
processSQLNamePattern(GetConnection(fout), query, cell->val, false, processSQLNamePattern(GetConnection(fout), query, cell->val, false,
...@@ -1171,7 +1171,7 @@ expand_table_name_patterns(Archive *fout, ...@@ -1171,7 +1171,7 @@ expand_table_name_patterns(Archive *fout,
for (cell = patterns->head; cell; cell = cell->next) for (cell = patterns->head; cell; cell = cell->next)
{ {
if (cell != patterns->head) if (cell != patterns->head)
appendPQExpBuffer(query, "UNION ALL\n"); appendPQExpBufferStr(query, "UNION ALL\n");
appendPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT c.oid" "SELECT c.oid"
"\nFROM pg_catalog.pg_class c" "\nFROM pg_catalog.pg_class c"
...@@ -1920,7 +1920,7 @@ buildMatViewRefreshDependencies(Archive *fout) ...@@ -1920,7 +1920,7 @@ buildMatViewRefreshDependencies(Archive *fout)
query = createPQExpBuffer(); query = createPQExpBuffer();
appendPQExpBuffer(query, "with recursive w as " appendPQExpBufferStr(query, "with recursive w as "
"( " "( "
"select d1.objid, d2.refobjid, c2.relkind as refrelkind " "select d1.objid, d2.refobjid, c2.relkind as refrelkind "
"from pg_depend d1 " "from pg_depend d1 "
...@@ -2260,33 +2260,33 @@ dumpDatabase(Archive *fout) ...@@ -2260,33 +2260,33 @@ dumpDatabase(Archive *fout)
fmtId(datname)); fmtId(datname));
if (strlen(encoding) > 0) if (strlen(encoding) > 0)
{ {
appendPQExpBuffer(creaQry, " ENCODING = "); appendPQExpBufferStr(creaQry, " ENCODING = ");
appendStringLiteralAH(creaQry, encoding, fout); appendStringLiteralAH(creaQry, encoding, fout);
} }
if (strlen(collate) > 0) if (strlen(collate) > 0)
{ {
appendPQExpBuffer(creaQry, " LC_COLLATE = "); appendPQExpBufferStr(creaQry, " LC_COLLATE = ");
appendStringLiteralAH(creaQry, collate, fout); appendStringLiteralAH(creaQry, collate, fout);
} }
if (strlen(ctype) > 0) if (strlen(ctype) > 0)
{ {
appendPQExpBuffer(creaQry, " LC_CTYPE = "); appendPQExpBufferStr(creaQry, " LC_CTYPE = ");
appendStringLiteralAH(creaQry, ctype, fout); appendStringLiteralAH(creaQry, ctype, fout);
} }
if (strlen(tablespace) > 0 && strcmp(tablespace, "pg_default") != 0) if (strlen(tablespace) > 0 && strcmp(tablespace, "pg_default") != 0)
appendPQExpBuffer(creaQry, " TABLESPACE = %s", appendPQExpBuffer(creaQry, " TABLESPACE = %s",
fmtId(tablespace)); fmtId(tablespace));
appendPQExpBuffer(creaQry, ";\n"); appendPQExpBufferStr(creaQry, ";\n");
if (binary_upgrade) if (binary_upgrade)
{ {
appendPQExpBuffer(creaQry, "\n-- For binary upgrade, set datfrozenxid.\n"); appendPQExpBufferStr(creaQry, "\n-- For binary upgrade, set datfrozenxid.\n");
appendPQExpBuffer(creaQry, "UPDATE pg_catalog.pg_database\n" appendPQExpBuffer(creaQry, "UPDATE pg_catalog.pg_database\n"
"SET datfrozenxid = '%u'\n" "SET datfrozenxid = '%u'\n"
"WHERE datname = ", "WHERE datname = ",
frozenxid); frozenxid);
appendStringLiteralAH(creaQry, datname, fout); appendStringLiteralAH(creaQry, datname, fout);
appendPQExpBuffer(creaQry, ";\n"); appendPQExpBufferStr(creaQry, ";\n");
} }
...@@ -2336,7 +2336,7 @@ dumpDatabase(Archive *fout) ...@@ -2336,7 +2336,7 @@ dumpDatabase(Archive *fout)
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid"); i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
appendPQExpBuffer(loOutQry, "\n-- For binary upgrade, set pg_largeobject.relfrozenxid\n"); appendPQExpBufferStr(loOutQry, "\n-- For binary upgrade, set pg_largeobject.relfrozenxid\n");
appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n" appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n"
"SET relfrozenxid = '%u'\n" "SET relfrozenxid = '%u'\n"
"WHERE oid = %u;\n", "WHERE oid = %u;\n",
...@@ -2368,7 +2368,7 @@ dumpDatabase(Archive *fout) ...@@ -2368,7 +2368,7 @@ dumpDatabase(Archive *fout)
i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid"); i_relfrozenxid = PQfnumber(lo_res, "relfrozenxid");
appendPQExpBuffer(loOutQry, "\n-- For binary upgrade, set pg_largeobject_metadata.relfrozenxid\n"); appendPQExpBufferStr(loOutQry, "\n-- For binary upgrade, set pg_largeobject_metadata.relfrozenxid\n");
appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n" appendPQExpBuffer(loOutQry, "UPDATE pg_catalog.pg_class\n"
"SET relfrozenxid = '%u'\n" "SET relfrozenxid = '%u'\n"
"WHERE oid = %u;\n", "WHERE oid = %u;\n",
...@@ -2407,7 +2407,7 @@ dumpDatabase(Archive *fout) ...@@ -2407,7 +2407,7 @@ dumpDatabase(Archive *fout)
*/ */
appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname)); appendPQExpBuffer(dbQry, "COMMENT ON DATABASE %s IS ", fmtId(datname));
appendStringLiteralAH(dbQry, comment, fout); appendStringLiteralAH(dbQry, comment, fout);
appendPQExpBuffer(dbQry, ";\n"); appendPQExpBufferStr(dbQry, ";\n");
ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL, ArchiveEntry(fout, dbCatId, createDumpId(), datname, NULL, NULL,
dba, false, "COMMENT", SECTION_NONE, dba, false, "COMMENT", SECTION_NONE,
...@@ -2460,9 +2460,9 @@ dumpEncoding(Archive *AH) ...@@ -2460,9 +2460,9 @@ dumpEncoding(Archive *AH)
if (g_verbose) if (g_verbose)
write_msg(NULL, "saving encoding = %s\n", encname); write_msg(NULL, "saving encoding = %s\n", encname);
appendPQExpBuffer(qry, "SET client_encoding = "); appendPQExpBufferStr(qry, "SET client_encoding = ");
appendStringLiteralAH(qry, encname, AH); appendStringLiteralAH(qry, encname, AH);
appendPQExpBuffer(qry, ";\n"); appendPQExpBufferStr(qry, ";\n");
ArchiveEntry(AH, nilCatalogId, createDumpId(), ArchiveEntry(AH, nilCatalogId, createDumpId(),
"ENCODING", NULL, NULL, "", "ENCODING", NULL, NULL, "",
...@@ -2530,11 +2530,11 @@ getBlobs(Archive *fout) ...@@ -2530,11 +2530,11 @@ getBlobs(Archive *fout)
" FROM pg_largeobject_metadata", " FROM pg_largeobject_metadata",
username_subquery); username_subquery);
else if (fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
appendPQExpBuffer(blobQry, appendPQExpBufferStr(blobQry,
"SELECT DISTINCT loid, NULL::oid, NULL::oid" "SELECT DISTINCT loid, NULL::oid, NULL::oid"
" FROM pg_largeobject"); " FROM pg_largeobject");
else else
appendPQExpBuffer(blobQry, appendPQExpBufferStr(blobQry,
"SELECT oid, NULL::oid, NULL::oid" "SELECT oid, NULL::oid, NULL::oid"
" FROM pg_class WHERE relkind = 'l'"); " FROM pg_class WHERE relkind = 'l'");
...@@ -2723,7 +2723,7 @@ binary_upgrade_set_type_oids_by_type_oid(Archive *fout, ...@@ -2723,7 +2723,7 @@ binary_upgrade_set_type_oids_by_type_oid(Archive *fout,
PGresult *upgrade_res; PGresult *upgrade_res;
Oid pg_type_array_oid; Oid pg_type_array_oid;
appendPQExpBuffer(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n"); appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type oid\n");
appendPQExpBuffer(upgrade_buffer, appendPQExpBuffer(upgrade_buffer,
"SELECT binary_upgrade.set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n", "SELECT binary_upgrade.set_next_pg_type_oid('%u'::pg_catalog.oid);\n\n",
pg_type_oid); pg_type_oid);
...@@ -2741,7 +2741,7 @@ binary_upgrade_set_type_oids_by_type_oid(Archive *fout, ...@@ -2741,7 +2741,7 @@ binary_upgrade_set_type_oids_by_type_oid(Archive *fout,
if (OidIsValid(pg_type_array_oid)) if (OidIsValid(pg_type_array_oid))
{ {
appendPQExpBuffer(upgrade_buffer, appendPQExpBufferStr(upgrade_buffer,
"\n-- For binary upgrade, must preserve pg_type array oid\n"); "\n-- For binary upgrade, must preserve pg_type array oid\n");
appendPQExpBuffer(upgrade_buffer, appendPQExpBuffer(upgrade_buffer,
"SELECT binary_upgrade.set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n", "SELECT binary_upgrade.set_next_array_pg_type_oid('%u'::pg_catalog.oid);\n\n",
...@@ -2784,7 +2784,7 @@ binary_upgrade_set_type_oids_by_rel_oid(Archive *fout, ...@@ -2784,7 +2784,7 @@ binary_upgrade_set_type_oids_by_rel_oid(Archive *fout,
Oid pg_type_toast_oid = atooid(PQgetvalue(upgrade_res, 0, Oid pg_type_toast_oid = atooid(PQgetvalue(upgrade_res, 0,
PQfnumber(upgrade_res, "trel"))); PQfnumber(upgrade_res, "trel")));
appendPQExpBuffer(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n"); appendPQExpBufferStr(upgrade_buffer, "\n-- For binary upgrade, must preserve pg_type toast oid\n");
appendPQExpBuffer(upgrade_buffer, appendPQExpBuffer(upgrade_buffer,
"SELECT binary_upgrade.set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n", "SELECT binary_upgrade.set_next_toast_pg_type_oid('%u'::pg_catalog.oid);\n\n",
pg_type_toast_oid); pg_type_toast_oid);
...@@ -2820,7 +2820,7 @@ binary_upgrade_set_pg_class_oids(Archive *fout, ...@@ -2820,7 +2820,7 @@ binary_upgrade_set_pg_class_oids(Archive *fout,
pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid"))); pg_class_reltoastrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "reltoastrelid")));
pg_index_indexrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "indexrelid"))); pg_index_indexrelid = atooid(PQgetvalue(upgrade_res, 0, PQfnumber(upgrade_res, "indexrelid")));
appendPQExpBuffer(upgrade_buffer, appendPQExpBufferStr(upgrade_buffer,
"\n-- For binary upgrade, must preserve pg_class oids\n"); "\n-- For binary upgrade, must preserve pg_class oids\n");
if (!is_index) if (!is_index)
...@@ -2855,7 +2855,7 @@ binary_upgrade_set_pg_class_oids(Archive *fout, ...@@ -2855,7 +2855,7 @@ binary_upgrade_set_pg_class_oids(Archive *fout,
"SELECT binary_upgrade.set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n", "SELECT binary_upgrade.set_next_index_pg_class_oid('%u'::pg_catalog.oid);\n",
pg_class_oid); pg_class_oid);
appendPQExpBuffer(upgrade_buffer, "\n"); appendPQExpBufferChar(upgrade_buffer, '\n');
PQclear(upgrade_res); PQclear(upgrade_res);
destroyPQExpBuffer(upgrade_query); destroyPQExpBuffer(upgrade_query);
...@@ -2892,7 +2892,7 @@ binary_upgrade_extension_member(PQExpBuffer upgrade_buffer, ...@@ -2892,7 +2892,7 @@ binary_upgrade_extension_member(PQExpBuffer upgrade_buffer,
if (extobj == NULL) if (extobj == NULL)
exit_horribly(NULL, "could not find parent extension for %s\n", objlabel); exit_horribly(NULL, "could not find parent extension for %s\n", objlabel);
appendPQExpBuffer(upgrade_buffer, appendPQExpBufferStr(upgrade_buffer,
"\n-- For binary upgrade, handle extension membership the hard way\n"); "\n-- For binary upgrade, handle extension membership the hard way\n");
appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s;\n", appendPQExpBuffer(upgrade_buffer, "ALTER EXTENSION %s ADD %s;\n",
fmtId(extobj->name), fmtId(extobj->name),
...@@ -3079,7 +3079,7 @@ getExtensions(Archive *fout, int *numExtensions) ...@@ -3079,7 +3079,7 @@ getExtensions(Archive *fout, int *numExtensions)
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT x.tableoid, x.oid, " appendPQExpBufferStr(query, "SELECT x.tableoid, x.oid, "
"x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition " "x.extname, n.nspname, x.extrelocatable, x.extversion, x.extconfig, x.extcondition "
"FROM pg_extension x " "FROM pg_extension x "
"JOIN pg_namespace n ON n.oid = x.extnamespace"); "JOIN pg_namespace n ON n.oid = x.extnamespace");
...@@ -3707,14 +3707,14 @@ getOpclasses(Archive *fout, int *numOpclasses) ...@@ -3707,14 +3707,14 @@ getOpclasses(Archive *fout, int *numOpclasses)
} }
else if (fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, opcname, " appendPQExpBufferStr(query, "SELECT tableoid, oid, opcname, "
"0::oid AS opcnamespace, " "0::oid AS opcnamespace, "
"''::name AS rolname " "''::name AS rolname "
"FROM pg_opclass"); "FROM pg_opclass");
} }
else else
{ {
appendPQExpBuffer(query, "SELECT " appendPQExpBufferStr(query, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_opclass') AS tableoid, " "(SELECT oid FROM pg_class WHERE relname = 'pg_opclass') AS tableoid, "
"oid, opcname, " "oid, opcname, "
"0::oid AS opcnamespace, " "0::oid AS opcnamespace, "
...@@ -3902,13 +3902,13 @@ getAggregates(Archive *fout, int *numAggs) ...@@ -3902,13 +3902,13 @@ getAggregates(Archive *fout, int *numAggs)
"WHERE nspname = 'pg_catalog')", "WHERE nspname = 'pg_catalog')",
username_subquery); username_subquery);
if (binary_upgrade && fout->remoteVersion >= 90100) if (binary_upgrade && fout->remoteVersion >= 90100)
appendPQExpBuffer(query, appendPQExpBufferStr(query,
" OR EXISTS(SELECT 1 FROM pg_depend WHERE " " OR EXISTS(SELECT 1 FROM pg_depend WHERE "
"classid = 'pg_proc'::regclass AND " "classid = 'pg_proc'::regclass AND "
"objid = p.oid AND " "objid = p.oid AND "
"refclassid = 'pg_extension'::regclass AND " "refclassid = 'pg_extension'::regclass AND "
"deptype = 'e')"); "deptype = 'e')");
appendPQExpBuffer(query, ")"); appendPQExpBufferChar(query, ')');
} }
else if (fout->remoteVersion >= 80200) else if (fout->remoteVersion >= 80200)
{ {
...@@ -4094,18 +4094,18 @@ getFuncs(Archive *fout, int *numFuncs) ...@@ -4094,18 +4094,18 @@ getFuncs(Archive *fout, int *numFuncs)
"WHERE nspname = 'pg_catalog')", "WHERE nspname = 'pg_catalog')",
username_subquery); username_subquery);
if (fout->remoteVersion >= 90200) if (fout->remoteVersion >= 90200)
appendPQExpBuffer(query, appendPQExpBufferStr(query,
"\n AND NOT EXISTS (SELECT 1 FROM pg_depend " "\n AND NOT EXISTS (SELECT 1 FROM pg_depend "
"WHERE classid = 'pg_proc'::regclass AND " "WHERE classid = 'pg_proc'::regclass AND "
"objid = p.oid AND deptype = 'i')"); "objid = p.oid AND deptype = 'i')");
if (binary_upgrade && fout->remoteVersion >= 90100) if (binary_upgrade && fout->remoteVersion >= 90100)
appendPQExpBuffer(query, appendPQExpBufferStr(query,
"\n OR EXISTS(SELECT 1 FROM pg_depend WHERE " "\n OR EXISTS(SELECT 1 FROM pg_depend WHERE "
"classid = 'pg_proc'::regclass AND " "classid = 'pg_proc'::regclass AND "
"objid = p.oid AND " "objid = p.oid AND "
"refclassid = 'pg_extension'::regclass AND " "refclassid = 'pg_extension'::regclass AND "
"deptype = 'e')"); "deptype = 'e')");
appendPQExpBuffer(query, ")"); appendPQExpBufferChar(query, ')');
} }
else if (fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
...@@ -4721,7 +4721,7 @@ getTables(Archive *fout, int *numTables) ...@@ -4721,7 +4721,7 @@ getTables(Archive *fout, int *numTables)
* applied to other things too. * applied to other things too.
*/ */
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "SET statement_timeout = "); appendPQExpBufferStr(query, "SET statement_timeout = ");
appendStringLiteralConn(query, lockWaitTimeout, GetConnection(fout)); appendStringLiteralConn(query, lockWaitTimeout, GetConnection(fout));
ExecuteSqlStatement(fout, query->data); ExecuteSqlStatement(fout, query->data);
} }
...@@ -4883,7 +4883,7 @@ getInherits(Archive *fout, int *numInherits) ...@@ -4883,7 +4883,7 @@ getInherits(Archive *fout, int *numInherits)
/* find all the inheritance information */ /* find all the inheritance information */
appendPQExpBuffer(query, "SELECT inhrelid, inhparent FROM pg_inherits"); appendPQExpBufferStr(query, "SELECT inhrelid, inhparent FROM pg_inherits");
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);
...@@ -5517,7 +5517,7 @@ getRules(Archive *fout, int *numRules) ...@@ -5517,7 +5517,7 @@ getRules(Archive *fout, int *numRules)
if (fout->remoteVersion >= 80300) if (fout->remoteVersion >= 80300)
{ {
appendPQExpBuffer(query, "SELECT " appendPQExpBufferStr(query, "SELECT "
"tableoid, oid, rulename, " "tableoid, oid, rulename, "
"ev_class AS ruletable, ev_type, is_instead, " "ev_class AS ruletable, ev_type, is_instead, "
"ev_enabled " "ev_enabled "
...@@ -5526,7 +5526,7 @@ getRules(Archive *fout, int *numRules) ...@@ -5526,7 +5526,7 @@ getRules(Archive *fout, int *numRules)
} }
else if (fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
appendPQExpBuffer(query, "SELECT " appendPQExpBufferStr(query, "SELECT "
"tableoid, oid, rulename, " "tableoid, oid, rulename, "
"ev_class AS ruletable, ev_type, is_instead, " "ev_class AS ruletable, ev_type, is_instead, "
"'O'::char AS ev_enabled " "'O'::char AS ev_enabled "
...@@ -5535,7 +5535,7 @@ getRules(Archive *fout, int *numRules) ...@@ -5535,7 +5535,7 @@ getRules(Archive *fout, int *numRules)
} }
else else
{ {
appendPQExpBuffer(query, "SELECT " appendPQExpBufferStr(query, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_rewrite') AS tableoid, " "(SELECT oid FROM pg_class WHERE relname = 'pg_rewrite') AS tableoid, "
"oid, rulename, " "oid, rulename, "
"ev_class AS ruletable, ev_type, is_instead, " "ev_class AS ruletable, ev_type, is_instead, "
...@@ -6010,13 +6010,13 @@ getProcLangs(Archive *fout, int *numProcLangs) ...@@ -6010,13 +6010,13 @@ getProcLangs(Archive *fout, int *numProcLangs)
else if (fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
/* No clear notion of an owner at all before 7.4 ... */ /* No clear notion of an owner at all before 7.4 ... */
appendPQExpBuffer(query, "SELECT tableoid, oid, * FROM pg_language " appendPQExpBufferStr(query, "SELECT tableoid, oid, * FROM pg_language "
"WHERE lanispl " "WHERE lanispl "
"ORDER BY oid"); "ORDER BY oid");
} }
else else
{ {
appendPQExpBuffer(query, "SELECT " appendPQExpBufferStr(query, "SELECT "
"(SELECT oid FROM pg_class WHERE relname = 'pg_language') AS tableoid, " "(SELECT oid FROM pg_class WHERE relname = 'pg_language') AS tableoid, "
"oid, * FROM pg_language " "oid, * FROM pg_language "
"WHERE lanispl " "WHERE lanispl "
...@@ -6118,21 +6118,21 @@ getCasts(Archive *fout, int *numCasts) ...@@ -6118,21 +6118,21 @@ getCasts(Archive *fout, int *numCasts)
if (fout->remoteVersion >= 80400) if (fout->remoteVersion >= 80400)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, " appendPQExpBufferStr(query, "SELECT tableoid, oid, "
"castsource, casttarget, castfunc, castcontext, " "castsource, casttarget, castfunc, castcontext, "
"castmethod " "castmethod "
"FROM pg_cast ORDER BY 3,4"); "FROM pg_cast ORDER BY 3,4");
} }
else if (fout->remoteVersion >= 70300) else if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, "SELECT tableoid, oid, " appendPQExpBufferStr(query, "SELECT tableoid, oid, "
"castsource, casttarget, castfunc, castcontext, " "castsource, casttarget, castfunc, castcontext, "
"CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod " "CASE WHEN castfunc = 0 THEN 'b' ELSE 'f' END AS castmethod "
"FROM pg_cast ORDER BY 3,4"); "FROM pg_cast ORDER BY 3,4");
} }
else else
{ {
appendPQExpBuffer(query, "SELECT 0 AS tableoid, p.oid, " appendPQExpBufferStr(query, "SELECT 0 AS tableoid, p.oid, "
"t1.oid AS castsource, t2.oid AS casttarget, " "t1.oid AS castsource, t2.oid AS casttarget, "
"p.oid AS castfunc, 'e' AS castcontext, " "p.oid AS castfunc, 'e' AS castcontext, "
"'f' AS castmethod " "'f' AS castmethod "
...@@ -6840,7 +6840,7 @@ getTSParsers(Archive *fout, int *numTSParsers) ...@@ -6840,7 +6840,7 @@ getTSParsers(Archive *fout, int *numTSParsers)
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT tableoid, oid, prsname, prsnamespace, " appendPQExpBufferStr(query, "SELECT tableoid, oid, prsname, prsnamespace, "
"prsstart::oid, prstoken::oid, " "prsstart::oid, prstoken::oid, "
"prsend::oid, prsheadline::oid, prslextype::oid " "prsend::oid, prsheadline::oid, prslextype::oid "
"FROM pg_ts_parser"); "FROM pg_ts_parser");
...@@ -7009,7 +7009,7 @@ getTSTemplates(Archive *fout, int *numTSTemplates) ...@@ -7009,7 +7009,7 @@ getTSTemplates(Archive *fout, int *numTSTemplates)
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog"); selectSourceSchema(fout, "pg_catalog");
appendPQExpBuffer(query, "SELECT tableoid, oid, tmplname, " appendPQExpBufferStr(query, "SELECT tableoid, oid, tmplname, "
"tmplnamespace, tmplinit::oid, tmpllexize::oid " "tmplnamespace, tmplinit::oid, tmpllexize::oid "
"FROM pg_ts_template"); "FROM pg_ts_template");
...@@ -7471,7 +7471,7 @@ dumpComment(Archive *fout, const char *target, ...@@ -7471,7 +7471,7 @@ dumpComment(Archive *fout, const char *target,
appendPQExpBuffer(query, "COMMENT ON %s IS ", target); appendPQExpBuffer(query, "COMMENT ON %s IS ", target);
appendStringLiteralAH(query, comments->descr, fout); appendStringLiteralAH(query, comments->descr, fout);
appendPQExpBuffer(query, ";\n"); appendPQExpBufferStr(query, ";\n");
/* /*
* We mark comments as SECTION_NONE because they really belong in the * We mark comments as SECTION_NONE because they really belong in the
...@@ -7535,7 +7535,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, ...@@ -7535,7 +7535,7 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
appendStringLiteralAH(query, descr, fout); appendStringLiteralAH(query, descr, fout);
appendPQExpBuffer(query, ";\n"); appendPQExpBufferStr(query, ";\n");
ArchiveEntry(fout, nilCatalogId, createDumpId(), ArchiveEntry(fout, nilCatalogId, createDumpId(),
target->data, target->data,
...@@ -7551,13 +7551,12 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo, ...@@ -7551,13 +7551,12 @@ dumpTableComment(Archive *fout, TableInfo *tbinfo,
resetPQExpBuffer(target); resetPQExpBuffer(target);
appendPQExpBuffer(target, "COLUMN %s.", appendPQExpBuffer(target, "COLUMN %s.",
fmtId(tbinfo->dobj.name)); fmtId(tbinfo->dobj.name));
appendPQExpBuffer(target, "%s", appendPQExpBufferStr(target, fmtId(tbinfo->attnames[objsubid - 1]));
fmtId(tbinfo->attnames[objsubid - 1]));
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
appendStringLiteralAH(query, descr, fout); appendStringLiteralAH(query, descr, fout);
appendPQExpBuffer(query, ";\n"); appendPQExpBufferStr(query, ";\n");
ArchiveEntry(fout, nilCatalogId, createDumpId(), ArchiveEntry(fout, nilCatalogId, createDumpId(),
target->data, target->data,
...@@ -7698,20 +7697,20 @@ collectComments(Archive *fout, CommentItem **items) ...@@ -7698,20 +7697,20 @@ collectComments(Archive *fout, CommentItem **items)
if (fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
{ {
appendPQExpBuffer(query, "SELECT description, classoid, objoid, objsubid " appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
"FROM pg_catalog.pg_description " "FROM pg_catalog.pg_description "
"ORDER BY classoid, objoid, objsubid"); "ORDER BY classoid, objoid, objsubid");
} }
else if (fout->remoteVersion >= 70200) else if (fout->remoteVersion >= 70200)
{ {
appendPQExpBuffer(query, "SELECT description, classoid, objoid, objsubid " appendPQExpBufferStr(query, "SELECT description, classoid, objoid, objsubid "
"FROM pg_description " "FROM pg_description "
"ORDER BY classoid, objoid, objsubid"); "ORDER BY classoid, objoid, objsubid");
} }
else else
{ {
/* Note: this will fail to find attribute comments in pre-7.2... */ /* Note: this will fail to find attribute comments in pre-7.2... */
appendPQExpBuffer(query, "SELECT description, 0 AS classoid, objoid, 0 AS objsubid " appendPQExpBufferStr(query, "SELECT description, 0 AS classoid, objoid, 0 AS objsubid "
"FROM pg_description " "FROM pg_description "
"ORDER BY objoid"); "ORDER BY objoid");
} }
...@@ -7976,7 +7975,7 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) ...@@ -7976,7 +7975,7 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
int i; int i;
int n; int n;
appendPQExpBuffer(q, "-- For binary upgrade, create an empty extension and insert objects into it\n"); appendPQExpBufferStr(q, "-- For binary upgrade, create an empty extension and insert objects into it\n");
/* /*
* We unconditionally create the extension, so we must drop it if it * We unconditionally create the extension, so we must drop it if it
...@@ -7987,15 +7986,15 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) ...@@ -7987,15 +7986,15 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
*/ */
appendPQExpBuffer(q, "DROP EXTENSION IF EXISTS %s;\n", qextname); appendPQExpBuffer(q, "DROP EXTENSION IF EXISTS %s;\n", qextname);
appendPQExpBuffer(q, appendPQExpBufferStr(q,
"SELECT binary_upgrade.create_empty_extension("); "SELECT binary_upgrade.create_empty_extension(");
appendStringLiteralAH(q, extinfo->dobj.name, fout); appendStringLiteralAH(q, extinfo->dobj.name, fout);
appendPQExpBuffer(q, ", "); appendPQExpBufferStr(q, ", ");
appendStringLiteralAH(q, extinfo->namespace, fout); appendStringLiteralAH(q, extinfo->namespace, fout);
appendPQExpBuffer(q, ", "); appendPQExpBufferStr(q, ", ");
appendPQExpBuffer(q, "%s, ", extinfo->relocatable ? "true" : "false"); appendPQExpBuffer(q, "%s, ", extinfo->relocatable ? "true" : "false");
appendStringLiteralAH(q, extinfo->extversion, fout); appendStringLiteralAH(q, extinfo->extversion, fout);
appendPQExpBuffer(q, ", "); appendPQExpBufferStr(q, ", ");
/* /*
* Note that we're pushing extconfig (an OID array) back into * Note that we're pushing extconfig (an OID array) back into
...@@ -8005,14 +8004,14 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) ...@@ -8005,14 +8004,14 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
if (strlen(extinfo->extconfig) > 2) if (strlen(extinfo->extconfig) > 2)
appendStringLiteralAH(q, extinfo->extconfig, fout); appendStringLiteralAH(q, extinfo->extconfig, fout);
else else
appendPQExpBuffer(q, "NULL"); appendPQExpBufferStr(q, "NULL");
appendPQExpBuffer(q, ", "); appendPQExpBufferStr(q, ", ");
if (strlen(extinfo->extcondition) > 2) if (strlen(extinfo->extcondition) > 2)
appendStringLiteralAH(q, extinfo->extcondition, fout); appendStringLiteralAH(q, extinfo->extcondition, fout);
else else
appendPQExpBuffer(q, "NULL"); appendPQExpBufferStr(q, "NULL");
appendPQExpBuffer(q, ", "); appendPQExpBufferStr(q, ", ");
appendPQExpBuffer(q, "ARRAY["); appendPQExpBufferStr(q, "ARRAY[");
n = 0; n = 0;
for (i = 0; i < extinfo->dobj.nDeps; i++) for (i = 0; i < extinfo->dobj.nDeps; i++)
{ {
...@@ -8022,12 +8021,12 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo) ...@@ -8022,12 +8021,12 @@ dumpExtension(Archive *fout, ExtensionInfo *extinfo)
if (extobj && extobj->objType == DO_EXTENSION) if (extobj && extobj->objType == DO_EXTENSION)
{ {
if (n++ > 0) if (n++ > 0)
appendPQExpBuffer(q, ","); appendPQExpBufferChar(q, ',');
appendStringLiteralAH(q, extobj->name, fout); appendStringLiteralAH(q, extobj->name, fout);
} }
} }
appendPQExpBuffer(q, "]::pg_catalog.text[]"); appendPQExpBufferStr(q, "]::pg_catalog.text[]");
appendPQExpBuffer(q, ");\n"); appendPQExpBufferStr(q, ");\n");
} }
appendPQExpBuffer(labelq, "EXTENSION %s", qextname); appendPQExpBuffer(labelq, "EXTENSION %s", qextname);
...@@ -8147,13 +8146,13 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -8147,13 +8146,13 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
{ {
label = PQgetvalue(res, i, PQfnumber(res, "enumlabel")); label = PQgetvalue(res, i, PQfnumber(res, "enumlabel"));
if (i > 0) if (i > 0)
appendPQExpBuffer(q, ","); appendPQExpBufferChar(q, ',');
appendPQExpBuffer(q, "\n "); appendPQExpBufferStr(q, "\n ");
appendStringLiteralAH(q, label, fout); appendStringLiteralAH(q, label, fout);
} }
} }
appendPQExpBuffer(q, "\n);\n"); appendPQExpBufferStr(q, "\n);\n");
if (binary_upgrade) if (binary_upgrade)
{ {
...@@ -8164,7 +8163,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -8164,7 +8163,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
label = PQgetvalue(res, i, PQfnumber(res, "enumlabel")); label = PQgetvalue(res, i, PQfnumber(res, "enumlabel"));
if (i == 0) if (i == 0)
appendPQExpBuffer(q, "\n-- For binary upgrade, must preserve pg_enum oids\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, must preserve pg_enum oids\n");
appendPQExpBuffer(q, appendPQExpBuffer(q,
"SELECT binary_upgrade.set_next_pg_enum_oid('%u'::pg_catalog.oid);\n", "SELECT binary_upgrade.set_next_pg_enum_oid('%u'::pg_catalog.oid);\n",
enum_oid); enum_oid);
...@@ -8173,7 +8172,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo) ...@@ -8173,7 +8172,7 @@ dumpEnumType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(q, "%s ADD VALUE ", appendPQExpBuffer(q, "%s ADD VALUE ",
qtypname); qtypname);
appendStringLiteralAH(q, label, fout); appendStringLiteralAH(q, label, fout);
appendPQExpBuffer(q, ";\n\n"); appendPQExpBufferStr(q, ";\n\n");
} }
} }
...@@ -8282,7 +8281,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8282,7 +8281,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
/* always schema-qualify, don't try to be smart */ /* always schema-qualify, don't try to be smart */
appendPQExpBuffer(q, ",\n subtype_opclass = %s.", appendPQExpBuffer(q, ",\n subtype_opclass = %s.",
fmtId(nspname)); fmtId(nspname));
appendPQExpBuffer(q, "%s", fmtId(opcname)); appendPQExpBufferStr(q, fmtId(opcname));
} }
collationOid = atooid(PQgetvalue(res, 0, PQfnumber(res, "collation"))); collationOid = atooid(PQgetvalue(res, 0, PQfnumber(res, "collation")));
...@@ -8295,8 +8294,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8295,8 +8294,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
/* always schema-qualify, don't try to be smart */ /* always schema-qualify, don't try to be smart */
appendPQExpBuffer(q, ",\n collation = %s.", appendPQExpBuffer(q, ",\n collation = %s.",
fmtId(coll->dobj.namespace->dobj.name)); fmtId(coll->dobj.namespace->dobj.name));
appendPQExpBuffer(q, "%s", appendPQExpBufferStr(q, fmtId(coll->dobj.name));
fmtId(coll->dobj.name));
} }
} }
...@@ -8308,7 +8306,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo) ...@@ -8308,7 +8306,7 @@ dumpRangeType(Archive *fout, TypeInfo *tyinfo)
if (strcmp(procname, "-") != 0) if (strcmp(procname, "-") != 0)
appendPQExpBuffer(q, ",\n subtype_diff = %s", procname); appendPQExpBuffer(q, ",\n subtype_diff = %s", procname);
appendPQExpBuffer(q, "\n);\n"); appendPQExpBufferStr(q, "\n);\n");
appendPQExpBuffer(labelq, "TYPE %s", qtypname); appendPQExpBuffer(labelq, "TYPE %s", qtypname);
...@@ -8640,11 +8638,11 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -8640,11 +8638,11 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
} }
if (strcmp(typcollatable, "t") == 0) if (strcmp(typcollatable, "t") == 0)
appendPQExpBuffer(q, ",\n COLLATABLE = true"); appendPQExpBufferStr(q, ",\n COLLATABLE = true");
if (typdefault != NULL) if (typdefault != NULL)
{ {
appendPQExpBuffer(q, ",\n DEFAULT = "); appendPQExpBufferStr(q, ",\n DEFAULT = ");
if (typdefault_is_literal) if (typdefault_is_literal)
appendStringLiteralAH(q, typdefault, fout); appendStringLiteralAH(q, typdefault, fout);
else else
...@@ -8664,41 +8662,41 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo) ...@@ -8664,41 +8662,41 @@ dumpBaseType(Archive *fout, TypeInfo *tyinfo)
if (strcmp(typcategory, "U") != 0) if (strcmp(typcategory, "U") != 0)
{ {
appendPQExpBuffer(q, ",\n CATEGORY = "); appendPQExpBufferStr(q, ",\n CATEGORY = ");
appendStringLiteralAH(q, typcategory, fout); appendStringLiteralAH(q, typcategory, fout);
} }
if (strcmp(typispreferred, "t") == 0) if (strcmp(typispreferred, "t") == 0)
appendPQExpBuffer(q, ",\n PREFERRED = true"); appendPQExpBufferStr(q, ",\n PREFERRED = true");
if (typdelim && strcmp(typdelim, ",") != 0) if (typdelim && strcmp(typdelim, ",") != 0)
{ {
appendPQExpBuffer(q, ",\n DELIMITER = "); appendPQExpBufferStr(q, ",\n DELIMITER = ");
appendStringLiteralAH(q, typdelim, fout); appendStringLiteralAH(q, typdelim, fout);
} }
if (strcmp(typalign, "c") == 0) if (strcmp(typalign, "c") == 0)
appendPQExpBuffer(q, ",\n ALIGNMENT = char"); appendPQExpBufferStr(q, ",\n ALIGNMENT = char");
else if (strcmp(typalign, "s") == 0) else if (strcmp(typalign, "s") == 0)
appendPQExpBuffer(q, ",\n ALIGNMENT = int2"); appendPQExpBufferStr(q, ",\n ALIGNMENT = int2");
else if (strcmp(typalign, "i") == 0) else if (strcmp(typalign, "i") == 0)
appendPQExpBuffer(q, ",\n ALIGNMENT = int4"); appendPQExpBufferStr(q, ",\n ALIGNMENT = int4");
else if (strcmp(typalign, "d") == 0) else if (strcmp(typalign, "d") == 0)
appendPQExpBuffer(q, ",\n ALIGNMENT = double"); appendPQExpBufferStr(q, ",\n ALIGNMENT = double");
if (strcmp(typstorage, "p") == 0) if (strcmp(typstorage, "p") == 0)
appendPQExpBuffer(q, ",\n STORAGE = plain"); appendPQExpBufferStr(q, ",\n STORAGE = plain");
else if (strcmp(typstorage, "e") == 0) else if (strcmp(typstorage, "e") == 0)
appendPQExpBuffer(q, ",\n STORAGE = external"); appendPQExpBufferStr(q, ",\n STORAGE = external");
else if (strcmp(typstorage, "x") == 0) else if (strcmp(typstorage, "x") == 0)
appendPQExpBuffer(q, ",\n STORAGE = extended"); appendPQExpBufferStr(q, ",\n STORAGE = extended");
else if (strcmp(typstorage, "m") == 0) else if (strcmp(typstorage, "m") == 0)
appendPQExpBuffer(q, ",\n STORAGE = main"); appendPQExpBufferStr(q, ",\n STORAGE = main");
if (strcmp(typbyval, "t") == 0) if (strcmp(typbyval, "t") == 0)
appendPQExpBuffer(q, ",\n PASSEDBYVALUE"); appendPQExpBufferStr(q, ",\n PASSEDBYVALUE");
appendPQExpBuffer(q, "\n);\n"); appendPQExpBufferStr(q, "\n);\n");
appendPQExpBuffer(labelq, "TYPE %s", qtypname); appendPQExpBuffer(labelq, "TYPE %s", qtypname);
...@@ -8822,17 +8820,16 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -8822,17 +8820,16 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
/* always schema-qualify, don't try to be smart */ /* always schema-qualify, don't try to be smart */
appendPQExpBuffer(q, " COLLATE %s.", appendPQExpBuffer(q, " COLLATE %s.",
fmtId(coll->dobj.namespace->dobj.name)); fmtId(coll->dobj.namespace->dobj.name));
appendPQExpBuffer(q, "%s", appendPQExpBufferStr(q, fmtId(coll->dobj.name));
fmtId(coll->dobj.name));
} }
} }
if (typnotnull[0] == 't') if (typnotnull[0] == 't')
appendPQExpBuffer(q, " NOT NULL"); appendPQExpBufferStr(q, " NOT NULL");
if (typdefault != NULL) if (typdefault != NULL)
{ {
appendPQExpBuffer(q, " DEFAULT "); appendPQExpBufferStr(q, " DEFAULT ");
if (typdefault_is_literal) if (typdefault_is_literal)
appendStringLiteralAH(q, typdefault, fout); appendStringLiteralAH(q, typdefault, fout);
else else
...@@ -8853,7 +8850,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo) ...@@ -8853,7 +8850,7 @@ dumpDomain(Archive *fout, TypeInfo *tyinfo)
fmtId(domcheck->dobj.name), domcheck->condef); fmtId(domcheck->dobj.name), domcheck->condef);
} }
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(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
...@@ -9016,8 +9013,8 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -9016,8 +9013,8 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
/* Format properly if not first attr */ /* Format properly if not first attr */
if (actual_atts++ > 0) if (actual_atts++ > 0)
appendPQExpBuffer(q, ","); appendPQExpBufferChar(q, ',');
appendPQExpBuffer(q, "\n\t"); appendPQExpBufferStr(q, "\n\t");
if (!attisdropped) if (!attisdropped)
{ {
...@@ -9034,8 +9031,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -9034,8 +9031,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
/* always schema-qualify, don't try to be smart */ /* always schema-qualify, don't try to be smart */
appendPQExpBuffer(q, " COLLATE %s.", appendPQExpBuffer(q, " COLLATE %s.",
fmtId(coll->dobj.namespace->dobj.name)); fmtId(coll->dobj.namespace->dobj.name));
appendPQExpBuffer(q, "%s", appendPQExpBufferStr(q, fmtId(coll->dobj.name));
fmtId(coll->dobj.name));
} }
} }
} }
...@@ -9050,16 +9046,16 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -9050,16 +9046,16 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
appendPQExpBuffer(q, "%s INTEGER /* dummy */", fmtId(attname)); appendPQExpBuffer(q, "%s INTEGER /* dummy */", fmtId(attname));
/* stash separately for insertion after the CREATE TYPE */ /* stash separately for insertion after the CREATE TYPE */
appendPQExpBuffer(dropped, appendPQExpBufferStr(dropped,
"\n-- For binary upgrade, recreate dropped column.\n"); "\n-- For binary upgrade, recreate dropped column.\n");
appendPQExpBuffer(dropped, "UPDATE pg_catalog.pg_attribute\n" appendPQExpBuffer(dropped, "UPDATE pg_catalog.pg_attribute\n"
"SET attlen = %s, " "SET attlen = %s, "
"attalign = '%s', attbyval = false\n" "attalign = '%s', attbyval = false\n"
"WHERE attname = ", attlen, attalign); "WHERE attname = ", attlen, attalign);
appendStringLiteralAH(dropped, attname, fout); appendStringLiteralAH(dropped, attname, fout);
appendPQExpBuffer(dropped, "\n AND attrelid = "); appendPQExpBufferStr(dropped, "\n AND attrelid = ");
appendStringLiteralAH(dropped, qtypname, fout); appendStringLiteralAH(dropped, qtypname, fout);
appendPQExpBuffer(dropped, "::pg_catalog.regclass;\n"); appendPQExpBufferStr(dropped, "::pg_catalog.regclass;\n");
appendPQExpBuffer(dropped, "ALTER TYPE %s ", appendPQExpBuffer(dropped, "ALTER TYPE %s ",
qtypname); qtypname);
...@@ -9067,7 +9063,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo) ...@@ -9067,7 +9063,7 @@ dumpCompositeType(Archive *fout, TypeInfo *tyinfo)
fmtId(attname)); fmtId(attname));
} }
} }
appendPQExpBuffer(q, "\n);\n"); appendPQExpBufferStr(q, "\n);\n");
appendPQExpBufferStr(q, dropped->data); appendPQExpBufferStr(q, dropped->data);
/* /*
...@@ -9200,13 +9196,12 @@ dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo) ...@@ -9200,13 +9196,12 @@ dumpCompositeTypeColComments(Archive *fout, TypeInfo *tyinfo)
resetPQExpBuffer(target); resetPQExpBuffer(target);
appendPQExpBuffer(target, "COLUMN %s.", appendPQExpBuffer(target, "COLUMN %s.",
fmtId(tyinfo->dobj.name)); fmtId(tyinfo->dobj.name));
appendPQExpBuffer(target, "%s", appendPQExpBufferStr(target, fmtId(attname));
fmtId(attname));
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data); appendPQExpBuffer(query, "COMMENT ON %s IS ", target->data);
appendStringLiteralAH(query, descr, fout); appendStringLiteralAH(query, descr, fout);
appendPQExpBuffer(query, ";\n"); appendPQExpBufferStr(query, ";\n");
ArchiveEntry(fout, nilCatalogId, createDumpId(), ArchiveEntry(fout, nilCatalogId, createDumpId(),
target->data, target->data,
...@@ -9396,23 +9391,21 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) ...@@ -9396,23 +9391,21 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
fmtId(funcInfo->dobj.name)); fmtId(funcInfo->dobj.name));
if (OidIsValid(plang->laninline)) if (OidIsValid(plang->laninline))
{ {
appendPQExpBuffer(defqry, " INLINE "); appendPQExpBufferStr(defqry, " INLINE ");
/* Cope with possibility that inline is in different schema */ /* Cope with possibility that inline is in different schema */
if (inlineInfo->dobj.namespace != funcInfo->dobj.namespace) if (inlineInfo->dobj.namespace != funcInfo->dobj.namespace)
appendPQExpBuffer(defqry, "%s.", appendPQExpBuffer(defqry, "%s.",
fmtId(inlineInfo->dobj.namespace->dobj.name)); fmtId(inlineInfo->dobj.namespace->dobj.name));
appendPQExpBuffer(defqry, "%s", appendPQExpBufferStr(defqry, fmtId(inlineInfo->dobj.name));
fmtId(inlineInfo->dobj.name));
} }
if (OidIsValid(plang->lanvalidator)) if (OidIsValid(plang->lanvalidator))
{ {
appendPQExpBuffer(defqry, " VALIDATOR "); appendPQExpBufferStr(defqry, " VALIDATOR ");
/* Cope with possibility that validator is in different schema */ /* Cope with possibility that validator is in different schema */
if (validatorInfo->dobj.namespace != funcInfo->dobj.namespace) if (validatorInfo->dobj.namespace != funcInfo->dobj.namespace)
appendPQExpBuffer(defqry, "%s.", appendPQExpBuffer(defqry, "%s.",
fmtId(validatorInfo->dobj.namespace->dobj.name)); fmtId(validatorInfo->dobj.namespace->dobj.name));
appendPQExpBuffer(defqry, "%s", appendPQExpBufferStr(defqry, fmtId(validatorInfo->dobj.name));
fmtId(validatorInfo->dobj.name));
} }
} }
else else
...@@ -9429,7 +9422,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang) ...@@ -9429,7 +9422,7 @@ dumpProcLang(Archive *fout, ProcLangInfo *plang)
appendPQExpBuffer(defqry, "CREATE OR REPLACE PROCEDURAL LANGUAGE %s", appendPQExpBuffer(defqry, "CREATE OR REPLACE PROCEDURAL LANGUAGE %s",
qlanname); qlanname);
} }
appendPQExpBuffer(defqry, ";\n"); appendPQExpBufferStr(defqry, ";\n");
appendPQExpBuffer(labelq, "LANGUAGE %s", qlanname); appendPQExpBuffer(labelq, "LANGUAGE %s", qlanname);
...@@ -9478,9 +9471,9 @@ format_function_arguments(FuncInfo *finfo, char *funcargs, bool is_agg) ...@@ -9478,9 +9471,9 @@ format_function_arguments(FuncInfo *finfo, char *funcargs, bool is_agg)
PQExpBufferData fn; PQExpBufferData fn;
initPQExpBuffer(&fn); initPQExpBuffer(&fn);
appendPQExpBuffer(&fn, "%s", fmtId(finfo->dobj.name)); appendPQExpBufferStr(&fn, fmtId(finfo->dobj.name));
if (is_agg && finfo->nargs == 0) if (is_agg && finfo->nargs == 0)
appendPQExpBuffer(&fn, "(*)"); appendPQExpBufferStr(&fn, "(*)");
else else
appendPQExpBuffer(&fn, "(%s)", funcargs); appendPQExpBuffer(&fn, "(%s)", funcargs);
return fn.data; return fn.data;
...@@ -9553,7 +9546,7 @@ format_function_arguments_old(Archive *fout, ...@@ -9553,7 +9546,7 @@ format_function_arguments_old(Archive *fout,
typname); typname);
free(typname); free(typname);
} }
appendPQExpBuffer(&fn, ")"); appendPQExpBufferChar(&fn, ')');
return fn.data; return fn.data;
} }
...@@ -9582,15 +9575,15 @@ format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes) ...@@ -9582,15 +9575,15 @@ format_function_signature(Archive *fout, FuncInfo *finfo, bool honor_quotes)
{ {
char *typname; char *typname;
if (j > 0)
appendPQExpBufferStr(&fn, ", ");
typname = getFormattedTypeName(fout, finfo->argtypes[j], typname = getFormattedTypeName(fout, finfo->argtypes[j],
zeroAsOpaque); zeroAsOpaque);
appendPQExpBufferStr(&fn, typname);
appendPQExpBuffer(&fn, "%s%s",
(j > 0) ? ", " : "",
typname);
free(typname); free(typname);
} }
appendPQExpBuffer(&fn, ")"); appendPQExpBufferChar(&fn, ')');
return fn.data; return fn.data;
} }
...@@ -9822,11 +9815,11 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9822,11 +9815,11 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
*/ */
if (probin[0] != '\0' && strcmp(probin, "-") != 0) if (probin[0] != '\0' && strcmp(probin, "-") != 0)
{ {
appendPQExpBuffer(asPart, "AS "); appendPQExpBufferStr(asPart, "AS ");
appendStringLiteralAH(asPart, probin, fout); appendStringLiteralAH(asPart, probin, fout);
if (strcmp(prosrc, "-") != 0) if (strcmp(prosrc, "-") != 0)
{ {
appendPQExpBuffer(asPart, ", "); appendPQExpBufferStr(asPart, ", ");
/* /*
* where we have bin, use dollar quoting if allowed and src * where we have bin, use dollar quoting if allowed and src
...@@ -9843,7 +9836,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9843,7 +9836,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
{ {
if (strcmp(prosrc, "-") != 0) if (strcmp(prosrc, "-") != 0)
{ {
appendPQExpBuffer(asPart, "AS "); appendPQExpBufferStr(asPart, "AS ");
/* with no bin, dollar quote src unconditionally if allowed */ /* with no bin, dollar quote src unconditionally if allowed */
if (disable_dollar_quoting) if (disable_dollar_quoting)
appendStringLiteralAH(asPart, prosrc, fout); appendStringLiteralAH(asPart, prosrc, fout);
...@@ -9950,27 +9943,27 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -9950,27 +9943,27 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
appendPQExpBuffer(q, "\n LANGUAGE %s", fmtId(lanname)); appendPQExpBuffer(q, "\n LANGUAGE %s", fmtId(lanname));
if (proiswindow[0] == 't') if (proiswindow[0] == 't')
appendPQExpBuffer(q, " WINDOW"); appendPQExpBufferStr(q, " WINDOW");
if (provolatile[0] != PROVOLATILE_VOLATILE) if (provolatile[0] != PROVOLATILE_VOLATILE)
{ {
if (provolatile[0] == PROVOLATILE_IMMUTABLE) if (provolatile[0] == PROVOLATILE_IMMUTABLE)
appendPQExpBuffer(q, " IMMUTABLE"); appendPQExpBufferStr(q, " IMMUTABLE");
else if (provolatile[0] == PROVOLATILE_STABLE) else if (provolatile[0] == PROVOLATILE_STABLE)
appendPQExpBuffer(q, " STABLE"); appendPQExpBufferStr(q, " STABLE");
else if (provolatile[0] != PROVOLATILE_VOLATILE) else if (provolatile[0] != PROVOLATILE_VOLATILE)
exit_horribly(NULL, "unrecognized provolatile value for function \"%s\"\n", exit_horribly(NULL, "unrecognized provolatile value for function \"%s\"\n",
finfo->dobj.name); finfo->dobj.name);
} }
if (proisstrict[0] == 't') if (proisstrict[0] == 't')
appendPQExpBuffer(q, " STRICT"); appendPQExpBufferStr(q, " STRICT");
if (prosecdef[0] == 't') if (prosecdef[0] == 't')
appendPQExpBuffer(q, " SECURITY DEFINER"); appendPQExpBufferStr(q, " SECURITY DEFINER");
if (proleakproof[0] == 't') if (proleakproof[0] == 't')
appendPQExpBuffer(q, " LEAKPROOF"); appendPQExpBufferStr(q, " LEAKPROOF");
/* /*
* COST and ROWS are emitted only if present and not default, so as not to * COST and ROWS are emitted only if present and not default, so as not to
...@@ -10014,7 +10007,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo) ...@@ -10014,7 +10007,7 @@ dumpFunc(Archive *fout, FuncInfo *finfo)
*/ */
if (pg_strcasecmp(configitem, "DateStyle") == 0 if (pg_strcasecmp(configitem, "DateStyle") == 0
|| pg_strcasecmp(configitem, "search_path") == 0) || pg_strcasecmp(configitem, "search_path") == 0)
appendPQExpBuffer(q, "%s", pos); appendPQExpBufferStr(q, pos);
else else
appendStringLiteralAH(q, pos, fout); appendStringLiteralAH(q, pos, fout);
} }
...@@ -10159,10 +10152,10 @@ dumpCast(Archive *fout, CastInfo *cast) ...@@ -10159,10 +10152,10 @@ dumpCast(Archive *fout, CastInfo *cast)
switch (cast->castmethod) switch (cast->castmethod)
{ {
case COERCION_METHOD_BINARY: case COERCION_METHOD_BINARY:
appendPQExpBuffer(defqry, "WITHOUT FUNCTION"); appendPQExpBufferStr(defqry, "WITHOUT FUNCTION");
break; break;
case COERCION_METHOD_INOUT: case COERCION_METHOD_INOUT:
appendPQExpBuffer(defqry, "WITH INOUT"); appendPQExpBufferStr(defqry, "WITH INOUT");
break; break;
case COERCION_METHOD_FUNCTION: case COERCION_METHOD_FUNCTION:
if (funcInfo) if (funcInfo)
...@@ -10186,10 +10179,10 @@ dumpCast(Archive *fout, CastInfo *cast) ...@@ -10186,10 +10179,10 @@ dumpCast(Archive *fout, CastInfo *cast)
} }
if (cast->castcontext == 'a') if (cast->castcontext == 'a')
appendPQExpBuffer(defqry, " AS ASSIGNMENT"); appendPQExpBufferStr(defqry, " AS ASSIGNMENT");
else if (cast->castcontext == 'i') else if (cast->castcontext == 'i')
appendPQExpBuffer(defqry, " AS IMPLICIT"); appendPQExpBufferStr(defqry, " AS IMPLICIT");
appendPQExpBuffer(defqry, ";\n"); appendPQExpBufferStr(defqry, ";\n");
appendPQExpBuffer(labelq, "CAST (%s AS %s)", appendPQExpBuffer(labelq, "CAST (%s AS %s)",
getFormattedTypeName(fout, cast->castsource, zeroAsNone), getFormattedTypeName(fout, cast->castsource, zeroAsNone),
...@@ -10375,10 +10368,10 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -10375,10 +10368,10 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
else else
name = fmtId(oprleft); name = fmtId(oprleft);
appendPQExpBuffer(details, ",\n LEFTARG = %s", name); appendPQExpBuffer(details, ",\n LEFTARG = %s", name);
appendPQExpBuffer(oprid, "%s", name); appendPQExpBufferStr(oprid, name);
} }
else else
appendPQExpBuffer(oprid, "NONE"); appendPQExpBufferStr(oprid, "NONE");
if (strcmp(oprkind, "l") == 0 || if (strcmp(oprkind, "l") == 0 ||
strcmp(oprkind, "b") == 0) strcmp(oprkind, "b") == 0)
...@@ -10391,7 +10384,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -10391,7 +10384,7 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
appendPQExpBuffer(oprid, ", %s)", name); appendPQExpBuffer(oprid, ", %s)", name);
} }
else else
appendPQExpBuffer(oprid, ", NONE)"); appendPQExpBufferStr(oprid, ", NONE)");
name = convertOperatorReference(fout, oprcom); name = convertOperatorReference(fout, oprcom);
if (name) if (name)
...@@ -10402,10 +10395,10 @@ dumpOpr(Archive *fout, OprInfo *oprinfo) ...@@ -10402,10 +10395,10 @@ dumpOpr(Archive *fout, OprInfo *oprinfo)
appendPQExpBuffer(details, ",\n NEGATOR = %s", name); appendPQExpBuffer(details, ",\n NEGATOR = %s", name);
if (strcmp(oprcanmerge, "t") == 0) if (strcmp(oprcanmerge, "t") == 0)
appendPQExpBuffer(details, ",\n MERGES"); appendPQExpBufferStr(details, ",\n MERGES");
if (strcmp(oprcanhash, "t") == 0) if (strcmp(oprcanhash, "t") == 0)
appendPQExpBuffer(details, ",\n HASHES"); appendPQExpBufferStr(details, ",\n HASHES");
name = convertRegProcReference(fout, oprrest); name = convertRegProcReference(fout, oprrest);
if (name) if (name)
...@@ -10714,7 +10707,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -10714,7 +10707,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
appendPQExpBuffer(q, "CREATE OPERATOR CLASS %s\n ", appendPQExpBuffer(q, "CREATE OPERATOR CLASS %s\n ",
fmtId(opcinfo->dobj.name)); fmtId(opcinfo->dobj.name));
if (strcmp(opcdefault, "t") == 0) if (strcmp(opcdefault, "t") == 0)
appendPQExpBuffer(q, "DEFAULT "); appendPQExpBufferStr(q, "DEFAULT ");
appendPQExpBuffer(q, "FOR TYPE %s USING %s", appendPQExpBuffer(q, "FOR TYPE %s USING %s",
opcintype, opcintype,
fmtId(amname)); fmtId(amname));
...@@ -10722,12 +10715,12 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -10722,12 +10715,12 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
(strcmp(opcfamilyname, opcinfo->dobj.name) != 0 || (strcmp(opcfamilyname, opcinfo->dobj.name) != 0 ||
strcmp(opcfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0)) strcmp(opcfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0))
{ {
appendPQExpBuffer(q, " FAMILY "); appendPQExpBufferStr(q, " FAMILY ");
if (strcmp(opcfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0) if (strcmp(opcfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0)
appendPQExpBuffer(q, "%s.", fmtId(opcfamilynsp)); appendPQExpBuffer(q, "%s.", fmtId(opcfamilynsp));
appendPQExpBuffer(q, "%s", fmtId(opcfamilyname)); appendPQExpBuffer(q, "%s", fmtId(opcfamilyname));
} }
appendPQExpBuffer(q, " AS\n "); appendPQExpBufferStr(q, " AS\n ");
needComma = false; needComma = false;
...@@ -10834,21 +10827,21 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -10834,21 +10827,21 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
sortfamilynsp = PQgetvalue(res, i, i_sortfamilynsp); sortfamilynsp = PQgetvalue(res, i, i_sortfamilynsp);
if (needComma) if (needComma)
appendPQExpBuffer(q, " ,\n "); appendPQExpBufferStr(q, " ,\n ");
appendPQExpBuffer(q, "OPERATOR %s %s", appendPQExpBuffer(q, "OPERATOR %s %s",
amopstrategy, amopopr); amopstrategy, amopopr);
if (strlen(sortfamily) > 0) if (strlen(sortfamily) > 0)
{ {
appendPQExpBuffer(q, " FOR ORDER BY "); appendPQExpBufferStr(q, " FOR ORDER BY ");
if (strcmp(sortfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0) if (strcmp(sortfamilynsp, opcinfo->dobj.namespace->dobj.name) != 0)
appendPQExpBuffer(q, "%s.", fmtId(sortfamilynsp)); appendPQExpBuffer(q, "%s.", fmtId(sortfamilynsp));
appendPQExpBuffer(q, "%s", fmtId(sortfamily)); appendPQExpBufferStr(q, fmtId(sortfamily));
} }
if (strcmp(amopreqcheck, "t") == 0) if (strcmp(amopreqcheck, "t") == 0)
appendPQExpBuffer(q, " RECHECK"); appendPQExpBufferStr(q, " RECHECK");
needComma = true; needComma = true;
} }
...@@ -10912,7 +10905,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -10912,7 +10905,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
amprocrighttype = PQgetvalue(res, i, i_amprocrighttype); amprocrighttype = PQgetvalue(res, i, i_amprocrighttype);
if (needComma) if (needComma)
appendPQExpBuffer(q, " ,\n "); appendPQExpBufferStr(q, " ,\n ");
appendPQExpBuffer(q, "FUNCTION %s", amprocnum); appendPQExpBuffer(q, "FUNCTION %s", amprocnum);
...@@ -10926,7 +10919,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo) ...@@ -10926,7 +10919,7 @@ dumpOpclass(Archive *fout, OpclassInfo *opcinfo)
PQclear(res); PQclear(res);
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(q, ";\n");
appendPQExpBuffer(labelq, "OPERATOR CLASS %s", appendPQExpBuffer(labelq, "OPERATOR CLASS %s",
fmtId(opcinfo->dobj.name)); fmtId(opcinfo->dobj.name));
...@@ -11192,21 +11185,21 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) ...@@ -11192,21 +11185,21 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
sortfamilynsp = PQgetvalue(res_ops, i, i_sortfamilynsp); sortfamilynsp = PQgetvalue(res_ops, i, i_sortfamilynsp);
if (needComma) if (needComma)
appendPQExpBuffer(q, " ,\n "); appendPQExpBufferStr(q, " ,\n ");
appendPQExpBuffer(q, "OPERATOR %s %s", appendPQExpBuffer(q, "OPERATOR %s %s",
amopstrategy, amopopr); amopstrategy, amopopr);
if (strlen(sortfamily) > 0) if (strlen(sortfamily) > 0)
{ {
appendPQExpBuffer(q, " FOR ORDER BY "); appendPQExpBufferStr(q, " FOR ORDER BY ");
if (strcmp(sortfamilynsp, opfinfo->dobj.namespace->dobj.name) != 0) if (strcmp(sortfamilynsp, opfinfo->dobj.namespace->dobj.name) != 0)
appendPQExpBuffer(q, "%s.", fmtId(sortfamilynsp)); appendPQExpBuffer(q, "%s.", fmtId(sortfamilynsp));
appendPQExpBuffer(q, "%s", fmtId(sortfamily)); appendPQExpBufferStr(q, fmtId(sortfamily));
} }
if (strcmp(amopreqcheck, "t") == 0) if (strcmp(amopreqcheck, "t") == 0)
appendPQExpBuffer(q, " RECHECK"); appendPQExpBufferStr(q, " RECHECK");
needComma = true; needComma = true;
} }
...@@ -11229,7 +11222,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) ...@@ -11229,7 +11222,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
amprocrighttype = PQgetvalue(res_procs, i, i_amprocrighttype); amprocrighttype = PQgetvalue(res_procs, i, i_amprocrighttype);
if (needComma) if (needComma)
appendPQExpBuffer(q, " ,\n "); appendPQExpBufferStr(q, " ,\n ");
appendPQExpBuffer(q, "FUNCTION %s (%s, %s) %s", appendPQExpBuffer(q, "FUNCTION %s (%s, %s) %s",
amprocnum, amproclefttype, amprocrighttype, amprocnum, amproclefttype, amprocrighttype,
...@@ -11238,7 +11231,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo) ...@@ -11238,7 +11231,7 @@ dumpOpfamily(Archive *fout, OpfamilyInfo *opfinfo)
needComma = true; needComma = true;
} }
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(q, ";\n");
} }
appendPQExpBuffer(labelq, "OPERATOR FAMILY %s", appendPQExpBuffer(labelq, "OPERATOR FAMILY %s",
...@@ -11329,9 +11322,9 @@ dumpCollation(Archive *fout, CollInfo *collinfo) ...@@ -11329,9 +11322,9 @@ dumpCollation(Archive *fout, CollInfo *collinfo)
appendPQExpBuffer(q, "CREATE COLLATION %s (lc_collate = ", appendPQExpBuffer(q, "CREATE COLLATION %s (lc_collate = ",
fmtId(collinfo->dobj.name)); fmtId(collinfo->dobj.name));
appendStringLiteralAH(q, collcollate, fout); appendStringLiteralAH(q, collcollate, fout);
appendPQExpBuffer(q, ", lc_ctype = "); appendPQExpBufferStr(q, ", lc_ctype = ");
appendStringLiteralAH(q, collctype, fout); appendStringLiteralAH(q, collctype, fout);
appendPQExpBuffer(q, ");\n"); appendPQExpBufferStr(q, ");\n");
appendPQExpBuffer(labelq, "COLLATION %s", fmtId(collinfo->dobj.name)); appendPQExpBuffer(labelq, "COLLATION %s", fmtId(collinfo->dobj.name));
...@@ -11427,7 +11420,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo) ...@@ -11427,7 +11420,7 @@ dumpConversion(Archive *fout, ConvInfo *convinfo)
(condefault) ? "DEFAULT " : "", (condefault) ? "DEFAULT " : "",
fmtId(convinfo->dobj.name)); fmtId(convinfo->dobj.name));
appendStringLiteralAH(q, conforencoding, fout); appendStringLiteralAH(q, conforencoding, fout);
appendPQExpBuffer(q, " TO "); appendPQExpBufferStr(q, " TO ");
appendStringLiteralAH(q, contoencoding, fout); appendStringLiteralAH(q, contoencoding, fout);
/* regproc is automatically quoted in 7.3 and above */ /* regproc is automatically quoted in 7.3 and above */
appendPQExpBuffer(q, " FROM %s;\n", conproc); appendPQExpBuffer(q, " FROM %s;\n", conproc);
...@@ -11474,16 +11467,15 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes) ...@@ -11474,16 +11467,15 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
if (honor_quotes) if (honor_quotes)
appendPQExpBuffer(&buf, "%s", appendPQExpBufferStr(&buf, fmtId(agginfo->aggfn.dobj.name));
fmtId(agginfo->aggfn.dobj.name));
else else
appendPQExpBuffer(&buf, "%s", agginfo->aggfn.dobj.name); appendPQExpBufferStr(&buf, agginfo->aggfn.dobj.name);
if (agginfo->aggfn.nargs == 0) if (agginfo->aggfn.nargs == 0)
appendPQExpBuffer(&buf, "(*)"); appendPQExpBuffer(&buf, "(*)");
else else
{ {
appendPQExpBuffer(&buf, "("); appendPQExpBufferChar(&buf, '(');
for (j = 0; j < agginfo->aggfn.nargs; j++) for (j = 0; j < agginfo->aggfn.nargs; j++)
{ {
char *typname; char *typname;
...@@ -11496,7 +11488,7 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes) ...@@ -11496,7 +11488,7 @@ format_aggregate_signature(AggInfo *agginfo, Archive *fout, bool honor_quotes)
typname); typname);
free(typname); free(typname);
} }
appendPQExpBuffer(&buf, ")"); appendPQExpBufferChar(&buf, ')');
} }
return buf.data; return buf.data;
} }
...@@ -11698,7 +11690,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo) ...@@ -11698,7 +11690,7 @@ dumpAgg(Archive *fout, AggInfo *agginfo)
if (!PQgetisnull(res, 0, i_agginitval)) if (!PQgetisnull(res, 0, i_agginitval))
{ {
appendPQExpBuffer(details, ",\n INITCOND = "); appendPQExpBufferStr(details, ",\n INITCOND = ");
appendStringLiteralAH(details, agginitval, fout); appendStringLiteralAH(details, agginitval, fout);
} }
...@@ -11888,10 +11880,10 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) ...@@ -11888,10 +11880,10 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
appendPQExpBuffer(q, "CREATE TEXT SEARCH DICTIONARY %s (\n", appendPQExpBuffer(q, "CREATE TEXT SEARCH DICTIONARY %s (\n",
fmtId(dictinfo->dobj.name)); fmtId(dictinfo->dobj.name));
appendPQExpBuffer(q, " TEMPLATE = "); appendPQExpBufferStr(q, " TEMPLATE = ");
if (strcmp(nspname, dictinfo->dobj.namespace->dobj.name) != 0) if (strcmp(nspname, dictinfo->dobj.namespace->dobj.name) != 0)
appendPQExpBuffer(q, "%s.", fmtId(nspname)); appendPQExpBuffer(q, "%s.", fmtId(nspname));
appendPQExpBuffer(q, "%s", fmtId(tmplname)); appendPQExpBufferStr(q, fmtId(tmplname));
PQclear(res); PQclear(res);
...@@ -11899,7 +11891,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo) ...@@ -11899,7 +11891,7 @@ dumpTSDictionary(Archive *fout, TSDictInfo *dictinfo)
if (dictinfo->dictinitoption) if (dictinfo->dictinitoption)
appendPQExpBuffer(q, ",\n %s", dictinfo->dictinitoption); appendPQExpBuffer(q, ",\n %s", dictinfo->dictinitoption);
appendPQExpBuffer(q, " );\n"); appendPQExpBufferStr(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
...@@ -12045,7 +12037,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) ...@@ -12045,7 +12037,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
appendPQExpBuffer(q, "CREATE TEXT SEARCH CONFIGURATION %s (\n", appendPQExpBuffer(q, "CREATE TEXT SEARCH CONFIGURATION %s (\n",
fmtId(cfginfo->dobj.name)); fmtId(cfginfo->dobj.name));
appendPQExpBuffer(q, " PARSER = "); appendPQExpBufferStr(q, " PARSER = ");
if (strcmp(nspname, cfginfo->dobj.namespace->dobj.name) != 0) if (strcmp(nspname, cfginfo->dobj.namespace->dobj.name) != 0)
appendPQExpBuffer(q, "%s.", fmtId(nspname)); appendPQExpBuffer(q, "%s.", fmtId(nspname));
appendPQExpBuffer(q, "%s );\n", fmtId(prsname)); appendPQExpBuffer(q, "%s );\n", fmtId(prsname));
...@@ -12079,7 +12071,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) ...@@ -12079,7 +12071,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
{ {
/* starting a new token type, so start a new command */ /* starting a new token type, so start a new command */
if (i > 0) if (i > 0)
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(q, ";\n");
appendPQExpBuffer(q, "\nALTER TEXT SEARCH CONFIGURATION %s\n", appendPQExpBuffer(q, "\nALTER TEXT SEARCH CONFIGURATION %s\n",
fmtId(cfginfo->dobj.name)); fmtId(cfginfo->dobj.name));
/* tokenname needs quoting, dictname does NOT */ /* tokenname needs quoting, dictname does NOT */
...@@ -12091,7 +12083,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo) ...@@ -12091,7 +12083,7 @@ dumpTSConfig(Archive *fout, TSConfigInfo *cfginfo)
} }
if (ntups > 0) if (ntups > 0)
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(q, ";\n");
PQclear(res); PQclear(res);
...@@ -12172,7 +12164,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo) ...@@ -12172,7 +12164,7 @@ dumpForeignDataWrapper(Archive *fout, FdwInfo *fdwinfo)
if (strlen(fdwinfo->fdwoptions) > 0) if (strlen(fdwinfo->fdwoptions) > 0)
appendPQExpBuffer(q, " OPTIONS (\n %s\n)", fdwinfo->fdwoptions); appendPQExpBuffer(q, " OPTIONS (\n %s\n)", fdwinfo->fdwoptions);
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(q, ";\n");
appendPQExpBuffer(delq, "DROP FOREIGN DATA WRAPPER %s;\n", appendPQExpBuffer(delq, "DROP FOREIGN DATA WRAPPER %s;\n",
qfdwname); qfdwname);
...@@ -12250,22 +12242,22 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo) ...@@ -12250,22 +12242,22 @@ dumpForeignServer(Archive *fout, ForeignServerInfo *srvinfo)
appendPQExpBuffer(q, "CREATE SERVER %s", qsrvname); appendPQExpBuffer(q, "CREATE SERVER %s", qsrvname);
if (srvinfo->srvtype && strlen(srvinfo->srvtype) > 0) if (srvinfo->srvtype && strlen(srvinfo->srvtype) > 0)
{ {
appendPQExpBuffer(q, " TYPE "); appendPQExpBufferStr(q, " TYPE ");
appendStringLiteralAH(q, srvinfo->srvtype, fout); appendStringLiteralAH(q, srvinfo->srvtype, fout);
} }
if (srvinfo->srvversion && strlen(srvinfo->srvversion) > 0) if (srvinfo->srvversion && strlen(srvinfo->srvversion) > 0)
{ {
appendPQExpBuffer(q, " VERSION "); appendPQExpBufferStr(q, " VERSION ");
appendStringLiteralAH(q, srvinfo->srvversion, fout); appendStringLiteralAH(q, srvinfo->srvversion, fout);
} }
appendPQExpBuffer(q, " FOREIGN DATA WRAPPER "); appendPQExpBufferStr(q, " FOREIGN DATA WRAPPER ");
appendPQExpBuffer(q, "%s", fmtId(fdwname)); appendPQExpBufferStr(q, fmtId(fdwname));
if (srvinfo->srvoptions && strlen(srvinfo->srvoptions) > 0) if (srvinfo->srvoptions && strlen(srvinfo->srvoptions) > 0)
appendPQExpBuffer(q, " OPTIONS (\n %s\n)", srvinfo->srvoptions); appendPQExpBuffer(q, " OPTIONS (\n %s\n)", srvinfo->srvoptions);
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(q, ";\n");
appendPQExpBuffer(delq, "DROP SERVER %s;\n", appendPQExpBuffer(delq, "DROP SERVER %s;\n",
qsrvname); qsrvname);
...@@ -12382,7 +12374,7 @@ dumpUserMappings(Archive *fout, ...@@ -12382,7 +12374,7 @@ dumpUserMappings(Archive *fout,
if (umoptions && strlen(umoptions) > 0) if (umoptions && strlen(umoptions) > 0)
appendPQExpBuffer(q, " OPTIONS (\n %s\n)", umoptions); appendPQExpBuffer(q, " OPTIONS (\n %s\n)", umoptions);
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(q, ";\n");
resetPQExpBuffer(delq); resetPQExpBuffer(delq);
appendPQExpBuffer(delq, "DROP USER MAPPING FOR %s", fmtId(usename)); appendPQExpBuffer(delq, "DROP USER MAPPING FOR %s", fmtId(usename));
...@@ -12591,7 +12583,7 @@ dumpSecLabel(Archive *fout, const char *target, ...@@ -12591,7 +12583,7 @@ dumpSecLabel(Archive *fout, const char *target,
"SECURITY LABEL FOR %s ON %s IS ", "SECURITY LABEL FOR %s ON %s IS ",
fmtId(labels[i].provider), target); fmtId(labels[i].provider), target);
appendStringLiteralAH(query, labels[i].label, fout); appendStringLiteralAH(query, labels[i].label, fout);
appendPQExpBuffer(query, ";\n"); appendPQExpBufferStr(query, ";\n");
} }
if (query->len > 0) if (query->len > 0)
...@@ -12665,7 +12657,7 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename) ...@@ -12665,7 +12657,7 @@ dumpTableSecLabel(Archive *fout, TableInfo *tbinfo, const char *reltypename)
appendPQExpBuffer(query, "SECURITY LABEL FOR %s ON %s IS ", appendPQExpBuffer(query, "SECURITY LABEL FOR %s ON %s IS ",
fmtId(provider), target->data); fmtId(provider), target->data);
appendStringLiteralAH(query, label, fout); appendStringLiteralAH(query, label, fout);
appendPQExpBuffer(query, ";\n"); appendPQExpBufferStr(query, ";\n");
} }
if (query->len > 0) if (query->len > 0)
{ {
...@@ -12795,7 +12787,7 @@ collectSecLabels(Archive *fout, SecLabelItem **items) ...@@ -12795,7 +12787,7 @@ collectSecLabels(Archive *fout, SecLabelItem **items)
query = createPQExpBuffer(); query = createPQExpBuffer();
appendPQExpBuffer(query, appendPQExpBufferStr(query,
"SELECT label, provider, classoid, objoid, objsubid " "SELECT label, provider, classoid, objoid, objsubid "
"FROM pg_catalog.pg_seclabel " "FROM pg_catalog.pg_seclabel "
"ORDER BY classoid, objoid, objsubid"); "ORDER BY classoid, objoid, objsubid");
...@@ -12921,7 +12913,7 @@ createViewAsClause(Archive *fout, TableInfo *tbinfo) ...@@ -12921,7 +12913,7 @@ createViewAsClause(Archive *fout, TableInfo *tbinfo)
} }
else else
{ {
appendPQExpBuffer(query, "SELECT definition AS viewdef " appendPQExpBufferStr(query, "SELECT definition AS viewdef "
"FROM pg_views WHERE viewname = "); "FROM pg_views WHERE viewname = ");
appendStringLiteralAH(query, tbinfo->dobj.name, fout); appendStringLiteralAH(query, tbinfo->dobj.name, fout);
} }
...@@ -13010,7 +13002,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13010,7 +13002,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if (tbinfo->checkoption != NULL) if (tbinfo->checkoption != NULL)
appendPQExpBuffer(q, "\n WITH %s CHECK OPTION", tbinfo->checkoption); appendPQExpBuffer(q, "\n WITH %s CHECK OPTION", tbinfo->checkoption);
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(q, ";\n");
appendPQExpBuffer(labelq, "VIEW %s", appendPQExpBuffer(labelq, "VIEW %s",
fmtId(tbinfo->dobj.name)); fmtId(tbinfo->dobj.name));
...@@ -13129,15 +13121,14 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13129,15 +13121,14 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
/* Format properly if not first attr */ /* Format properly if not first attr */
if (actual_atts == 0) if (actual_atts == 0)
appendPQExpBuffer(q, " ("); appendPQExpBufferStr(q, " (");
else else
appendPQExpBuffer(q, ","); appendPQExpBufferStr(q, ",");
appendPQExpBuffer(q, "\n "); appendPQExpBufferStr(q, "\n ");
actual_atts++; actual_atts++;
/* Attribute name */ /* Attribute name */
appendPQExpBuffer(q, "%s", appendPQExpBufferStr(q, fmtId(tbinfo->attnames[j]));
fmtId(tbinfo->attnames[j]));
if (tbinfo->attisdropped[j]) if (tbinfo->attisdropped[j])
{ {
...@@ -13147,7 +13138,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13147,7 +13138,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
* valid type name; insert INTEGER as a stopgap. We'll * valid type name; insert INTEGER as a stopgap. We'll
* clean things up later. * clean things up later.
*/ */
appendPQExpBuffer(q, " INTEGER /* dummy */"); appendPQExpBufferStr(q, " INTEGER /* dummy */");
/* Skip all the rest, too */ /* Skip all the rest, too */
continue; continue;
} }
...@@ -13155,7 +13146,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13155,7 +13146,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
/* Attribute type */ /* Attribute type */
if (tbinfo->reloftype && !binary_upgrade) if (tbinfo->reloftype && !binary_upgrade)
{ {
appendPQExpBuffer(q, " WITH OPTIONS"); appendPQExpBufferStr(q, " WITH OPTIONS");
} }
else if (fout->remoteVersion >= 70100) else if (fout->remoteVersion >= 70100)
{ {
...@@ -13181,8 +13172,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13181,8 +13172,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
/* always schema-qualify, don't try to be smart */ /* always schema-qualify, don't try to be smart */
appendPQExpBuffer(q, " COLLATE %s.", appendPQExpBuffer(q, " COLLATE %s.",
fmtId(coll->dobj.namespace->dobj.name)); fmtId(coll->dobj.namespace->dobj.name));
appendPQExpBuffer(q, "%s", appendPQExpBufferStr(q, fmtId(coll->dobj.name));
fmtId(coll->dobj.name));
} }
} }
...@@ -13191,7 +13181,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13191,7 +13181,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
tbinfo->attrdefs[j]->adef_expr); tbinfo->attrdefs[j]->adef_expr);
if (has_notnull) if (has_notnull)
appendPQExpBuffer(q, " NOT NULL"); appendPQExpBufferStr(q, " NOT NULL");
} }
} }
...@@ -13206,44 +13196,43 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13206,44 +13196,43 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
continue; continue;
if (actual_atts == 0) if (actual_atts == 0)
appendPQExpBuffer(q, " (\n "); appendPQExpBufferStr(q, " (\n ");
else else
appendPQExpBuffer(q, ",\n "); appendPQExpBufferStr(q, ",\n ");
appendPQExpBuffer(q, "CONSTRAINT %s ", appendPQExpBuffer(q, "CONSTRAINT %s ",
fmtId(constr->dobj.name)); fmtId(constr->dobj.name));
appendPQExpBuffer(q, "%s", constr->condef); appendPQExpBufferStr(q, constr->condef);
actual_atts++; actual_atts++;
} }
if (actual_atts) if (actual_atts)
appendPQExpBuffer(q, "\n)"); appendPQExpBufferStr(q, "\n)");
else if (!(tbinfo->reloftype && !binary_upgrade)) else if (!(tbinfo->reloftype && !binary_upgrade))
{ {
/* /*
* We must have a parenthesized attribute list, even though * We must have a parenthesized attribute list, even though
* empty, when not using the OF TYPE syntax. * empty, when not using the OF TYPE syntax.
*/ */
appendPQExpBuffer(q, " (\n)"); appendPQExpBufferStr(q, " (\n)");
} }
if (numParents > 0 && !binary_upgrade) if (numParents > 0 && !binary_upgrade)
{ {
appendPQExpBuffer(q, "\nINHERITS ("); appendPQExpBufferStr(q, "\nINHERITS (");
for (k = 0; k < numParents; k++) for (k = 0; k < numParents; k++)
{ {
TableInfo *parentRel = parents[k]; TableInfo *parentRel = parents[k];
if (k > 0) if (k > 0)
appendPQExpBuffer(q, ", "); appendPQExpBufferStr(q, ", ");
if (parentRel->dobj.namespace != tbinfo->dobj.namespace) if (parentRel->dobj.namespace != tbinfo->dobj.namespace)
appendPQExpBuffer(q, "%s.", appendPQExpBuffer(q, "%s.",
fmtId(parentRel->dobj.namespace->dobj.name)); fmtId(parentRel->dobj.namespace->dobj.name));
appendPQExpBuffer(q, "%s", appendPQExpBufferStr(q, fmtId(parentRel->dobj.name));
fmtId(parentRel->dobj.name));
} }
appendPQExpBuffer(q, ")"); appendPQExpBufferChar(q, ')');
} }
if (tbinfo->relkind == RELKIND_FOREIGN_TABLE) if (tbinfo->relkind == RELKIND_FOREIGN_TABLE)
...@@ -13255,18 +13244,18 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13255,18 +13244,18 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
{ {
bool addcomma = false; bool addcomma = false;
appendPQExpBuffer(q, "\nWITH ("); appendPQExpBufferStr(q, "\nWITH (");
if (tbinfo->reloptions && strlen(tbinfo->reloptions) > 0) if (tbinfo->reloptions && strlen(tbinfo->reloptions) > 0)
{ {
addcomma = true; addcomma = true;
appendPQExpBuffer(q, "%s", tbinfo->reloptions); appendPQExpBufferStr(q, tbinfo->reloptions);
} }
if (tbinfo->toast_reloptions && strlen(tbinfo->toast_reloptions) > 0) if (tbinfo->toast_reloptions && strlen(tbinfo->toast_reloptions) > 0)
{ {
appendPQExpBuffer(q, "%s%s", addcomma ? ", " : "", appendPQExpBuffer(q, "%s%s", addcomma ? ", " : "",
tbinfo->toast_reloptions); tbinfo->toast_reloptions);
} }
appendPQExpBuffer(q, ")"); appendPQExpBufferChar(q, ')');
} }
/* Dump generic options if any */ /* Dump generic options if any */
...@@ -13287,7 +13276,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13287,7 +13276,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
destroyPQExpBuffer(result); destroyPQExpBuffer(result);
} }
else else
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(q, ";\n");
/* /*
* To create binary-compatible heap files, we have to ensure the same * To create binary-compatible heap files, we have to ensure the same
...@@ -13309,7 +13298,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13309,7 +13298,7 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
{ {
if (tbinfo->attisdropped[j]) if (tbinfo->attisdropped[j])
{ {
appendPQExpBuffer(q, "\n-- For binary upgrade, recreate dropped column.\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, recreate dropped column.\n");
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_attribute\n" appendPQExpBuffer(q, "UPDATE pg_catalog.pg_attribute\n"
"SET attlen = %d, " "SET attlen = %d, "
"attalign = '%c', attbyval = false\n" "attalign = '%c', attbyval = false\n"
...@@ -13317,9 +13306,9 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13317,9 +13306,9 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
tbinfo->attlen[j], tbinfo->attlen[j],
tbinfo->attalign[j]); tbinfo->attalign[j]);
appendStringLiteralAH(q, tbinfo->attnames[j], fout); appendStringLiteralAH(q, tbinfo->attnames[j], fout);
appendPQExpBuffer(q, "\n AND attrelid = "); appendPQExpBufferStr(q, "\n AND attrelid = ");
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
appendPQExpBuffer(q, "::pg_catalog.regclass;\n"); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n");
if (tbinfo->relkind == RELKIND_RELATION) if (tbinfo->relkind == RELKIND_RELATION)
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
...@@ -13334,14 +13323,14 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13334,14 +13323,14 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
else if (!tbinfo->attislocal[j]) else if (!tbinfo->attislocal[j])
{ {
Assert(tbinfo->relkind != RELKIND_FOREIGN_TABLE); Assert(tbinfo->relkind != RELKIND_FOREIGN_TABLE);
appendPQExpBuffer(q, "\n-- For binary upgrade, recreate inherited column.\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, recreate inherited column.\n");
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_attribute\n" appendPQExpBufferStr(q, "UPDATE pg_catalog.pg_attribute\n"
"SET attislocal = false\n" "SET attislocal = false\n"
"WHERE attname = "); "WHERE attname = ");
appendStringLiteralAH(q, tbinfo->attnames[j], fout); appendStringLiteralAH(q, tbinfo->attnames[j], fout);
appendPQExpBuffer(q, "\n AND attrelid = "); appendPQExpBufferStr(q, "\n AND attrelid = ");
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
appendPQExpBuffer(q, "::pg_catalog.regclass;\n"); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n");
} }
} }
...@@ -13352,24 +13341,24 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13352,24 +13341,24 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if (constr->separate || constr->conislocal) if (constr->separate || constr->conislocal)
continue; continue;
appendPQExpBuffer(q, "\n-- For binary upgrade, set up inherited constraint.\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, set up inherited constraint.\n");
appendPQExpBuffer(q, "ALTER TABLE ONLY %s ", appendPQExpBuffer(q, "ALTER TABLE ONLY %s ",
fmtId(tbinfo->dobj.name)); fmtId(tbinfo->dobj.name));
appendPQExpBuffer(q, " ADD CONSTRAINT %s ", appendPQExpBuffer(q, " ADD CONSTRAINT %s ",
fmtId(constr->dobj.name)); fmtId(constr->dobj.name));
appendPQExpBuffer(q, "%s;\n", constr->condef); appendPQExpBuffer(q, "%s;\n", constr->condef);
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_constraint\n" appendPQExpBufferStr(q, "UPDATE pg_catalog.pg_constraint\n"
"SET conislocal = false\n" "SET conislocal = false\n"
"WHERE contype = 'c' AND conname = "); "WHERE contype = 'c' AND conname = ");
appendStringLiteralAH(q, constr->dobj.name, fout); appendStringLiteralAH(q, constr->dobj.name, fout);
appendPQExpBuffer(q, "\n AND conrelid = "); appendPQExpBufferStr(q, "\n AND conrelid = ");
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
appendPQExpBuffer(q, "::pg_catalog.regclass;\n"); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n");
} }
if (numParents > 0) if (numParents > 0)
{ {
appendPQExpBuffer(q, "\n-- For binary upgrade, set up inheritance this way.\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, set up inheritance this way.\n");
for (k = 0; k < numParents; k++) for (k = 0; k < numParents; k++)
{ {
TableInfo *parentRel = parents[k]; TableInfo *parentRel = parents[k];
...@@ -13386,24 +13375,24 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13386,24 +13375,24 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if (tbinfo->reloftype) if (tbinfo->reloftype)
{ {
appendPQExpBuffer(q, "\n-- For binary upgrade, set up typed tables this way.\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, set up typed tables this way.\n");
appendPQExpBuffer(q, "ALTER TABLE ONLY %s OF %s;\n", appendPQExpBuffer(q, "ALTER TABLE ONLY %s OF %s;\n",
fmtId(tbinfo->dobj.name), fmtId(tbinfo->dobj.name),
tbinfo->reloftype); tbinfo->reloftype);
} }
appendPQExpBuffer(q, "\n-- For binary upgrade, set heap's relfrozenxid\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, set heap's relfrozenxid\n");
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n" appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n"
"SET relfrozenxid = '%u'\n" "SET relfrozenxid = '%u'\n"
"WHERE oid = ", "WHERE oid = ",
tbinfo->frozenxid); tbinfo->frozenxid);
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
appendPQExpBuffer(q, "::pg_catalog.regclass;\n"); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n");
if (tbinfo->toast_oid) if (tbinfo->toast_oid)
{ {
/* We preserve the toast oids, so we can use it during restore */ /* We preserve the toast oids, so we can use it during restore */
appendPQExpBuffer(q, "\n-- For binary upgrade, set toast's relfrozenxid\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, set toast's relfrozenxid\n");
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n" appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n"
"SET relfrozenxid = '%u'\n" "SET relfrozenxid = '%u'\n"
"WHERE oid = '%u';\n", "WHERE oid = '%u';\n",
...@@ -13420,12 +13409,12 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo) ...@@ -13420,12 +13409,12 @@ dumpTableSchema(Archive *fout, TableInfo *tbinfo)
if (binary_upgrade && tbinfo->relkind == RELKIND_MATVIEW && if (binary_upgrade && tbinfo->relkind == RELKIND_MATVIEW &&
tbinfo->relispopulated) tbinfo->relispopulated)
{ {
appendPQExpBuffer(q, "\n-- For binary upgrade, mark materialized view as populated\n"); appendPQExpBufferStr(q, "\n-- For binary upgrade, mark materialized view as populated\n");
appendPQExpBuffer(q, "UPDATE pg_catalog.pg_class\n" appendPQExpBufferStr(q, "UPDATE pg_catalog.pg_class\n"
"SET relispopulated = 't'\n" "SET relispopulated = 't'\n"
"WHERE oid = "); "WHERE oid = ");
appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout); appendStringLiteralAH(q, fmtId(tbinfo->dobj.name), fout);
appendPQExpBuffer(q, "::pg_catalog.regclass;\n"); appendPQExpBufferStr(q, "::pg_catalog.regclass;\n");
} }
/* /*
...@@ -13834,19 +13823,19 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo) ...@@ -13834,19 +13823,19 @@ dumpConstraint(Archive *fout, ConstraintInfo *coninfo)
fmtId(attname)); fmtId(attname));
} }
appendPQExpBuffer(q, ")"); appendPQExpBufferChar(q, ')');
if (indxinfo->options && strlen(indxinfo->options) > 0) if (indxinfo->options && strlen(indxinfo->options) > 0)
appendPQExpBuffer(q, " WITH (%s)", indxinfo->options); appendPQExpBuffer(q, " WITH (%s)", indxinfo->options);
if (coninfo->condeferrable) if (coninfo->condeferrable)
{ {
appendPQExpBuffer(q, " DEFERRABLE"); appendPQExpBufferStr(q, " DEFERRABLE");
if (coninfo->condeferred) if (coninfo->condeferred)
appendPQExpBuffer(q, " INITIALLY DEFERRED"); appendPQExpBufferStr(q, " INITIALLY DEFERRED");
} }
appendPQExpBuffer(q, ";\n"); appendPQExpBufferStr(q, ";\n");
} }
/* If the index is clustered, we need to record that. */ /* If the index is clustered, we need to record that. */
...@@ -14039,7 +14028,7 @@ findLastBuiltinOid_V71(Archive *fout, const char *dbname) ...@@ -14039,7 +14028,7 @@ findLastBuiltinOid_V71(Archive *fout, const char *dbname)
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query = createPQExpBuffer();
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT datlastsysoid from pg_database where datname = "); appendPQExpBufferStr(query, "SELECT datlastsysoid from pg_database where datname = ");
appendStringLiteralAH(query, dbname, fout); appendStringLiteralAH(query, dbname, fout);
res = ExecuteSqlQueryForSingleRow(fout, query->data); res = ExecuteSqlQueryForSingleRow(fout, query->data);
...@@ -14191,18 +14180,18 @@ dumpSequence(Archive *fout, TableInfo *tbinfo) ...@@ -14191,18 +14180,18 @@ dumpSequence(Archive *fout, TableInfo *tbinfo)
if (minv) if (minv)
appendPQExpBuffer(query, " MINVALUE %s\n", minv); appendPQExpBuffer(query, " MINVALUE %s\n", minv);
else else
appendPQExpBuffer(query, " NO MINVALUE\n"); appendPQExpBufferStr(query, " NO MINVALUE\n");
if (maxv) if (maxv)
appendPQExpBuffer(query, " MAXVALUE %s\n", maxv); appendPQExpBuffer(query, " MAXVALUE %s\n", maxv);
else else
appendPQExpBuffer(query, " NO MAXVALUE\n"); appendPQExpBufferStr(query, " NO MAXVALUE\n");
appendPQExpBuffer(query, appendPQExpBuffer(query,
" CACHE %s%s", " CACHE %s%s",
cache, (cycled ? "\n CYCLE" : "")); cache, (cycled ? "\n CYCLE" : ""));
appendPQExpBuffer(query, ";\n"); appendPQExpBufferStr(query, ";\n");
appendPQExpBuffer(labelq, "SEQUENCE %s", fmtId(tbinfo->dobj.name)); appendPQExpBuffer(labelq, "SEQUENCE %s", fmtId(tbinfo->dobj.name));
...@@ -14310,7 +14299,7 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo) ...@@ -14310,7 +14299,7 @@ dumpSequenceData(Archive *fout, TableDataInfo *tdinfo)
called = (strcmp(PQgetvalue(res, 0, 1), "t") == 0); called = (strcmp(PQgetvalue(res, 0, 1), "t") == 0);
resetPQExpBuffer(query); resetPQExpBuffer(query);
appendPQExpBuffer(query, "SELECT pg_catalog.setval("); appendPQExpBufferStr(query, "SELECT pg_catalog.setval(");
appendStringLiteralAH(query, fmtId(tbinfo->dobj.name), fout); appendStringLiteralAH(query, fmtId(tbinfo->dobj.name), fout);
appendPQExpBuffer(query, ", %s, %s);\n", appendPQExpBuffer(query, ", %s, %s);\n",
last, (called ? "true" : "false")); last, (called ? "true" : "false"));
...@@ -14367,23 +14356,23 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -14367,23 +14356,23 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
{ {
if (tginfo->tgisconstraint) if (tginfo->tgisconstraint)
{ {
appendPQExpBuffer(query, "CREATE CONSTRAINT TRIGGER "); appendPQExpBufferStr(query, "CREATE CONSTRAINT TRIGGER ");
appendPQExpBufferStr(query, fmtId(tginfo->tgconstrname)); appendPQExpBufferStr(query, fmtId(tginfo->tgconstrname));
} }
else else
{ {
appendPQExpBuffer(query, "CREATE TRIGGER "); appendPQExpBufferStr(query, "CREATE TRIGGER ");
appendPQExpBufferStr(query, fmtId(tginfo->dobj.name)); appendPQExpBufferStr(query, fmtId(tginfo->dobj.name));
} }
appendPQExpBuffer(query, "\n "); appendPQExpBufferStr(query, "\n ");
/* Trigger type */ /* Trigger type */
if (TRIGGER_FOR_BEFORE(tginfo->tgtype)) if (TRIGGER_FOR_BEFORE(tginfo->tgtype))
appendPQExpBuffer(query, "BEFORE"); appendPQExpBufferStr(query, "BEFORE");
else if (TRIGGER_FOR_AFTER(tginfo->tgtype)) else if (TRIGGER_FOR_AFTER(tginfo->tgtype))
appendPQExpBuffer(query, "AFTER"); appendPQExpBufferStr(query, "AFTER");
else if (TRIGGER_FOR_INSTEAD(tginfo->tgtype)) else if (TRIGGER_FOR_INSTEAD(tginfo->tgtype))
appendPQExpBuffer(query, "INSTEAD OF"); appendPQExpBufferStr(query, "INSTEAD OF");
else else
{ {
write_msg(NULL, "unexpected tgtype value: %d\n", tginfo->tgtype); write_msg(NULL, "unexpected tgtype value: %d\n", tginfo->tgtype);
...@@ -14393,31 +14382,31 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -14393,31 +14382,31 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
findx = 0; findx = 0;
if (TRIGGER_FOR_INSERT(tginfo->tgtype)) if (TRIGGER_FOR_INSERT(tginfo->tgtype))
{ {
appendPQExpBuffer(query, " INSERT"); appendPQExpBufferStr(query, " INSERT");
findx++; findx++;
} }
if (TRIGGER_FOR_DELETE(tginfo->tgtype)) if (TRIGGER_FOR_DELETE(tginfo->tgtype))
{ {
if (findx > 0) if (findx > 0)
appendPQExpBuffer(query, " OR DELETE"); appendPQExpBufferStr(query, " OR DELETE");
else else
appendPQExpBuffer(query, " DELETE"); appendPQExpBufferStr(query, " DELETE");
findx++; findx++;
} }
if (TRIGGER_FOR_UPDATE(tginfo->tgtype)) if (TRIGGER_FOR_UPDATE(tginfo->tgtype))
{ {
if (findx > 0) if (findx > 0)
appendPQExpBuffer(query, " OR UPDATE"); appendPQExpBufferStr(query, " OR UPDATE");
else else
appendPQExpBuffer(query, " UPDATE"); appendPQExpBufferStr(query, " UPDATE");
findx++; findx++;
} }
if (TRIGGER_FOR_TRUNCATE(tginfo->tgtype)) if (TRIGGER_FOR_TRUNCATE(tginfo->tgtype))
{ {
if (findx > 0) if (findx > 0)
appendPQExpBuffer(query, " OR TRUNCATE"); appendPQExpBufferStr(query, " OR TRUNCATE");
else else
appendPQExpBuffer(query, " TRUNCATE"); appendPQExpBufferStr(query, " TRUNCATE");
findx++; findx++;
} }
appendPQExpBuffer(query, " ON %s\n", appendPQExpBuffer(query, " ON %s\n",
...@@ -14436,18 +14425,18 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -14436,18 +14425,18 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
fmtId(tginfo->tgconstrrelname)); fmtId(tginfo->tgconstrrelname));
} }
if (!tginfo->tgdeferrable) if (!tginfo->tgdeferrable)
appendPQExpBuffer(query, "NOT "); appendPQExpBufferStr(query, "NOT ");
appendPQExpBuffer(query, "DEFERRABLE INITIALLY "); appendPQExpBufferStr(query, "DEFERRABLE INITIALLY ");
if (tginfo->tginitdeferred) if (tginfo->tginitdeferred)
appendPQExpBuffer(query, "DEFERRED\n"); appendPQExpBufferStr(query, "DEFERRED\n");
else else
appendPQExpBuffer(query, "IMMEDIATE\n"); appendPQExpBufferStr(query, "IMMEDIATE\n");
} }
if (TRIGGER_FOR_ROW(tginfo->tgtype)) if (TRIGGER_FOR_ROW(tginfo->tgtype))
appendPQExpBuffer(query, " FOR EACH ROW\n "); appendPQExpBufferStr(query, " FOR EACH ROW\n ");
else else
appendPQExpBuffer(query, " FOR EACH STATEMENT\n "); appendPQExpBufferStr(query, " FOR EACH STATEMENT\n ");
/* In 7.3, result of regproc is already quoted */ /* In 7.3, result of regproc is already quoted */
if (fout->remoteVersion >= 70300) if (fout->remoteVersion >= 70300)
...@@ -14476,12 +14465,12 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -14476,12 +14465,12 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
} }
if (findx > 0) if (findx > 0)
appendPQExpBuffer(query, ", "); appendPQExpBufferStr(query, ", ");
appendStringLiteralAH(query, p, fout); appendStringLiteralAH(query, p, fout);
p += tlen + 1; p += tlen + 1;
} }
free(tgargs); free(tgargs);
appendPQExpBuffer(query, ");\n"); appendPQExpBufferStr(query, ");\n");
} }
if (tginfo->tgenabled != 't' && tginfo->tgenabled != 'O') if (tginfo->tgenabled != 't' && tginfo->tgenabled != 'O')
...@@ -14492,16 +14481,16 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo) ...@@ -14492,16 +14481,16 @@ dumpTrigger(Archive *fout, TriggerInfo *tginfo)
{ {
case 'D': case 'D':
case 'f': case 'f':
appendPQExpBuffer(query, "DISABLE"); appendPQExpBufferStr(query, "DISABLE");
break; break;
case 'A': case 'A':
appendPQExpBuffer(query, "ENABLE ALWAYS"); appendPQExpBufferStr(query, "ENABLE ALWAYS");
break; break;
case 'R': case 'R':
appendPQExpBuffer(query, "ENABLE REPLICA"); appendPQExpBufferStr(query, "ENABLE REPLICA");
break; break;
default: default:
appendPQExpBuffer(query, "ENABLE"); appendPQExpBufferStr(query, "ENABLE");
break; break;
} }
appendPQExpBuffer(query, " TRIGGER %s;\n", appendPQExpBuffer(query, " TRIGGER %s;\n",
...@@ -14541,9 +14530,9 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) ...@@ -14541,9 +14530,9 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo)
query = createPQExpBuffer(); query = createPQExpBuffer();
labelq = createPQExpBuffer(); labelq = createPQExpBuffer();
appendPQExpBuffer(query, "CREATE EVENT TRIGGER "); appendPQExpBufferStr(query, "CREATE EVENT TRIGGER ");
appendPQExpBufferStr(query, fmtId(evtinfo->dobj.name)); appendPQExpBufferStr(query, fmtId(evtinfo->dobj.name));
appendPQExpBuffer(query, " ON "); appendPQExpBufferStr(query, " ON ");
appendPQExpBufferStr(query, fmtId(evtinfo->evtevent)); appendPQExpBufferStr(query, fmtId(evtinfo->evtevent));
appendPQExpBufferStr(query, " "); appendPQExpBufferStr(query, " ");
...@@ -14554,9 +14543,9 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) ...@@ -14554,9 +14543,9 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo)
appendPQExpBufferStr(query, ") "); appendPQExpBufferStr(query, ") ");
} }
appendPQExpBuffer(query, "\n EXECUTE PROCEDURE "); appendPQExpBufferStr(query, "\n EXECUTE PROCEDURE ");
appendPQExpBufferStr(query, evtinfo->evtfname); appendPQExpBufferStr(query, evtinfo->evtfname);
appendPQExpBuffer(query, "();\n"); appendPQExpBufferStr(query, "();\n");
if (evtinfo->evtenabled != 'O') if (evtinfo->evtenabled != 'O')
{ {
...@@ -14565,19 +14554,19 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo) ...@@ -14565,19 +14554,19 @@ dumpEventTrigger(Archive *fout, EventTriggerInfo *evtinfo)
switch (evtinfo->evtenabled) switch (evtinfo->evtenabled)
{ {
case 'D': case 'D':
appendPQExpBuffer(query, "DISABLE"); appendPQExpBufferStr(query, "DISABLE");
break; break;
case 'A': case 'A':
appendPQExpBuffer(query, "ENABLE ALWAYS"); appendPQExpBufferStr(query, "ENABLE ALWAYS");
break; break;
case 'R': case 'R':
appendPQExpBuffer(query, "ENABLE REPLICA"); appendPQExpBufferStr(query, "ENABLE REPLICA");
break; break;
default: default:
appendPQExpBuffer(query, "ENABLE"); appendPQExpBufferStr(query, "ENABLE");
break; break;
} }
appendPQExpBuffer(query, ";\n"); appendPQExpBufferStr(query, ";\n");
} }
appendPQExpBuffer(labelq, "EVENT TRIGGER %s ", appendPQExpBuffer(labelq, "EVENT TRIGGER %s ",
fmtId(evtinfo->dobj.name)); fmtId(evtinfo->dobj.name));
...@@ -14756,7 +14745,7 @@ getExtensionMembership(Archive *fout, ExtensionInfo extinfo[], ...@@ -14756,7 +14745,7 @@ getExtensionMembership(Archive *fout, ExtensionInfo extinfo[],
query = createPQExpBuffer(); query = createPQExpBuffer();
/* refclassid constraint is redundant but may speed the search */ /* refclassid constraint is redundant but may speed the search */
appendPQExpBuffer(query, "SELECT " appendPQExpBufferStr(query, "SELECT "
"classid, objid, refclassid, refobjid " "classid, objid, refclassid, refobjid "
"FROM pg_depend " "FROM pg_depend "
"WHERE refclassid = 'pg_extension'::regclass " "WHERE refclassid = 'pg_extension'::regclass "
...@@ -14960,7 +14949,7 @@ getDependencies(Archive *fout) ...@@ -14960,7 +14949,7 @@ getDependencies(Archive *fout)
* PIN dependencies aren't interesting, and EXTENSION dependencies were * PIN dependencies aren't interesting, and EXTENSION dependencies were
* already processed by getExtensionMembership. * already processed by getExtensionMembership.
*/ */
appendPQExpBuffer(query, "SELECT " appendPQExpBufferStr(query, "SELECT "
"classid, objid, refclassid, refobjid, deptype " "classid, objid, refclassid, refobjid, deptype "
"FROM pg_depend " "FROM pg_depend "
"WHERE deptype != 'p' AND deptype != 'e' " "WHERE deptype != 'p' AND deptype != 'e' "
...@@ -15304,7 +15293,7 @@ selectSourceSchema(Archive *fout, const char *schemaName) ...@@ -15304,7 +15293,7 @@ selectSourceSchema(Archive *fout, const char *schemaName)
appendPQExpBuffer(query, "SET search_path = %s", appendPQExpBuffer(query, "SET search_path = %s",
fmtId(schemaName)); fmtId(schemaName));
if (strcmp(schemaName, "pg_catalog") != 0) if (strcmp(schemaName, "pg_catalog") != 0)
appendPQExpBuffer(query, ", pg_catalog"); appendPQExpBufferStr(query, ", pg_catalog");
ExecuteSqlStatement(fout, query->data); ExecuteSqlStatement(fout, query->data);
...@@ -15397,21 +15386,21 @@ myFormatType(const char *typname, int32 typmod) ...@@ -15397,21 +15386,21 @@ myFormatType(const char *typname, int32 typmod)
{ {
int len = (typmod - VARHDRSZ); int len = (typmod - VARHDRSZ);
appendPQExpBuffer(buf, "character"); appendPQExpBufferStr(buf, "character");
if (len > 1) if (len > 1)
appendPQExpBuffer(buf, "(%d)", appendPQExpBuffer(buf, "(%d)",
typmod - VARHDRSZ); typmod - VARHDRSZ);
} }
else if (strcmp(typname, "varchar") == 0) else if (strcmp(typname, "varchar") == 0)
{ {
appendPQExpBuffer(buf, "character varying"); appendPQExpBufferStr(buf, "character varying");
if (typmod != -1) if (typmod != -1)
appendPQExpBuffer(buf, "(%d)", appendPQExpBuffer(buf, "(%d)",
typmod - VARHDRSZ); typmod - VARHDRSZ);
} }
else if (strcmp(typname, "numeric") == 0) else if (strcmp(typname, "numeric") == 0)
{ {
appendPQExpBuffer(buf, "numeric"); appendPQExpBufferStr(buf, "numeric");
if (typmod != -1) if (typmod != -1)
{ {
int32 tmp_typmod; int32 tmp_typmod;
...@@ -15431,13 +15420,13 @@ myFormatType(const char *typname, int32 typmod) ...@@ -15431,13 +15420,13 @@ myFormatType(const char *typname, int32 typmod)
* through with quotes. - thomas 1998-12-13 * through with quotes. - thomas 1998-12-13
*/ */
else if (strcmp(typname, "char") == 0) else if (strcmp(typname, "char") == 0)
appendPQExpBuffer(buf, "\"char\""); appendPQExpBufferStr(buf, "\"char\"");
else else
appendPQExpBuffer(buf, "%s", fmtId(typname)); appendPQExpBufferStr(buf, fmtId(typname));
/* Append array qualifier for array types */ /* Append array qualifier for array types */
if (isarray) if (isarray)
appendPQExpBuffer(buf, "[]"); appendPQExpBufferStr(buf, "[]");
result = pg_strdup(buf->data); result = pg_strdup(buf->data);
destroyPQExpBuffer(buf); destroyPQExpBuffer(buf);
...@@ -15460,22 +15449,22 @@ fmtCopyColumnList(const TableInfo *ti, PQExpBuffer buffer) ...@@ -15460,22 +15449,22 @@ fmtCopyColumnList(const TableInfo *ti, PQExpBuffer buffer)
bool needComma; bool needComma;
int i; int i;
appendPQExpBuffer(buffer, "("); appendPQExpBufferChar(buffer, '(');
needComma = false; needComma = false;
for (i = 0; i < numatts; i++) for (i = 0; i < numatts; i++)
{ {
if (attisdropped[i]) if (attisdropped[i])
continue; continue;
if (needComma) if (needComma)
appendPQExpBuffer(buffer, ", "); appendPQExpBufferStr(buffer, ", ");
appendPQExpBuffer(buffer, "%s", fmtId(attnames[i])); appendPQExpBufferStr(buffer, fmtId(attnames[i]));
needComma = true; needComma = true;
} }
if (!needComma) if (!needComma)
return ""; /* no undropped columns */ return ""; /* no undropped columns */
appendPQExpBuffer(buffer, ")"); appendPQExpBufferChar(buffer, ')');
return buffer->data; return buffer->data;
} }
......
...@@ -199,7 +199,7 @@ main(int argc, char *argv[]) ...@@ -199,7 +199,7 @@ main(int argc, char *argv[])
{ {
case 'a': case 'a':
data_only = true; data_only = true;
appendPQExpBuffer(pgdumpopts, " -a"); appendPQExpBufferStr(pgdumpopts, " -a");
break; break;
case 'c': case 'c':
...@@ -212,7 +212,7 @@ main(int argc, char *argv[]) ...@@ -212,7 +212,7 @@ main(int argc, char *argv[])
case 'f': case 'f':
filename = pg_strdup(optarg); filename = pg_strdup(optarg);
appendPQExpBuffer(pgdumpopts, " -f "); appendPQExpBufferStr(pgdumpopts, " -f ");
doShellQuoting(pgdumpopts, filename); doShellQuoting(pgdumpopts, filename);
break; break;
...@@ -233,11 +233,11 @@ main(int argc, char *argv[]) ...@@ -233,11 +233,11 @@ main(int argc, char *argv[])
break; break;
case 'o': case 'o':
appendPQExpBuffer(pgdumpopts, " -o"); appendPQExpBufferStr(pgdumpopts, " -o");
break; break;
case 'O': case 'O':
appendPQExpBuffer(pgdumpopts, " -O"); appendPQExpBufferStr(pgdumpopts, " -O");
break; break;
case 'p': case 'p':
...@@ -249,11 +249,11 @@ main(int argc, char *argv[]) ...@@ -249,11 +249,11 @@ main(int argc, char *argv[])
break; break;
case 's': case 's':
appendPQExpBuffer(pgdumpopts, " -s"); appendPQExpBufferStr(pgdumpopts, " -s");
break; break;
case 'S': case 'S':
appendPQExpBuffer(pgdumpopts, " -S "); appendPQExpBufferStr(pgdumpopts, " -S ");
doShellQuoting(pgdumpopts, optarg); doShellQuoting(pgdumpopts, optarg);
break; break;
...@@ -267,35 +267,35 @@ main(int argc, char *argv[]) ...@@ -267,35 +267,35 @@ main(int argc, char *argv[])
case 'v': case 'v':
verbose = true; verbose = true;
appendPQExpBuffer(pgdumpopts, " -v"); appendPQExpBufferStr(pgdumpopts, " -v");
break; break;
case 'w': case 'w':
prompt_password = TRI_NO; prompt_password = TRI_NO;
appendPQExpBuffer(pgdumpopts, " -w"); appendPQExpBufferStr(pgdumpopts, " -w");
break; break;
case 'W': case 'W':
prompt_password = TRI_YES; prompt_password = TRI_YES;
appendPQExpBuffer(pgdumpopts, " -W"); appendPQExpBufferStr(pgdumpopts, " -W");
break; break;
case 'x': case 'x':
skip_acls = true; skip_acls = true;
appendPQExpBuffer(pgdumpopts, " -x"); appendPQExpBufferStr(pgdumpopts, " -x");
break; break;
case 0: case 0:
break; break;
case 2: case 2:
appendPQExpBuffer(pgdumpopts, " --lock-wait-timeout "); appendPQExpBufferStr(pgdumpopts, " --lock-wait-timeout ");
doShellQuoting(pgdumpopts, optarg); doShellQuoting(pgdumpopts, optarg);
break; break;
case 3: case 3:
use_role = pg_strdup(optarg); use_role = pg_strdup(optarg);
appendPQExpBuffer(pgdumpopts, " --role "); appendPQExpBufferStr(pgdumpopts, " --role ");
doShellQuoting(pgdumpopts, use_role); doShellQuoting(pgdumpopts, use_role);
break; break;
...@@ -345,25 +345,25 @@ main(int argc, char *argv[]) ...@@ -345,25 +345,25 @@ main(int argc, char *argv[])
/* Add long options to the pg_dump argument list */ /* Add long options to the pg_dump argument list */
if (binary_upgrade) if (binary_upgrade)
appendPQExpBuffer(pgdumpopts, " --binary-upgrade"); appendPQExpBufferStr(pgdumpopts, " --binary-upgrade");
if (column_inserts) if (column_inserts)
appendPQExpBuffer(pgdumpopts, " --column-inserts"); appendPQExpBufferStr(pgdumpopts, " --column-inserts");
if (disable_dollar_quoting) if (disable_dollar_quoting)
appendPQExpBuffer(pgdumpopts, " --disable-dollar-quoting"); appendPQExpBufferStr(pgdumpopts, " --disable-dollar-quoting");
if (disable_triggers) if (disable_triggers)
appendPQExpBuffer(pgdumpopts, " --disable-triggers"); appendPQExpBufferStr(pgdumpopts, " --disable-triggers");
if (inserts) if (inserts)
appendPQExpBuffer(pgdumpopts, " --inserts"); appendPQExpBufferStr(pgdumpopts, " --inserts");
if (no_tablespaces) if (no_tablespaces)
appendPQExpBuffer(pgdumpopts, " --no-tablespaces"); appendPQExpBufferStr(pgdumpopts, " --no-tablespaces");
if (quote_all_identifiers) if (quote_all_identifiers)
appendPQExpBuffer(pgdumpopts, " --quote-all-identifiers"); appendPQExpBufferStr(pgdumpopts, " --quote-all-identifiers");
if (use_setsessauth) if (use_setsessauth)
appendPQExpBuffer(pgdumpopts, " --use-set-session-authorization"); appendPQExpBufferStr(pgdumpopts, " --use-set-session-authorization");
if (no_security_labels) if (no_security_labels)
appendPQExpBuffer(pgdumpopts, " --no-security-labels"); appendPQExpBufferStr(pgdumpopts, " --no-security-labels");
if (no_unlogged_table_data) if (no_unlogged_table_data)
appendPQExpBuffer(pgdumpopts, " --no-unlogged-table-data"); appendPQExpBufferStr(pgdumpopts, " --no-unlogged-table-data");
/* /*
* If there was a database specified on the command line, use that, * If there was a database specified on the command line, use that,
...@@ -746,7 +746,7 @@ dumpRoles(PGconn *conn) ...@@ -746,7 +746,7 @@ dumpRoles(PGconn *conn)
if (binary_upgrade) if (binary_upgrade)
{ {
appendPQExpBuffer(buf, "\n-- For binary upgrade, must preserve pg_authid.oid\n"); appendPQExpBufferStr(buf, "\n-- For binary upgrade, must preserve pg_authid.oid\n");
appendPQExpBuffer(buf, appendPQExpBuffer(buf,
"SELECT binary_upgrade.set_next_pg_authid_oid('%u'::pg_catalog.oid);\n\n", "SELECT binary_upgrade.set_next_pg_authid_oid('%u'::pg_catalog.oid);\n\n",
auth_oid); auth_oid);
...@@ -766,34 +766,34 @@ dumpRoles(PGconn *conn) ...@@ -766,34 +766,34 @@ dumpRoles(PGconn *conn)
appendPQExpBuffer(buf, "ALTER ROLE %s WITH", fmtId(rolename)); appendPQExpBuffer(buf, "ALTER ROLE %s WITH", fmtId(rolename));
if (strcmp(PQgetvalue(res, i, i_rolsuper), "t") == 0) if (strcmp(PQgetvalue(res, i, i_rolsuper), "t") == 0)
appendPQExpBuffer(buf, " SUPERUSER"); appendPQExpBufferStr(buf, " SUPERUSER");
else else
appendPQExpBuffer(buf, " NOSUPERUSER"); appendPQExpBufferStr(buf, " NOSUPERUSER");
if (strcmp(PQgetvalue(res, i, i_rolinherit), "t") == 0) if (strcmp(PQgetvalue(res, i, i_rolinherit), "t") == 0)
appendPQExpBuffer(buf, " INHERIT"); appendPQExpBufferStr(buf, " INHERIT");
else else
appendPQExpBuffer(buf, " NOINHERIT"); appendPQExpBufferStr(buf, " NOINHERIT");
if (strcmp(PQgetvalue(res, i, i_rolcreaterole), "t") == 0) if (strcmp(PQgetvalue(res, i, i_rolcreaterole), "t") == 0)
appendPQExpBuffer(buf, " CREATEROLE"); appendPQExpBufferStr(buf, " CREATEROLE");
else else
appendPQExpBuffer(buf, " NOCREATEROLE"); appendPQExpBufferStr(buf, " NOCREATEROLE");
if (strcmp(PQgetvalue(res, i, i_rolcreatedb), "t") == 0) if (strcmp(PQgetvalue(res, i, i_rolcreatedb), "t") == 0)
appendPQExpBuffer(buf, " CREATEDB"); appendPQExpBufferStr(buf, " CREATEDB");
else else
appendPQExpBuffer(buf, " NOCREATEDB"); appendPQExpBufferStr(buf, " NOCREATEDB");
if (strcmp(PQgetvalue(res, i, i_rolcanlogin), "t") == 0) if (strcmp(PQgetvalue(res, i, i_rolcanlogin), "t") == 0)
appendPQExpBuffer(buf, " LOGIN"); appendPQExpBufferStr(buf, " LOGIN");
else else
appendPQExpBuffer(buf, " NOLOGIN"); appendPQExpBufferStr(buf, " NOLOGIN");
if (strcmp(PQgetvalue(res, i, i_rolreplication), "t") == 0) if (strcmp(PQgetvalue(res, i, i_rolreplication), "t") == 0)
appendPQExpBuffer(buf, " REPLICATION"); appendPQExpBufferStr(buf, " REPLICATION");
else else
appendPQExpBuffer(buf, " NOREPLICATION"); appendPQExpBufferStr(buf, " NOREPLICATION");
if (strcmp(PQgetvalue(res, i, i_rolconnlimit), "-1") != 0) if (strcmp(PQgetvalue(res, i, i_rolconnlimit), "-1") != 0)
appendPQExpBuffer(buf, " CONNECTION LIMIT %s", appendPQExpBuffer(buf, " CONNECTION LIMIT %s",
...@@ -801,7 +801,7 @@ dumpRoles(PGconn *conn) ...@@ -801,7 +801,7 @@ dumpRoles(PGconn *conn)
if (!PQgetisnull(res, i, i_rolpassword)) if (!PQgetisnull(res, i, i_rolpassword))
{ {
appendPQExpBuffer(buf, " PASSWORD "); appendPQExpBufferStr(buf, " PASSWORD ");
appendStringLiteralConn(buf, PQgetvalue(res, i, i_rolpassword), conn); appendStringLiteralConn(buf, PQgetvalue(res, i, i_rolpassword), conn);
} }
...@@ -809,13 +809,13 @@ dumpRoles(PGconn *conn) ...@@ -809,13 +809,13 @@ dumpRoles(PGconn *conn)
appendPQExpBuffer(buf, " VALID UNTIL '%s'", appendPQExpBuffer(buf, " VALID UNTIL '%s'",
PQgetvalue(res, i, i_rolvaliduntil)); PQgetvalue(res, i, i_rolvaliduntil));
appendPQExpBuffer(buf, ";\n"); appendPQExpBufferStr(buf, ";\n");
if (!PQgetisnull(res, i, i_rolcomment)) if (!PQgetisnull(res, i, i_rolcomment))
{ {
appendPQExpBuffer(buf, "COMMENT ON ROLE %s IS ", fmtId(rolename)); appendPQExpBuffer(buf, "COMMENT ON ROLE %s IS ", fmtId(rolename));
appendStringLiteralConn(buf, PQgetvalue(res, i, i_rolcomment), conn); appendStringLiteralConn(buf, PQgetvalue(res, i, i_rolcomment), conn);
appendPQExpBuffer(buf, ";\n"); appendPQExpBufferStr(buf, ";\n");
} }
if (!no_security_labels && server_version >= 90200) if (!no_security_labels && server_version >= 90200)
...@@ -1068,9 +1068,9 @@ dumpTablespaces(PGconn *conn) ...@@ -1068,9 +1068,9 @@ dumpTablespaces(PGconn *conn)
appendPQExpBuffer(buf, "CREATE TABLESPACE %s", fspcname); appendPQExpBuffer(buf, "CREATE TABLESPACE %s", fspcname);
appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner)); appendPQExpBuffer(buf, " OWNER %s", fmtId(spcowner));
appendPQExpBuffer(buf, " LOCATION "); appendPQExpBufferStr(buf, " LOCATION ");
appendStringLiteralConn(buf, spclocation, conn); appendStringLiteralConn(buf, spclocation, conn);
appendPQExpBuffer(buf, ";\n"); appendPQExpBufferStr(buf, ";\n");
if (spcoptions && spcoptions[0] != '\0') if (spcoptions && spcoptions[0] != '\0')
appendPQExpBuffer(buf, "ALTER TABLESPACE %s SET (%s);\n", appendPQExpBuffer(buf, "ALTER TABLESPACE %s SET (%s);\n",
...@@ -1090,7 +1090,7 @@ dumpTablespaces(PGconn *conn) ...@@ -1090,7 +1090,7 @@ dumpTablespaces(PGconn *conn)
{ {
appendPQExpBuffer(buf, "COMMENT ON TABLESPACE %s IS ", fspcname); appendPQExpBuffer(buf, "COMMENT ON TABLESPACE %s IS ", fspcname);
appendStringLiteralConn(buf, spccomment, conn); appendStringLiteralConn(buf, spccomment, conn);
appendPQExpBuffer(buf, ";\n"); appendPQExpBufferStr(buf, ";\n");
} }
if (!no_security_labels && server_version >= 90200) if (!no_security_labels && server_version >= 90200)
...@@ -1320,26 +1320,26 @@ dumpCreateDB(PGconn *conn) ...@@ -1320,26 +1320,26 @@ dumpCreateDB(PGconn *conn)
{ {
appendPQExpBuffer(buf, "CREATE DATABASE %s", fdbname); appendPQExpBuffer(buf, "CREATE DATABASE %s", fdbname);
appendPQExpBuffer(buf, " WITH TEMPLATE = template0"); appendPQExpBufferStr(buf, " WITH TEMPLATE = template0");
if (strlen(dbowner) != 0) if (strlen(dbowner) != 0)
appendPQExpBuffer(buf, " OWNER = %s", fmtId(dbowner)); appendPQExpBuffer(buf, " OWNER = %s", fmtId(dbowner));
if (default_encoding && strcmp(dbencoding, default_encoding) != 0) if (default_encoding && strcmp(dbencoding, default_encoding) != 0)
{ {
appendPQExpBuffer(buf, " ENCODING = "); appendPQExpBufferStr(buf, " ENCODING = ");
appendStringLiteralConn(buf, dbencoding, conn); appendStringLiteralConn(buf, dbencoding, conn);
} }
if (default_collate && strcmp(dbcollate, default_collate) != 0) if (default_collate && strcmp(dbcollate, default_collate) != 0)
{ {
appendPQExpBuffer(buf, " LC_COLLATE = "); appendPQExpBufferStr(buf, " LC_COLLATE = ");
appendStringLiteralConn(buf, dbcollate, conn); appendStringLiteralConn(buf, dbcollate, conn);
} }
if (default_ctype && strcmp(dbctype, default_ctype) != 0) if (default_ctype && strcmp(dbctype, default_ctype) != 0)
{ {
appendPQExpBuffer(buf, " LC_CTYPE = "); appendPQExpBufferStr(buf, " LC_CTYPE = ");
appendStringLiteralConn(buf, dbctype, conn); appendStringLiteralConn(buf, dbctype, conn);
} }
...@@ -1359,24 +1359,24 @@ dumpCreateDB(PGconn *conn) ...@@ -1359,24 +1359,24 @@ dumpCreateDB(PGconn *conn)
appendPQExpBuffer(buf, " CONNECTION LIMIT = %s", appendPQExpBuffer(buf, " CONNECTION LIMIT = %s",
dbconnlimit); dbconnlimit);
appendPQExpBuffer(buf, ";\n"); appendPQExpBufferStr(buf, ";\n");
if (strcmp(dbistemplate, "t") == 0) if (strcmp(dbistemplate, "t") == 0)
{ {
appendPQExpBuffer(buf, "UPDATE pg_catalog.pg_database SET datistemplate = 't' WHERE datname = "); appendPQExpBufferStr(buf, "UPDATE pg_catalog.pg_database SET datistemplate = 't' WHERE datname = ");
appendStringLiteralConn(buf, dbname, conn); appendStringLiteralConn(buf, dbname, conn);
appendPQExpBuffer(buf, ";\n"); appendPQExpBufferStr(buf, ";\n");
} }
if (binary_upgrade) if (binary_upgrade)
{ {
appendPQExpBuffer(buf, "-- For binary upgrade, set datfrozenxid.\n"); appendPQExpBufferStr(buf, "-- For binary upgrade, set datfrozenxid.\n");
appendPQExpBuffer(buf, "UPDATE pg_catalog.pg_database " appendPQExpBuffer(buf, "UPDATE pg_catalog.pg_database "
"SET datfrozenxid = '%u' " "SET datfrozenxid = '%u' "
"WHERE datname = ", "WHERE datname = ",
dbfrozenxid); dbfrozenxid);
appendStringLiteralConn(buf, dbname, conn); appendStringLiteralConn(buf, dbname, conn);
appendPQExpBuffer(buf, ";\n"); appendPQExpBufferStr(buf, ";\n");
} }
} }
...@@ -1472,7 +1472,7 @@ dumpUserConfig(PGconn *conn, const char *username) ...@@ -1472,7 +1472,7 @@ dumpUserConfig(PGconn *conn, const char *username)
printfPQExpBuffer(buf, "SELECT useconfig[%d] FROM pg_shadow WHERE usename = ", count); printfPQExpBuffer(buf, "SELECT useconfig[%d] FROM pg_shadow WHERE usename = ", count);
appendStringLiteralConn(buf, username, conn); appendStringLiteralConn(buf, username, conn);
if (server_version >= 90000) if (server_version >= 90000)
appendPQExpBuffer(buf, ")"); appendPQExpBufferChar(buf, ')');
res = executeQuery(conn, buf->data); res = executeQuery(conn, buf->data);
if (PQntuples(res) == 1 && if (PQntuples(res) == 1 &&
...@@ -1561,10 +1561,10 @@ makeAlterConfigCommand(PGconn *conn, const char *arrayitem, ...@@ -1561,10 +1561,10 @@ makeAlterConfigCommand(PGconn *conn, const char *arrayitem,
*/ */
if (pg_strcasecmp(mine, "DateStyle") == 0 if (pg_strcasecmp(mine, "DateStyle") == 0
|| pg_strcasecmp(mine, "search_path") == 0) || pg_strcasecmp(mine, "search_path") == 0)
appendPQExpBuffer(buf, "%s", pos + 1); appendPQExpBufferStr(buf, pos + 1);
else else
appendStringLiteralConn(buf, pos + 1, conn); appendStringLiteralConn(buf, pos + 1, conn);
appendPQExpBuffer(buf, ";\n"); appendPQExpBufferStr(buf, ";\n");
fprintf(OPF, "%s", buf->data); fprintf(OPF, "%s", buf->data);
destroyPQExpBuffer(buf); destroyPQExpBuffer(buf);
...@@ -1644,9 +1644,9 @@ runPgDump(const char *dbname) ...@@ -1644,9 +1644,9 @@ runPgDump(const char *dbname)
* format. * format.
*/ */
if (filename) if (filename)
appendPQExpBuffer(cmd, " -Fa "); appendPQExpBufferStr(cmd, " -Fa ");
else else
appendPQExpBuffer(cmd, " -Fp "); appendPQExpBufferStr(cmd, " -Fp ");
/* /*
* Append the database name to the already-constructed stem of connection * Append the database name to the already-constructed stem of connection
...@@ -1657,7 +1657,7 @@ runPgDump(const char *dbname) ...@@ -1657,7 +1657,7 @@ runPgDump(const char *dbname)
doShellQuoting(cmd, connstrbuf->data); doShellQuoting(cmd, connstrbuf->data);
appendPQExpBuffer(cmd, "%s", SYSTEMQUOTE); appendPQExpBufferStr(cmd, SYSTEMQUOTE);
if (verbose) if (verbose)
fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data); fprintf(stderr, _("%s: running \"%s\"\n"), progname, cmd->data);
...@@ -2082,7 +2082,7 @@ doShellQuoting(PQExpBuffer buf, const char *str) ...@@ -2082,7 +2082,7 @@ doShellQuoting(PQExpBuffer buf, const char *str)
for (p = str; *p; p++) for (p = str; *p; p++)
{ {
if (*p == '\'') if (*p == '\'')
appendPQExpBuffer(buf, "'\"'\"'"); appendPQExpBufferStr(buf, "'\"'\"'");
else else
appendPQExpBufferChar(buf, *p); appendPQExpBufferChar(buf, *p);
} }
...@@ -2093,7 +2093,7 @@ doShellQuoting(PQExpBuffer buf, const char *str) ...@@ -2093,7 +2093,7 @@ doShellQuoting(PQExpBuffer buf, const char *str)
for (p = str; *p; p++) for (p = str; *p; p++)
{ {
if (*p == '"') if (*p == '"')
appendPQExpBuffer(buf, "\\\""); appendPQExpBufferStr(buf, "\\\"");
else else
appendPQExpBufferChar(buf, *p); appendPQExpBufferChar(buf, *p);
} }
......
...@@ -2786,7 +2786,7 @@ lookup_function_oid(PGconn *conn, const char *desc, Oid *foid) ...@@ -2786,7 +2786,7 @@ lookup_function_oid(PGconn *conn, const char *desc, Oid *foid)
PGresult *res; PGresult *res;
query = createPQExpBuffer(); query = createPQExpBuffer();
printfPQExpBuffer(query, "SELECT "); appendPQExpBufferStr(query, "SELECT ");
appendStringLiteralConn(query, desc, conn); appendStringLiteralConn(query, desc, conn);
appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid", appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
strchr(desc, '(') ? "regprocedure" : "regproc"); strchr(desc, '(') ? "regprocedure" : "regproc");
......
...@@ -362,9 +362,9 @@ do_copy(const char *args) ...@@ -362,9 +362,9 @@ do_copy(const char *args)
printfPQExpBuffer(&query, "COPY "); printfPQExpBuffer(&query, "COPY ");
appendPQExpBufferStr(&query, options->before_tofrom); appendPQExpBufferStr(&query, options->before_tofrom);
if (options->from) if (options->from)
appendPQExpBuffer(&query, " FROM STDIN "); appendPQExpBufferStr(&query, " FROM STDIN ");
else else
appendPQExpBuffer(&query, " TO STDOUT "); appendPQExpBufferStr(&query, " TO STDOUT ");
if (options->after_tofrom) if (options->after_tofrom)
appendPQExpBufferStr(&query, options->after_tofrom); appendPQExpBufferStr(&query, options->after_tofrom);
......
...@@ -105,14 +105,14 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem) ...@@ -105,14 +105,14 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem)
gettext_noop("Description")); gettext_noop("Description"));
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false, processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "p.proname", NULL, "n.nspname", "p.proname", NULL,
"pg_catalog.pg_function_is_visible(p.oid)"); "pg_catalog.pg_function_is_visible(p.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2, 4;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -167,7 +167,7 @@ describeTablespaces(const char *pattern, bool verbose) ...@@ -167,7 +167,7 @@ describeTablespaces(const char *pattern, bool verbose)
if (verbose) if (verbose)
{ {
appendPQExpBuffer(&buf, ",\n "); appendPQExpBufferStr(&buf, ",\n ");
printACLColumn(&buf, "spcacl"); printACLColumn(&buf, "spcacl");
} }
...@@ -176,14 +176,14 @@ describeTablespaces(const char *pattern, bool verbose) ...@@ -176,14 +176,14 @@ describeTablespaces(const char *pattern, bool verbose)
",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"", ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_tablespace\n"); "\nFROM pg_catalog.pg_tablespace\n");
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
NULL, "spcname", NULL, NULL, "spcname", NULL,
NULL); NULL);
appendPQExpBuffer(&buf, "ORDER BY 1;"); appendPQExpBufferStr(&buf, "ORDER BY 1;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -359,12 +359,12 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool ...@@ -359,12 +359,12 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
gettext_noop("Source code"), gettext_noop("Source code"),
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_proc p" "\nFROM pg_catalog.pg_proc p"
"\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"); "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
if (verbose) if (verbose)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n"); " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
have_where = false; have_where = false;
...@@ -377,65 +377,65 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool ...@@ -377,65 +377,65 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
if (!showAggregate) if (!showAggregate)
{ {
if (have_where) if (have_where)
appendPQExpBuffer(&buf, " AND "); appendPQExpBufferStr(&buf, " AND ");
else else
{ {
appendPQExpBuffer(&buf, "WHERE "); appendPQExpBufferStr(&buf, "WHERE ");
have_where = true; have_where = true;
} }
appendPQExpBuffer(&buf, "NOT p.proisagg\n"); appendPQExpBufferStr(&buf, "NOT p.proisagg\n");
} }
if (!showTrigger) if (!showTrigger)
{ {
if (have_where) if (have_where)
appendPQExpBuffer(&buf, " AND "); appendPQExpBufferStr(&buf, " AND ");
else else
{ {
appendPQExpBuffer(&buf, "WHERE "); appendPQExpBufferStr(&buf, "WHERE ");
have_where = true; have_where = true;
} }
appendPQExpBuffer(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n"); appendPQExpBufferStr(&buf, "p.prorettype <> 'pg_catalog.trigger'::pg_catalog.regtype\n");
} }
if (!showWindow && pset.sversion >= 80400) if (!showWindow && pset.sversion >= 80400)
{ {
if (have_where) if (have_where)
appendPQExpBuffer(&buf, " AND "); appendPQExpBufferStr(&buf, " AND ");
else else
{ {
appendPQExpBuffer(&buf, "WHERE "); appendPQExpBufferStr(&buf, "WHERE ");
have_where = true; have_where = true;
} }
appendPQExpBuffer(&buf, "NOT p.proiswindow\n"); appendPQExpBufferStr(&buf, "NOT p.proiswindow\n");
} }
} }
else else
{ {
bool needs_or = false; bool needs_or = false;
appendPQExpBuffer(&buf, "WHERE (\n "); appendPQExpBufferStr(&buf, "WHERE (\n ");
have_where = true; have_where = true;
/* Note: at least one of these must be true ... */ /* Note: at least one of these must be true ... */
if (showAggregate) if (showAggregate)
{ {
appendPQExpBuffer(&buf, "p.proisagg\n"); appendPQExpBufferStr(&buf, "p.proisagg\n");
needs_or = true; needs_or = true;
} }
if (showTrigger) if (showTrigger)
{ {
if (needs_or) if (needs_or)
appendPQExpBuffer(&buf, " OR "); appendPQExpBufferStr(&buf, " OR ");
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n"); "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
needs_or = true; needs_or = true;
} }
if (showWindow) if (showWindow)
{ {
if (needs_or) if (needs_or)
appendPQExpBuffer(&buf, " OR "); appendPQExpBufferStr(&buf, " OR ");
appendPQExpBuffer(&buf, "p.proiswindow\n"); appendPQExpBufferStr(&buf, "p.proiswindow\n");
needs_or = true; needs_or = true;
} }
appendPQExpBuffer(&buf, " )\n"); appendPQExpBufferStr(&buf, " )\n");
} }
processSQLNamePattern(pset.db, &buf, pattern, have_where, false, processSQLNamePattern(pset.db, &buf, pattern, have_where, false,
...@@ -443,10 +443,10 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool ...@@ -443,10 +443,10 @@ describeFunctions(const char *functypes, const char *pattern, bool verbose, bool
"pg_catalog.pg_function_is_visible(p.oid)"); "pg_catalog.pg_function_is_visible(p.oid)");
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
appendPQExpBuffer(&buf, "ORDER BY 1, 2, 4;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 4;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -497,7 +497,7 @@ describeTypes(const char *pattern, bool verbose, bool showSystem) ...@@ -497,7 +497,7 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
gettext_noop("Size")); gettext_noop("Size"));
if (verbose && pset.sversion >= 80300) if (verbose && pset.sversion >= 80300)
{ {
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" pg_catalog.array_to_string(\n" " pg_catalog.array_to_string(\n"
" ARRAY(\n" " ARRAY(\n"
" SELECT e.enumlabel\n" " SELECT e.enumlabel\n"
...@@ -505,10 +505,10 @@ describeTypes(const char *pattern, bool verbose, bool showSystem) ...@@ -505,10 +505,10 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
" WHERE e.enumtypid = t.oid\n"); " WHERE e.enumtypid = t.oid\n");
if (pset.sversion >= 90100) if (pset.sversion >= 90100)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" ORDER BY e.enumsortorder\n"); " ORDER BY e.enumsortorder\n");
else else
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" ORDER BY e.oid\n"); " ORDER BY e.oid\n");
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
...@@ -520,22 +520,22 @@ describeTypes(const char *pattern, bool verbose, bool showSystem) ...@@ -520,22 +520,22 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
if (verbose && pset.sversion >= 90200) if (verbose && pset.sversion >= 90200)
{ {
printACLColumn(&buf, "t.typacl"); printACLColumn(&buf, "t.typacl");
appendPQExpBuffer(&buf, ",\n "); appendPQExpBufferStr(&buf, ",\n ");
} }
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
" pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n", " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, "FROM pg_catalog.pg_type t\n" appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_type t\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"); " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
/* /*
* do not include complex types (typrelid!=0) unless they are standalone * do not include complex types (typrelid!=0) unless they are standalone
* composite types * composite types
*/ */
appendPQExpBuffer(&buf, "WHERE (t.typrelid = 0 "); appendPQExpBufferStr(&buf, "WHERE (t.typrelid = 0 ");
appendPQExpBuffer(&buf, "OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c " appendPQExpBufferStr(&buf, "OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c "
"WHERE c.oid = t.typrelid))\n"); "WHERE c.oid = t.typrelid))\n");
/* /*
...@@ -543,12 +543,12 @@ describeTypes(const char *pattern, bool verbose, bool showSystem) ...@@ -543,12 +543,12 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
* that their names start with underscore) * that their names start with underscore)
*/ */
if (pset.sversion >= 80300) if (pset.sversion >= 80300)
appendPQExpBuffer(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n"); appendPQExpBufferStr(&buf, " AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
else else
appendPQExpBuffer(&buf, " AND t.typname !~ '^_'\n"); appendPQExpBufferStr(&buf, " AND t.typname !~ '^_'\n");
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
/* Match name pattern against either internal or external name */ /* Match name pattern against either internal or external name */
...@@ -557,7 +557,7 @@ describeTypes(const char *pattern, bool verbose, bool showSystem) ...@@ -557,7 +557,7 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
"pg_catalog.format_type(t.oid, NULL)", "pg_catalog.format_type(t.oid, NULL)",
"pg_catalog.pg_type_is_visible(t.oid)"); "pg_catalog.pg_type_is_visible(t.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -617,14 +617,14 @@ describeOperators(const char *pattern, bool showSystem) ...@@ -617,14 +617,14 @@ describeOperators(const char *pattern, bool showSystem)
gettext_noop("Description")); gettext_noop("Description"));
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, "WHERE n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, true, processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, true,
"n.nspname", "o.oprname", NULL, "n.nspname", "o.oprname", NULL,
"pg_catalog.pg_operator_is_visible(o.oid)"); "pg_catalog.pg_operator_is_visible(o.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3, 4;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3, 4;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -669,7 +669,7 @@ listAllDbs(const char *pattern, bool verbose) ...@@ -669,7 +669,7 @@ listAllDbs(const char *pattern, bool verbose)
" d.datctype as \"%s\",\n", " d.datctype as \"%s\",\n",
gettext_noop("Collate"), gettext_noop("Collate"),
gettext_noop("Ctype")); gettext_noop("Ctype"));
appendPQExpBuffer(&buf, " "); appendPQExpBufferStr(&buf, " ");
printACLColumn(&buf, "d.datacl"); printACLColumn(&buf, "d.datacl");
if (verbose && pset.sversion >= 80200) if (verbose && pset.sversion >= 80200)
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
...@@ -686,17 +686,17 @@ listAllDbs(const char *pattern, bool verbose) ...@@ -686,17 +686,17 @@ listAllDbs(const char *pattern, bool verbose)
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"", ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_database d\n"); "\nFROM pg_catalog.pg_database d\n");
if (verbose && pset.sversion >= 80000) if (verbose && pset.sversion >= 80000)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n"); " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
if (pattern) if (pattern)
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
NULL, "d.datname", NULL, NULL); NULL, "d.datname", NULL, NULL);
appendPQExpBuffer(&buf, "ORDER BY 1;"); appendPQExpBufferStr(&buf, "ORDER BY 1;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
if (!res) if (!res)
...@@ -761,7 +761,7 @@ permissionsList(const char *pattern) ...@@ -761,7 +761,7 @@ permissionsList(const char *pattern)
" ), E'\\n') AS \"%s\"", " ), E'\\n') AS \"%s\"",
gettext_noop("Column access privileges")); gettext_noop("Column access privileges"));
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_class c\n" appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_class c\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
"WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f')\n"); "WHERE c.relkind IN ('r', 'v', 'm', 'S', 'f')\n");
...@@ -775,7 +775,7 @@ permissionsList(const char *pattern) ...@@ -775,7 +775,7 @@ permissionsList(const char *pattern)
"n.nspname", "c.relname", NULL, "n.nspname", "c.relname", NULL,
"n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)"); "n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
if (!res) if (!res)
...@@ -839,7 +839,7 @@ listDefaultACLs(const char *pattern) ...@@ -839,7 +839,7 @@ listDefaultACLs(const char *pattern)
printACLColumn(&buf, "d.defaclacl"); printACLColumn(&buf, "d.defaclacl");
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_default_acl d\n" appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_default_acl d\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n"); " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
...@@ -848,7 +848,7 @@ listDefaultACLs(const char *pattern) ...@@ -848,7 +848,7 @@ listDefaultACLs(const char *pattern)
"pg_catalog.pg_get_userbyid(d.defaclrole)", "pg_catalog.pg_get_userbyid(d.defaclrole)",
NULL); NULL);
appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
if (!res) if (!res)
...@@ -914,7 +914,7 @@ objectDescription(const char *pattern, bool showSystem) ...@@ -914,7 +914,7 @@ objectDescription(const char *pattern, bool showSystem)
gettext_noop("constraint")); gettext_noop("constraint"));
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, "WHERE n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern,
...@@ -941,7 +941,7 @@ objectDescription(const char *pattern, bool showSystem) ...@@ -941,7 +941,7 @@ objectDescription(const char *pattern, bool showSystem)
gettext_noop("operator class")); gettext_noop("operator class"));
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false, processSQLNamePattern(pset.db, &buf, pattern, true, false,
...@@ -970,7 +970,7 @@ objectDescription(const char *pattern, bool showSystem) ...@@ -970,7 +970,7 @@ objectDescription(const char *pattern, bool showSystem)
gettext_noop("operator family")); gettext_noop("operator family"));
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false, processSQLNamePattern(pset.db, &buf, pattern, true, false,
...@@ -992,7 +992,7 @@ objectDescription(const char *pattern, bool showSystem) ...@@ -992,7 +992,7 @@ objectDescription(const char *pattern, bool showSystem)
gettext_noop("rule")); gettext_noop("rule"));
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false, processSQLNamePattern(pset.db, &buf, pattern, true, false,
...@@ -1012,18 +1012,18 @@ objectDescription(const char *pattern, bool showSystem) ...@@ -1012,18 +1012,18 @@ objectDescription(const char *pattern, bool showSystem)
gettext_noop("trigger")); gettext_noop("trigger"));
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, "WHERE n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false, processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
"n.nspname", "t.tgname", NULL, "n.nspname", "t.tgname", NULL,
"pg_catalog.pg_table_is_visible(c.oid)"); "pg_catalog.pg_table_is_visible(c.oid)");
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
") AS tt\n" ") AS tt\n"
" JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n"); " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2, 3;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -1067,14 +1067,14 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem) ...@@ -1067,14 +1067,14 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"); " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, "WHERE n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, "WHERE n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false, processSQLNamePattern(pset.db, &buf, pattern, !showSystem && !pattern, false,
"n.nspname", "c.relname", NULL, "n.nspname", "c.relname", NULL,
"pg_catalog.pg_table_is_visible(c.oid)"); "pg_catalog.pg_table_is_visible(c.oid)");
appendPQExpBuffer(&buf, "ORDER BY 2, 3;"); appendPQExpBufferStr(&buf, "ORDER BY 2, 3;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -1330,30 +1330,30 @@ describeOneTableDetails(const char *schemaname, ...@@ -1330,30 +1330,30 @@ describeOneTableDetails(const char *schemaname,
* you are adding column(s) preceding to verbose-only columns. * you are adding column(s) preceding to verbose-only columns.
*/ */
printfPQExpBuffer(&buf, "SELECT a.attname,"); printfPQExpBuffer(&buf, "SELECT a.attname,");
appendPQExpBuffer(&buf, "\n pg_catalog.format_type(a.atttypid, a.atttypmod)," appendPQExpBufferStr(&buf, "\n pg_catalog.format_type(a.atttypid, a.atttypmod),"
"\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)" "\n (SELECT substring(pg_catalog.pg_get_expr(d.adbin, d.adrelid) for 128)"
"\n FROM pg_catalog.pg_attrdef d" "\n FROM pg_catalog.pg_attrdef d"
"\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)," "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef),"
"\n a.attnotnull, a.attnum,"); "\n a.attnotnull, a.attnum,");
if (pset.sversion >= 90100) if (pset.sversion >= 90100)
appendPQExpBuffer(&buf, "\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n" appendPQExpBufferStr(&buf, "\n (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type t\n"
" WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation"); " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
else else
appendPQExpBuffer(&buf, "\n NULL AS attcollation"); appendPQExpBufferStr(&buf, "\n NULL AS attcollation");
if (tableinfo.relkind == 'i') if (tableinfo.relkind == 'i')
appendPQExpBuffer(&buf, ",\n pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef"); appendPQExpBufferStr(&buf, ",\n pg_catalog.pg_get_indexdef(a.attrelid, a.attnum, TRUE) AS indexdef");
else else
appendPQExpBuffer(&buf, ",\n NULL AS indexdef"); appendPQExpBufferStr(&buf, ",\n NULL AS indexdef");
if (tableinfo.relkind == 'f' && pset.sversion >= 90200) if (tableinfo.relkind == 'f' && pset.sversion >= 90200)
appendPQExpBuffer(&buf, ",\n CASE WHEN attfdwoptions IS NULL THEN '' ELSE " appendPQExpBufferStr(&buf, ",\n CASE WHEN attfdwoptions IS NULL THEN '' ELSE "
" '(' || array_to_string(ARRAY(SELECT quote_ident(option_name) || ' ' || quote_literal(option_value) FROM " " '(' || array_to_string(ARRAY(SELECT quote_ident(option_name) || ' ' || quote_literal(option_value) FROM "
" pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions"); " pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
else else
appendPQExpBuffer(&buf, ",\n NULL AS attfdwoptions"); appendPQExpBufferStr(&buf, ",\n NULL AS attfdwoptions");
if (verbose) if (verbose)
{ {
appendPQExpBuffer(&buf, ",\n a.attstorage"); appendPQExpBufferStr(&buf, ",\n a.attstorage");
appendPQExpBuffer(&buf, ",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget"); appendPQExpBufferStr(&buf, ",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
/* /*
* In 9.0+, we have column comments for: relations, views, composite * In 9.0+, we have column comments for: relations, views, composite
...@@ -1362,12 +1362,12 @@ describeOneTableDetails(const char *schemaname, ...@@ -1362,12 +1362,12 @@ describeOneTableDetails(const char *schemaname,
if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' || if (tableinfo.relkind == 'r' || tableinfo.relkind == 'v' ||
tableinfo.relkind == 'm' || tableinfo.relkind == 'm' ||
tableinfo.relkind == 'f' || tableinfo.relkind == 'c') tableinfo.relkind == 'f' || tableinfo.relkind == 'c')
appendPQExpBuffer(&buf, ", pg_catalog.col_description(a.attrelid, a.attnum)"); appendPQExpBufferStr(&buf, ", pg_catalog.col_description(a.attrelid, a.attnum)");
} }
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_attribute a"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_attribute a");
appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid); appendPQExpBuffer(&buf, "\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
appendPQExpBuffer(&buf, "\nORDER BY a.attnum;"); appendPQExpBufferStr(&buf, "\nORDER BY a.attnum;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
if (!res) if (!res)
...@@ -1589,11 +1589,11 @@ describeOneTableDetails(const char *schemaname, ...@@ -1589,11 +1589,11 @@ describeOneTableDetails(const char *schemaname,
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf,
"SELECT i.indisunique, i.indisprimary, i.indisclustered, "); "SELECT i.indisunique, i.indisprimary, i.indisclustered, ");
if (pset.sversion >= 80200) if (pset.sversion >= 80200)
appendPQExpBuffer(&buf, "i.indisvalid,\n"); appendPQExpBufferStr(&buf, "i.indisvalid,\n");
else else
appendPQExpBuffer(&buf, "true AS indisvalid,\n"); appendPQExpBufferStr(&buf, "true AS indisvalid,\n");
if (pset.sversion >= 90000) if (pset.sversion >= 90000)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" (NOT i.indimmediate) AND " " (NOT i.indimmediate) AND "
"EXISTS (SELECT 1 FROM pg_catalog.pg_constraint " "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
"WHERE conrelid = i.indrelid AND " "WHERE conrelid = i.indrelid AND "
...@@ -1607,7 +1607,7 @@ describeOneTableDetails(const char *schemaname, ...@@ -1607,7 +1607,7 @@ describeOneTableDetails(const char *schemaname,
"contype IN ('p','u','x') AND " "contype IN ('p','u','x') AND "
"condeferred) AS condeferred,\n"); "condeferred) AS condeferred,\n");
else else
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" false AS condeferrable, false AS condeferred,\n"); " false AS condeferrable, false AS condeferred,\n");
if (pset.sversion >= 90400) if (pset.sversion >= 90400)
...@@ -1659,16 +1659,16 @@ describeOneTableDetails(const char *schemaname, ...@@ -1659,16 +1659,16 @@ describeOneTableDetails(const char *schemaname,
appendPQExpBuffer(&tmpbuf, _(", predicate (%s)"), indpred); appendPQExpBuffer(&tmpbuf, _(", predicate (%s)"), indpred);
if (strcmp(indisclustered, "t") == 0) if (strcmp(indisclustered, "t") == 0)
appendPQExpBuffer(&tmpbuf, _(", clustered")); appendPQExpBufferStr(&tmpbuf, _(", clustered"));
if (strcmp(indisvalid, "t") != 0) if (strcmp(indisvalid, "t") != 0)
appendPQExpBuffer(&tmpbuf, _(", invalid")); appendPQExpBufferStr(&tmpbuf, _(", invalid"));
if (strcmp(deferrable, "t") == 0) if (strcmp(deferrable, "t") == 0)
appendPQExpBuffer(&tmpbuf, _(", deferrable")); appendPQExpBufferStr(&tmpbuf, _(", deferrable"));
if (strcmp(deferred, "t") == 0) if (strcmp(deferred, "t") == 0)
appendPQExpBuffer(&tmpbuf, _(", initially deferred")); appendPQExpBufferStr(&tmpbuf, _(", initially deferred"));
if (strcmp(indisreplident, "t") == 0) if (strcmp(indisreplident, "t") == 0)
appendPQExpBuffer(&tmpbuf, _(", replica identity")); appendPQExpBuffer(&tmpbuf, _(", replica identity"));
...@@ -1731,28 +1731,28 @@ describeOneTableDetails(const char *schemaname, ...@@ -1731,28 +1731,28 @@ describeOneTableDetails(const char *schemaname,
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf,
"SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, "); "SELECT c2.relname, i.indisprimary, i.indisunique, i.indisclustered, ");
if (pset.sversion >= 80200) if (pset.sversion >= 80200)
appendPQExpBuffer(&buf, "i.indisvalid, "); appendPQExpBufferStr(&buf, "i.indisvalid, ");
else else
appendPQExpBuffer(&buf, "true as indisvalid, "); appendPQExpBufferStr(&buf, "true as indisvalid, ");
appendPQExpBuffer(&buf, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "); appendPQExpBufferStr(&buf, "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n ");
if (pset.sversion >= 90000) if (pset.sversion >= 90000)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"pg_catalog.pg_get_constraintdef(con.oid, true), " "pg_catalog.pg_get_constraintdef(con.oid, true), "
"contype, condeferrable, condeferred"); "contype, condeferrable, condeferred");
else else
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"null AS constraintdef, null AS contype, " "null AS constraintdef, null AS contype, "
"false AS condeferrable, false AS condeferred"); "false AS condeferrable, false AS condeferred");
if (pset.sversion >= 90400) if (pset.sversion >= 90400)
appendPQExpBuffer(&buf, ", i.indisreplident"); appendPQExpBufferStr(&buf, ", i.indisreplident");
else else
appendPQExpBuffer(&buf, ", false AS indisreplident"); appendPQExpBufferStr(&buf, ", false AS indisreplident");
if (pset.sversion >= 80000) if (pset.sversion >= 80000)
appendPQExpBuffer(&buf, ", c2.reltablespace"); appendPQExpBufferStr(&buf, ", c2.reltablespace");
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"); "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n");
if (pset.sversion >= 90000) if (pset.sversion >= 90000)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n"); " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n");
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n" "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
...@@ -1786,13 +1786,13 @@ describeOneTableDetails(const char *schemaname, ...@@ -1786,13 +1786,13 @@ describeOneTableDetails(const char *schemaname,
/* Label as primary key or unique (but not both) */ /* Label as primary key or unique (but not both) */
if (strcmp(PQgetvalue(result, i, 1), "t") == 0) if (strcmp(PQgetvalue(result, i, 1), "t") == 0)
appendPQExpBuffer(&buf, " PRIMARY KEY,"); appendPQExpBufferStr(&buf, " PRIMARY KEY,");
else if (strcmp(PQgetvalue(result, i, 2), "t") == 0) else if (strcmp(PQgetvalue(result, i, 2), "t") == 0)
{ {
if (strcmp(PQgetvalue(result, i, 7), "u") == 0) if (strcmp(PQgetvalue(result, i, 7), "u") == 0)
appendPQExpBuffer(&buf, " UNIQUE CONSTRAINT,"); appendPQExpBufferStr(&buf, " UNIQUE CONSTRAINT,");
else else
appendPQExpBuffer(&buf, " UNIQUE,"); appendPQExpBufferStr(&buf, " UNIQUE,");
} }
/* Everything after "USING" is echoed verbatim */ /* Everything after "USING" is echoed verbatim */
...@@ -1804,18 +1804,18 @@ describeOneTableDetails(const char *schemaname, ...@@ -1804,18 +1804,18 @@ describeOneTableDetails(const char *schemaname,
/* Need these for deferrable PK/UNIQUE indexes */ /* Need these for deferrable PK/UNIQUE indexes */
if (strcmp(PQgetvalue(result, i, 8), "t") == 0) if (strcmp(PQgetvalue(result, i, 8), "t") == 0)
appendPQExpBuffer(&buf, " DEFERRABLE"); appendPQExpBufferStr(&buf, " DEFERRABLE");
if (strcmp(PQgetvalue(result, i, 9), "t") == 0) if (strcmp(PQgetvalue(result, i, 9), "t") == 0)
appendPQExpBuffer(&buf, " INITIALLY DEFERRED"); appendPQExpBufferStr(&buf, " INITIALLY DEFERRED");
} }
/* Add these for all cases */ /* Add these for all cases */
if (strcmp(PQgetvalue(result, i, 3), "t") == 0) if (strcmp(PQgetvalue(result, i, 3), "t") == 0)
appendPQExpBuffer(&buf, " CLUSTER"); appendPQExpBufferStr(&buf, " CLUSTER");
if (strcmp(PQgetvalue(result, i, 4), "t") != 0) if (strcmp(PQgetvalue(result, i, 4), "t") != 0)
appendPQExpBuffer(&buf, " INVALID"); appendPQExpBufferStr(&buf, " INVALID");
if (strcmp(PQgetvalue(result, i, 10), "t") == 0) if (strcmp(PQgetvalue(result, i, 10), "t") == 0)
appendPQExpBuffer(&buf, " REPLICA IDENTITY"); appendPQExpBuffer(&buf, " REPLICA IDENTITY");
...@@ -2079,17 +2079,17 @@ describeOneTableDetails(const char *schemaname, ...@@ -2079,17 +2079,17 @@ describeOneTableDetails(const char *schemaname,
(pset.sversion >= 90000 ? ", true" : ""), (pset.sversion >= 90000 ? ", true" : ""),
oid); oid);
if (pset.sversion >= 90000) if (pset.sversion >= 90000)
appendPQExpBuffer(&buf, "NOT t.tgisinternal"); appendPQExpBufferStr(&buf, "NOT t.tgisinternal");
else if (pset.sversion >= 80300) else if (pset.sversion >= 80300)
appendPQExpBuffer(&buf, "t.tgconstraint = 0"); appendPQExpBufferStr(&buf, "t.tgconstraint = 0");
else else
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"(NOT tgisconstraint " "(NOT tgisconstraint "
" OR NOT EXISTS" " OR NOT EXISTS"
" (SELECT 1 FROM pg_catalog.pg_depend d " " (SELECT 1 FROM pg_catalog.pg_depend d "
" JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) " " JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
" WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))"); " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))");
appendPQExpBuffer(&buf, "\nORDER BY 1;"); appendPQExpBufferStr(&buf, "\nORDER BY 1;");
result = PSQLexec(buf.data, false); result = PSQLexec(buf.data, false);
if (!result) if (!result)
...@@ -2252,7 +2252,7 @@ describeOneTableDetails(const char *schemaname, ...@@ -2252,7 +2252,7 @@ describeOneTableDetails(const char *schemaname,
printfPQExpBuffer(&buf, "%*s %s", printfPQExpBuffer(&buf, "%*s %s",
sw, "", PQgetvalue(result, i, 0)); sw, "", PQgetvalue(result, i, 0));
if (i < tuples - 1) if (i < tuples - 1)
appendPQExpBuffer(&buf, ","); appendPQExpBufferStr(&buf, ",");
printTableAddFooter(&cont, buf.data); printTableAddFooter(&cont, buf.data);
} }
...@@ -2296,7 +2296,7 @@ describeOneTableDetails(const char *schemaname, ...@@ -2296,7 +2296,7 @@ describeOneTableDetails(const char *schemaname,
printfPQExpBuffer(&buf, "%*s %s", printfPQExpBuffer(&buf, "%*s %s",
ctw, "", PQgetvalue(result, i, 0)); ctw, "", PQgetvalue(result, i, 0));
if (i < tuples - 1) if (i < tuples - 1)
appendPQExpBuffer(&buf, ","); appendPQExpBufferChar(&buf, ',');
printTableAddFooter(&cont, buf.data); printTableAddFooter(&cont, buf.data);
} }
...@@ -2506,7 +2506,7 @@ describeRoles(const char *pattern, bool verbose) ...@@ -2506,7 +2506,7 @@ describeRoles(const char *pattern, bool verbose)
NULL, "u.usename", NULL, NULL); NULL, "u.usename", NULL, NULL);
} }
appendPQExpBuffer(&buf, "ORDER BY 1;"); appendPQExpBufferStr(&buf, "ORDER BY 1;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
if (!res) if (!res)
...@@ -2552,10 +2552,10 @@ describeRoles(const char *pattern, bool verbose) ...@@ -2552,10 +2552,10 @@ describeRoles(const char *pattern, bool verbose)
if (conns >= 0) if (conns >= 0)
{ {
if (buf.len > 0) if (buf.len > 0)
appendPQExpBufferStr(&buf, "\n"); appendPQExpBufferChar(&buf, '\n');
if (conns == 0) if (conns == 0)
appendPQExpBuffer(&buf, _("No connections")); appendPQExpBufferStr(&buf, _("No connections"));
else else
appendPQExpBuffer(&buf, ngettext("%d connection", appendPQExpBuffer(&buf, ngettext("%d connection",
"%d connections", "%d connections",
...@@ -2754,36 +2754,36 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys ...@@ -2754,36 +2754,36 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
gettext_noop("Description")); gettext_noop("Description"));
} }
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_class c" "\nFROM pg_catalog.pg_class c"
"\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace"); "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
if (showIndexes) if (showIndexes)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid" "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
"\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid"); "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
appendPQExpBuffer(&buf, "\nWHERE c.relkind IN ("); appendPQExpBufferStr(&buf, "\nWHERE c.relkind IN (");
if (showTables) if (showTables)
appendPQExpBuffer(&buf, "'r',"); appendPQExpBufferStr(&buf, "'r',");
if (showViews) if (showViews)
appendPQExpBuffer(&buf, "'v',"); appendPQExpBufferStr(&buf, "'v',");
if (showMatViews) if (showMatViews)
appendPQExpBuffer(&buf, "'m',"); appendPQExpBufferStr(&buf, "'m',");
if (showIndexes) if (showIndexes)
appendPQExpBuffer(&buf, "'i',"); appendPQExpBufferStr(&buf, "'i',");
if (showSeq) if (showSeq)
appendPQExpBuffer(&buf, "'S',"); appendPQExpBufferStr(&buf, "'S',");
if (showSystem || pattern) if (showSystem || pattern)
appendPQExpBuffer(&buf, "'s',"); /* was RELKIND_SPECIAL in <= appendPQExpBufferStr(&buf, "'s',"); /* was RELKIND_SPECIAL in <=
* 8.1 */ * 8.1 */
if (showForeign) if (showForeign)
appendPQExpBuffer(&buf, "'f',"); appendPQExpBufferStr(&buf, "'f',");
appendPQExpBuffer(&buf, "''"); /* dummy */ appendPQExpBufferStr(&buf, "''"); /* dummy */
appendPQExpBuffer(&buf, ")\n"); appendPQExpBufferStr(&buf, ")\n");
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
/* /*
...@@ -2792,13 +2792,13 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys ...@@ -2792,13 +2792,13 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
* in any case; it seems a bit confusing to allow their indexes to be * in any case; it seems a bit confusing to allow their indexes to be
* shown. Use plain \d if you really need to look at a TOAST table/index. * shown. Use plain \d if you really need to look at a TOAST table/index.
*/ */
appendPQExpBuffer(&buf, " AND n.nspname !~ '^pg_toast'\n"); appendPQExpBufferStr(&buf, " AND n.nspname !~ '^pg_toast'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false, processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "c.relname", NULL, "n.nspname", "c.relname", NULL,
"pg_catalog.pg_table_is_visible(c.oid)"); "pg_catalog.pg_table_is_visible(c.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1,2;"); appendPQExpBufferStr(&buf, "ORDER BY 1,2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -2881,10 +2881,10 @@ listLanguages(const char *pattern, bool verbose, bool showSystem) ...@@ -2881,10 +2881,10 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
NULL, "l.lanname", NULL, NULL); NULL, "l.lanname", NULL, NULL);
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, "WHERE l.lanplcallfoid != 0\n"); appendPQExpBufferStr(&buf, "WHERE l.lanplcallfoid != 0\n");
appendPQExpBuffer(&buf, "ORDER BY 1;"); appendPQExpBufferStr(&buf, "ORDER BY 1;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -2926,7 +2926,7 @@ listDomains(const char *pattern, bool verbose, bool showSystem) ...@@ -2926,7 +2926,7 @@ listDomains(const char *pattern, bool verbose, bool showSystem)
gettext_noop("Type")); gettext_noop("Type"));
if (pset.sversion >= 90100) if (pset.sversion >= 90100)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" COALESCE((SELECT ' collate ' || c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n" " COALESCE((SELECT ' collate ' || c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
" WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation), '') ||\n"); " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation), '') ||\n");
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
...@@ -2943,7 +2943,7 @@ listDomains(const char *pattern, bool verbose, bool showSystem) ...@@ -2943,7 +2943,7 @@ listDomains(const char *pattern, bool verbose, bool showSystem)
{ {
if (pset.sversion >= 90200) if (pset.sversion >= 90200)
{ {
appendPQExpBuffer(&buf, ",\n "); appendPQExpBufferStr(&buf, ",\n ");
printACLColumn(&buf, "t.typacl"); printACLColumn(&buf, "t.typacl");
} }
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
...@@ -2951,27 +2951,27 @@ listDomains(const char *pattern, bool verbose, bool showSystem) ...@@ -2951,27 +2951,27 @@ listDomains(const char *pattern, bool verbose, bool showSystem)
gettext_noop("Description")); gettext_noop("Description"));
} }
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_type t\n" "\nFROM pg_catalog.pg_type t\n"
" LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"); " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
if (verbose) if (verbose)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" LEFT JOIN pg_catalog.pg_description d " " LEFT JOIN pg_catalog.pg_description d "
"ON d.classoid = t.tableoid AND d.objoid = t.oid " "ON d.classoid = t.tableoid AND d.objoid = t.oid "
"AND d.objsubid = 0\n"); "AND d.objsubid = 0\n");
appendPQExpBuffer(&buf, "WHERE t.typtype = 'd'\n"); appendPQExpBufferStr(&buf, "WHERE t.typtype = 'd'\n");
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false, processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "t.typname", NULL, "n.nspname", "t.typname", NULL,
"pg_catalog.pg_type_is_visible(t.oid)"); "pg_catalog.pg_type_is_visible(t.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3022,29 +3022,29 @@ listConversions(const char *pattern, bool verbose, bool showSystem) ...@@ -3022,29 +3022,29 @@ listConversions(const char *pattern, bool verbose, bool showSystem)
",\n d.description AS \"%s\"", ",\n d.description AS \"%s\"",
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_conversion c\n" "\nFROM pg_catalog.pg_conversion c\n"
" JOIN pg_catalog.pg_namespace n " " JOIN pg_catalog.pg_namespace n "
"ON n.oid = c.connamespace\n"); "ON n.oid = c.connamespace\n");
if (verbose) if (verbose)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"LEFT JOIN pg_catalog.pg_description d " "LEFT JOIN pg_catalog.pg_description d "
"ON d.classoid = c.tableoid\n" "ON d.classoid = c.tableoid\n"
" AND d.objoid = c.oid " " AND d.objoid = c.oid "
"AND d.objsubid = 0\n"); "AND d.objsubid = 0\n");
appendPQExpBuffer(&buf, "WHERE true\n"); appendPQExpBufferStr(&buf, "WHERE true\n");
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false, processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "c.conname", NULL, "n.nspname", "c.conname", NULL,
"pg_catalog.pg_conversion_is_visible(c.oid)"); "pg_catalog.pg_conversion_is_visible(c.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3099,13 +3099,13 @@ listEventTriggers(const char *pattern, bool verbose) ...@@ -3099,13 +3099,13 @@ listEventTriggers(const char *pattern, bool verbose)
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"", ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_event_trigger e "); "\nFROM pg_event_trigger e ");
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
NULL, "evtname", NULL, NULL); NULL, "evtname", NULL, NULL);
appendPQExpBuffer(&buf, "ORDER BY 1"); appendPQExpBufferStr(&buf, "ORDER BY 1");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3167,7 +3167,7 @@ listCasts(const char *pattern, bool verbose) ...@@ -3167,7 +3167,7 @@ listCasts(const char *pattern, bool verbose)
",\n d.description AS \"%s\"\n", ",\n d.description AS \"%s\"\n",
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n" "FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
" ON c.castfunc = p.oid\n" " ON c.castfunc = p.oid\n"
" LEFT JOIN pg_catalog.pg_type ts\n" " LEFT JOIN pg_catalog.pg_type ts\n"
...@@ -3180,12 +3180,12 @@ listCasts(const char *pattern, bool verbose) ...@@ -3180,12 +3180,12 @@ listCasts(const char *pattern, bool verbose)
" ON nt.oid = tt.typnamespace\n"); " ON nt.oid = tt.typnamespace\n");
if (verbose) if (verbose)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" LEFT JOIN pg_catalog.pg_description d\n" " LEFT JOIN pg_catalog.pg_description d\n"
" ON d.classoid = c.tableoid AND d.objoid = " " ON d.classoid = c.tableoid AND d.objoid = "
"c.oid AND d.objsubid = 0\n"); "c.oid AND d.objsubid = 0\n");
appendPQExpBuffer(&buf, "WHERE ( (true"); appendPQExpBufferStr(&buf, "WHERE ( (true");
/* /*
* Match name pattern against either internal or external name of either * Match name pattern against either internal or external name of either
...@@ -3196,14 +3196,14 @@ listCasts(const char *pattern, bool verbose) ...@@ -3196,14 +3196,14 @@ listCasts(const char *pattern, bool verbose)
"pg_catalog.format_type(ts.oid, NULL)", "pg_catalog.format_type(ts.oid, NULL)",
"pg_catalog.pg_type_is_visible(ts.oid)"); "pg_catalog.pg_type_is_visible(ts.oid)");
appendPQExpBuffer(&buf, ") OR (true"); appendPQExpBufferStr(&buf, ") OR (true");
processSQLNamePattern(pset.db, &buf, pattern, true, false, processSQLNamePattern(pset.db, &buf, pattern, true, false,
"nt.nspname", "tt.typname", "nt.nspname", "tt.typname",
"pg_catalog.format_type(tt.oid, NULL)", "pg_catalog.format_type(tt.oid, NULL)",
"pg_catalog.pg_type_is_visible(tt.oid)"); "pg_catalog.pg_type_is_visible(tt.oid)");
appendPQExpBuffer(&buf, ") )\nORDER BY 1, 2;"); appendPQExpBufferStr(&buf, ") )\nORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3258,12 +3258,12 @@ listCollations(const char *pattern, bool verbose, bool showSystem) ...@@ -3258,12 +3258,12 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"", ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n" "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
"WHERE n.oid = c.collnamespace\n"); "WHERE n.oid = c.collnamespace\n");
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, " AND n.nspname <> 'pg_catalog'\n" appendPQExpBufferStr(&buf, " AND n.nspname <> 'pg_catalog'\n"
" AND n.nspname <> 'information_schema'\n"); " AND n.nspname <> 'information_schema'\n");
/* /*
...@@ -3272,13 +3272,13 @@ listCollations(const char *pattern, bool verbose, bool showSystem) ...@@ -3272,13 +3272,13 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
* unusable collations, so you will need to hack name pattern processing * unusable collations, so you will need to hack name pattern processing
* somehow to avoid inconsistent behavior. * somehow to avoid inconsistent behavior.
*/ */
appendPQExpBuffer(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n"); appendPQExpBufferStr(&buf, " AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
processSQLNamePattern(pset.db, &buf, pattern, true, false, processSQLNamePattern(pset.db, &buf, pattern, true, false,
"n.nspname", "c.collname", NULL, "n.nspname", "c.collname", NULL,
"pg_catalog.pg_collation_is_visible(c.oid)"); "pg_catalog.pg_collation_is_visible(c.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3317,7 +3317,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem) ...@@ -3317,7 +3317,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem)
if (verbose) if (verbose)
{ {
appendPQExpBuffer(&buf, ",\n "); appendPQExpBufferStr(&buf, ",\n ");
printACLColumn(&buf, "n.nspacl"); printACLColumn(&buf, "n.nspacl");
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"", ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
...@@ -3328,7 +3328,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem) ...@@ -3328,7 +3328,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem)
"\nFROM pg_catalog.pg_namespace n\n"); "\nFROM pg_catalog.pg_namespace n\n");
if (!showSystem && !pattern) if (!showSystem && !pattern)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n"); "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
processSQLNamePattern(pset.db, &buf, pattern, processSQLNamePattern(pset.db, &buf, pattern,
...@@ -3336,7 +3336,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem) ...@@ -3336,7 +3336,7 @@ listSchemas(const char *pattern, bool verbose, bool showSystem)
NULL, "n.nspname", NULL, NULL, "n.nspname", NULL,
NULL); NULL);
appendPQExpBuffer(&buf, "ORDER BY 1;"); appendPQExpBufferStr(&buf, "ORDER BY 1;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3393,7 +3393,7 @@ listTSParsers(const char *pattern, bool verbose) ...@@ -3393,7 +3393,7 @@ listTSParsers(const char *pattern, bool verbose)
"n.nspname", "p.prsname", NULL, "n.nspname", "p.prsname", NULL,
"pg_catalog.pg_ts_parser_is_visible(p.oid)"); "pg_catalog.pg_ts_parser_is_visible(p.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3434,7 +3434,7 @@ listTSParsersVerbose(const char *pattern) ...@@ -3434,7 +3434,7 @@ listTSParsersVerbose(const char *pattern)
"n.nspname", "p.prsname", NULL, "n.nspname", "p.prsname", NULL,
"pg_catalog.pg_ts_parser_is_visible(p.oid)"); "pg_catalog.pg_ts_parser_is_visible(p.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3630,14 +3630,14 @@ listTSDictionaries(const char *pattern, bool verbose) ...@@ -3630,14 +3630,14 @@ listTSDictionaries(const char *pattern, bool verbose)
" pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n", " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, "FROM pg_catalog.pg_ts_dict d\n" appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_dict d\n"
"LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n"); "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
"n.nspname", "d.dictname", NULL, "n.nspname", "d.dictname", NULL,
"pg_catalog.pg_ts_dict_is_visible(d.oid)"); "pg_catalog.pg_ts_dict_is_visible(d.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3698,14 +3698,14 @@ listTSTemplates(const char *pattern, bool verbose) ...@@ -3698,14 +3698,14 @@ listTSTemplates(const char *pattern, bool verbose)
gettext_noop("Name"), gettext_noop("Name"),
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, "FROM pg_catalog.pg_ts_template t\n" appendPQExpBufferStr(&buf, "FROM pg_catalog.pg_ts_template t\n"
"LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n"); "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
"n.nspname", "t.tmplname", NULL, "n.nspname", "t.tmplname", NULL,
"pg_catalog.pg_ts_template_is_visible(t.oid)"); "pg_catalog.pg_ts_template_is_visible(t.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3762,7 +3762,7 @@ listTSConfigs(const char *pattern, bool verbose) ...@@ -3762,7 +3762,7 @@ listTSConfigs(const char *pattern, bool verbose)
"n.nspname", "c.cfgname", NULL, "n.nspname", "c.cfgname", NULL,
"pg_catalog.pg_ts_config_is_visible(c.oid)"); "pg_catalog.pg_ts_config_is_visible(c.oid)");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3804,7 +3804,7 @@ listTSConfigsVerbose(const char *pattern) ...@@ -3804,7 +3804,7 @@ listTSConfigsVerbose(const char *pattern)
"n.nspname", "c.cfgname", NULL, "n.nspname", "c.cfgname", NULL,
"pg_catalog.pg_ts_config_is_visible(c.oid)"); "pg_catalog.pg_ts_config_is_visible(c.oid)");
appendPQExpBuffer(&buf, "ORDER BY 3, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 3, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -3955,7 +3955,7 @@ listForeignDataWrappers(const char *pattern, bool verbose) ...@@ -3955,7 +3955,7 @@ listForeignDataWrappers(const char *pattern, bool verbose)
if (verbose) if (verbose)
{ {
appendPQExpBuffer(&buf, ",\n "); appendPQExpBufferStr(&buf, ",\n ");
printACLColumn(&buf, "fdwacl"); printACLColumn(&buf, "fdwacl");
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE " ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
...@@ -3972,10 +3972,10 @@ listForeignDataWrappers(const char *pattern, bool verbose) ...@@ -3972,10 +3972,10 @@ listForeignDataWrappers(const char *pattern, bool verbose)
gettext_noop("Description")); gettext_noop("Description"));
} }
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_foreign_data_wrapper fdw\n");
if (verbose && pset.sversion >= 90100) if (verbose && pset.sversion >= 90100)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"LEFT JOIN pg_catalog.pg_description d\n" "LEFT JOIN pg_catalog.pg_description d\n"
" ON d.classoid = fdw.tableoid " " ON d.classoid = fdw.tableoid "
"AND d.objoid = fdw.oid AND d.objsubid = 0\n"); "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
...@@ -3983,7 +3983,7 @@ listForeignDataWrappers(const char *pattern, bool verbose) ...@@ -3983,7 +3983,7 @@ listForeignDataWrappers(const char *pattern, bool verbose)
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
NULL, "fdwname", NULL, NULL); NULL, "fdwname", NULL, NULL);
appendPQExpBuffer(&buf, "ORDER BY 1;"); appendPQExpBufferStr(&buf, "ORDER BY 1;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -4030,7 +4030,7 @@ listForeignServers(const char *pattern, bool verbose) ...@@ -4030,7 +4030,7 @@ listForeignServers(const char *pattern, bool verbose)
if (verbose) if (verbose)
{ {
appendPQExpBuffer(&buf, ",\n "); appendPQExpBufferStr(&buf, ",\n ");
printACLColumn(&buf, "s.srvacl"); printACLColumn(&buf, "s.srvacl");
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
",\n" ",\n"
...@@ -4049,12 +4049,12 @@ listForeignServers(const char *pattern, bool verbose) ...@@ -4049,12 +4049,12 @@ listForeignServers(const char *pattern, bool verbose)
gettext_noop("Description")); gettext_noop("Description"));
} }
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_foreign_server s\n" "\nFROM pg_catalog.pg_foreign_server s\n"
" JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n"); " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
if (verbose) if (verbose)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"LEFT JOIN pg_description d\n " "LEFT JOIN pg_description d\n "
"ON d.classoid = s.tableoid AND d.objoid = s.oid " "ON d.classoid = s.tableoid AND d.objoid = s.oid "
"AND d.objsubid = 0\n"); "AND d.objsubid = 0\n");
...@@ -4062,7 +4062,7 @@ listForeignServers(const char *pattern, bool verbose) ...@@ -4062,7 +4062,7 @@ listForeignServers(const char *pattern, bool verbose)
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
NULL, "s.srvname", NULL, NULL); NULL, "s.srvname", NULL, NULL);
appendPQExpBuffer(&buf, "ORDER BY 1;"); appendPQExpBufferStr(&buf, "ORDER BY 1;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -4115,12 +4115,12 @@ listUserMappings(const char *pattern, bool verbose) ...@@ -4115,12 +4115,12 @@ listUserMappings(const char *pattern, bool verbose)
" END AS \"%s\"", " END AS \"%s\"",
gettext_noop("FDW Options")); gettext_noop("FDW Options"));
appendPQExpBuffer(&buf, "\nFROM pg_catalog.pg_user_mappings um\n"); appendPQExpBufferStr(&buf, "\nFROM pg_catalog.pg_user_mappings um\n");
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
NULL, "um.srvname", "um.usename", NULL); NULL, "um.srvname", "um.usename", NULL);
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -4177,7 +4177,7 @@ listForeignTables(const char *pattern, bool verbose) ...@@ -4177,7 +4177,7 @@ listForeignTables(const char *pattern, bool verbose)
gettext_noop("FDW Options"), gettext_noop("FDW Options"),
gettext_noop("Description")); gettext_noop("Description"));
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
"\nFROM pg_catalog.pg_foreign_table ft\n" "\nFROM pg_catalog.pg_foreign_table ft\n"
" INNER JOIN pg_catalog.pg_class c" " INNER JOIN pg_catalog.pg_class c"
" ON c.oid = ft.ftrelid\n" " ON c.oid = ft.ftrelid\n"
...@@ -4186,7 +4186,7 @@ listForeignTables(const char *pattern, bool verbose) ...@@ -4186,7 +4186,7 @@ listForeignTables(const char *pattern, bool verbose)
" INNER JOIN pg_catalog.pg_foreign_server s" " INNER JOIN pg_catalog.pg_foreign_server s"
" ON s.oid = ft.ftserver\n"); " ON s.oid = ft.ftserver\n");
if (verbose) if (verbose)
appendPQExpBuffer(&buf, appendPQExpBufferStr(&buf,
" LEFT JOIN pg_catalog.pg_description d\n" " LEFT JOIN pg_catalog.pg_description d\n"
" ON d.classoid = c.tableoid AND " " ON d.classoid = c.tableoid AND "
"d.objoid = c.oid AND d.objsubid = 0\n"); "d.objoid = c.oid AND d.objsubid = 0\n");
...@@ -4194,7 +4194,7 @@ listForeignTables(const char *pattern, bool verbose) ...@@ -4194,7 +4194,7 @@ listForeignTables(const char *pattern, bool verbose)
processSQLNamePattern(pset.db, &buf, pattern, false, false, processSQLNamePattern(pset.db, &buf, pattern, false, false,
NULL, "n.nspname", "c.relname", NULL); NULL, "n.nspname", "c.relname", NULL);
appendPQExpBuffer(&buf, "ORDER BY 1, 2;"); appendPQExpBufferStr(&buf, "ORDER BY 1, 2;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -4248,7 +4248,7 @@ listExtensions(const char *pattern) ...@@ -4248,7 +4248,7 @@ listExtensions(const char *pattern)
NULL, "e.extname", NULL, NULL, "e.extname", NULL,
NULL); NULL);
appendPQExpBuffer(&buf, "ORDER BY 1;"); appendPQExpBufferStr(&buf, "ORDER BY 1;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
...@@ -4294,7 +4294,7 @@ listExtensionContents(const char *pattern) ...@@ -4294,7 +4294,7 @@ listExtensionContents(const char *pattern)
NULL, "e.extname", NULL, NULL, "e.extname", NULL,
NULL); NULL);
appendPQExpBuffer(&buf, "ORDER BY 1;"); appendPQExpBufferStr(&buf, "ORDER BY 1;");
res = PSQLexec(buf.data, false); res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf); termPQExpBuffer(&buf);
......
...@@ -3613,7 +3613,7 @@ _complete_from_query(int is_schema_query, const char *text, int state) ...@@ -3613,7 +3613,7 @@ _complete_from_query(int is_schema_query, const char *text, int state)
"pg_catalog.pg_class c") == 0 && "pg_catalog.pg_class c") == 0 &&
strncmp(text, "pg_", 3) !=0) strncmp(text, "pg_", 3) !=0)
{ {
appendPQExpBuffer(&query_buffer, appendPQExpBufferStr(&query_buffer,
" AND c.relnamespace <> (SELECT oid FROM" " AND c.relnamespace <> (SELECT oid FROM"
" pg_catalog.pg_namespace WHERE nspname = 'pg_catalog')"); " pg_catalog.pg_namespace WHERE nspname = 'pg_catalog')");
} }
......
...@@ -196,12 +196,12 @@ cluster_one_database(const char *dbname, bool verbose, const char *table, ...@@ -196,12 +196,12 @@ cluster_one_database(const char *dbname, bool verbose, const char *table,
initPQExpBuffer(&sql); initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "CLUSTER"); appendPQExpBufferStr(&sql, "CLUSTER");
if (verbose) if (verbose)
appendPQExpBuffer(&sql, " VERBOSE"); appendPQExpBufferStr(&sql, " VERBOSE");
if (table) if (table)
appendPQExpBuffer(&sql, " %s", table); appendPQExpBuffer(&sql, " %s", table);
appendPQExpBuffer(&sql, ";\n"); appendPQExpBufferStr(&sql, ";\n");
conn = connectDatabase(dbname, host, port, username, prompt_password, conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false); progname, false);
......
...@@ -195,7 +195,7 @@ main(int argc, char *argv[]) ...@@ -195,7 +195,7 @@ main(int argc, char *argv[])
if (lc_ctype) if (lc_ctype)
appendPQExpBuffer(&sql, " LC_CTYPE '%s'", lc_ctype); appendPQExpBuffer(&sql, " LC_CTYPE '%s'", lc_ctype);
appendPQExpBuffer(&sql, ";\n"); appendPQExpBufferStr(&sql, ";\n");
/* No point in trying to use postgres db when creating postgres db. */ /* No point in trying to use postgres db when creating postgres db. */
if (maintenance_db == NULL && strcmp(dbname, "postgres") == 0) if (maintenance_db == NULL && strcmp(dbname, "postgres") == 0)
...@@ -222,7 +222,7 @@ main(int argc, char *argv[]) ...@@ -222,7 +222,7 @@ main(int argc, char *argv[])
{ {
printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname)); printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname));
appendStringLiteralConn(&sql, comment, conn); appendStringLiteralConn(&sql, comment, conn);
appendPQExpBuffer(&sql, ";\n"); appendPQExpBufferStr(&sql, ";\n");
if (echo) if (echo)
printf("%s", sql.data); printf("%s", sql.data);
......
...@@ -254,10 +254,10 @@ main(int argc, char *argv[]) ...@@ -254,10 +254,10 @@ main(int argc, char *argv[])
if (newpassword) if (newpassword)
{ {
if (encrypted == TRI_YES) if (encrypted == TRI_YES)
appendPQExpBuffer(&sql, " ENCRYPTED"); appendPQExpBufferStr(&sql, " ENCRYPTED");
if (encrypted == TRI_NO) if (encrypted == TRI_NO)
appendPQExpBuffer(&sql, " UNENCRYPTED"); appendPQExpBufferStr(&sql, " UNENCRYPTED");
appendPQExpBuffer(&sql, " PASSWORD "); appendPQExpBufferStr(&sql, " PASSWORD ");
if (encrypted != TRI_NO) if (encrypted != TRI_NO)
{ {
...@@ -277,32 +277,32 @@ main(int argc, char *argv[]) ...@@ -277,32 +277,32 @@ main(int argc, char *argv[])
appendStringLiteralConn(&sql, newpassword, conn); appendStringLiteralConn(&sql, newpassword, conn);
} }
if (superuser == TRI_YES) if (superuser == TRI_YES)
appendPQExpBuffer(&sql, " SUPERUSER"); appendPQExpBufferStr(&sql, " SUPERUSER");
if (superuser == TRI_NO) if (superuser == TRI_NO)
appendPQExpBuffer(&sql, " NOSUPERUSER"); appendPQExpBufferStr(&sql, " NOSUPERUSER");
if (createdb == TRI_YES) if (createdb == TRI_YES)
appendPQExpBuffer(&sql, " CREATEDB"); appendPQExpBufferStr(&sql, " CREATEDB");
if (createdb == TRI_NO) if (createdb == TRI_NO)
appendPQExpBuffer(&sql, " NOCREATEDB"); appendPQExpBufferStr(&sql, " NOCREATEDB");
if (createrole == TRI_YES) if (createrole == TRI_YES)
appendPQExpBuffer(&sql, " CREATEROLE"); appendPQExpBufferStr(&sql, " CREATEROLE");
if (createrole == TRI_NO) if (createrole == TRI_NO)
appendPQExpBuffer(&sql, " NOCREATEROLE"); appendPQExpBufferStr(&sql, " NOCREATEROLE");
if (inherit == TRI_YES) if (inherit == TRI_YES)
appendPQExpBuffer(&sql, " INHERIT"); appendPQExpBufferStr(&sql, " INHERIT");
if (inherit == TRI_NO) if (inherit == TRI_NO)
appendPQExpBuffer(&sql, " NOINHERIT"); appendPQExpBufferStr(&sql, " NOINHERIT");
if (login == TRI_YES) if (login == TRI_YES)
appendPQExpBuffer(&sql, " LOGIN"); appendPQExpBufferStr(&sql, " LOGIN");
if (login == TRI_NO) if (login == TRI_NO)
appendPQExpBuffer(&sql, " NOLOGIN"); appendPQExpBufferStr(&sql, " NOLOGIN");
if (replication == TRI_YES) if (replication == TRI_YES)
appendPQExpBuffer(&sql, " REPLICATION"); appendPQExpBufferStr(&sql, " REPLICATION");
if (replication == TRI_NO) if (replication == TRI_NO)
appendPQExpBuffer(&sql, " NOREPLICATION"); appendPQExpBufferStr(&sql, " NOREPLICATION");
if (conn_limit != NULL) if (conn_limit != NULL)
appendPQExpBuffer(&sql, " CONNECTION LIMIT %s", conn_limit); appendPQExpBuffer(&sql, " CONNECTION LIMIT %s", conn_limit);
appendPQExpBuffer(&sql, ";\n"); appendPQExpBufferStr(&sql, ";\n");
if (echo) if (echo)
printf("%s", sql.data); printf("%s", sql.data);
......
...@@ -246,14 +246,14 @@ reindex_one_database(const char *name, const char *dbname, const char *type, ...@@ -246,14 +246,14 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
initPQExpBuffer(&sql); initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "REINDEX"); appendPQExpBufferStr(&sql, "REINDEX");
if (strcmp(type, "TABLE") == 0) if (strcmp(type, "TABLE") == 0)
appendPQExpBuffer(&sql, " TABLE %s", name); appendPQExpBuffer(&sql, " TABLE %s", name);
else if (strcmp(type, "INDEX") == 0) else if (strcmp(type, "INDEX") == 0)
appendPQExpBuffer(&sql, " INDEX %s", name); appendPQExpBuffer(&sql, " INDEX %s", name);
else if (strcmp(type, "DATABASE") == 0) else if (strcmp(type, "DATABASE") == 0)
appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name)); appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name));
appendPQExpBuffer(&sql, ";\n"); appendPQExpBufferStr(&sql, ";\n");
conn = connectDatabase(dbname, host, port, username, prompt_password, conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false); progname, false);
......
...@@ -248,13 +248,13 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz ...@@ -248,13 +248,13 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
if (analyze_only) if (analyze_only)
{ {
appendPQExpBuffer(&sql, "ANALYZE"); appendPQExpBufferStr(&sql, "ANALYZE");
if (verbose) if (verbose)
appendPQExpBuffer(&sql, " VERBOSE"); appendPQExpBufferStr(&sql, " VERBOSE");
} }
else else
{ {
appendPQExpBuffer(&sql, "VACUUM"); appendPQExpBufferStr(&sql, "VACUUM");
if (PQserverVersion(conn) >= 90000) if (PQserverVersion(conn) >= 90000)
{ {
const char *paren = " ("; const char *paren = " (";
...@@ -282,23 +282,23 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz ...@@ -282,23 +282,23 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
sep = comma; sep = comma;
} }
if (sep != paren) if (sep != paren)
appendPQExpBuffer(&sql, ")"); appendPQExpBufferStr(&sql, ")");
} }
else else
{ {
if (full) if (full)
appendPQExpBuffer(&sql, " FULL"); appendPQExpBufferStr(&sql, " FULL");
if (freeze) if (freeze)
appendPQExpBuffer(&sql, " FREEZE"); appendPQExpBufferStr(&sql, " FREEZE");
if (verbose) if (verbose)
appendPQExpBuffer(&sql, " VERBOSE"); appendPQExpBufferStr(&sql, " VERBOSE");
if (and_analyze) if (and_analyze)
appendPQExpBuffer(&sql, " ANALYZE"); appendPQExpBufferStr(&sql, " ANALYZE");
} }
} }
if (table) if (table)
appendPQExpBuffer(&sql, " %s", table); appendPQExpBuffer(&sql, " %s", table);
appendPQExpBuffer(&sql, ";\n"); appendPQExpBufferStr(&sql, ";\n");
if (!executeMaintenanceCommand(conn, sql.data, echo)) if (!executeMaintenanceCommand(conn, sql.data, echo))
{ {
......
...@@ -1601,7 +1601,7 @@ PQconnectPoll(PGconn *conn) ...@@ -1601,7 +1601,7 @@ PQconnectPoll(PGconn *conn)
break; break;
default: default:
appendPQExpBuffer(&conn->errorMessage, appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext( libpq_gettext(
"invalid connection state, " "invalid connection state, "
"probably indicative of memory corruption\n" "probably indicative of memory corruption\n"
...@@ -1695,7 +1695,7 @@ keep_going: /* We will come back to here until there is ...@@ -1695,7 +1695,7 @@ keep_going: /* We will come back to here until there is
if (usekeepalives < 0) if (usekeepalives < 0)
{ {
appendPQExpBuffer(&conn->errorMessage, appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("keepalives parameter must be an integer\n")); libpq_gettext("keepalives parameter must be an integer\n"));
err = 1; err = 1;
} }
...@@ -1920,7 +1920,7 @@ keep_going: /* We will come back to here until there is ...@@ -1920,7 +1920,7 @@ keep_going: /* We will come back to here until there is
* stub * stub
*/ */
if (errno == ENOSYS) if (errno == ENOSYS)
appendPQExpBuffer(&conn->errorMessage, appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("requirepeer parameter is not supported on this platform\n")); libpq_gettext("requirepeer parameter is not supported on this platform\n"));
else else
appendPQExpBuffer(&conn->errorMessage, appendPQExpBuffer(&conn->errorMessage,
...@@ -2084,7 +2084,7 @@ keep_going: /* We will come back to here until there is ...@@ -2084,7 +2084,7 @@ keep_going: /* We will come back to here until there is
* "verify-full" */ * "verify-full" */
{ {
/* Require SSL, but server does not want it */ /* Require SSL, but server does not want it */
appendPQExpBuffer(&conn->errorMessage, appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("server does not support SSL, but SSL was required\n")); libpq_gettext("server does not support SSL, but SSL was required\n"));
goto error_return; goto error_return;
} }
...@@ -2470,7 +2470,7 @@ keep_going: /* We will come back to here until there is ...@@ -2470,7 +2470,7 @@ keep_going: /* We will come back to here until there is
if (res) if (res)
{ {
if (res->resultStatus != PGRES_FATAL_ERROR) if (res->resultStatus != PGRES_FATAL_ERROR)
appendPQExpBuffer(&conn->errorMessage, appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("unexpected message from server during startup\n")); libpq_gettext("unexpected message from server during startup\n"));
else if (conn->send_appname && else if (conn->send_appname &&
(conn->appname || conn->fbappname)) (conn->appname || conn->fbappname))
......
...@@ -204,7 +204,7 @@ main(int argc, char **argv) ...@@ -204,7 +204,7 @@ main(int argc, char **argv)
"AND holder.granted " "AND holder.granted "
"AND holder.pid <> $1 AND holder.pid IN ("); "AND holder.pid <> $1 AND holder.pid IN (");
/* The spec syntax requires at least one session; assume that here. */ /* The spec syntax requires at least one session; assume that here. */
appendPQExpBuffer(&wait_query, "%s", backend_pids[1]); appendPQExpBufferStr(&wait_query, backend_pids[1]);
for (i = 2; i < nconns; i++) for (i = 2; i < nconns; i++)
appendPQExpBuffer(&wait_query, ", %s", backend_pids[i]); appendPQExpBuffer(&wait_query, ", %s", backend_pids[i]);
appendPQExpBufferStr(&wait_query, appendPQExpBufferStr(&wait_query,
......
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