1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-25 21:42:33 +03:00

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

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

David Rowley
This commit is contained in:
Heikki Linnakangas 2013-11-18 18:29:01 +02:00
parent f1df4731ee
commit 32ceba3ea7
15 changed files with 739 additions and 750 deletions

View File

@ -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,
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,
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)
{ {
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,
" %s IS ", " %s IS ",
fmtId(objname)); fmtId(objname));
appendStringLiteralConn(buffer, label, conn); appendStringLiteralConn(buffer, label, conn);
appendPQExpBuffer(buffer, ";\n"); appendPQExpBufferStr(buffer, ";\n");
} }
} }

View File

@ -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)
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)
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)
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
{ {
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);

File diff suppressed because it is too large Load Diff

View File

@ -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[])
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[])
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[])
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[])
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[])
/* 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)
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)
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)
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)
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)
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)
{ {
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)
{ {
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)
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)
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,
*/ */
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)
* 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)
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)
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)
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);
} }

View File

@ -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");

View File

@ -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);

File diff suppressed because it is too large Load Diff

View File

@ -3613,8 +3613,8 @@ _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')");
} }

View File

@ -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);

View File

@ -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[])
{ {
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);

View File

@ -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[])
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);

View File

@ -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);

View File

@ -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
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))
{ {

View File

@ -1601,9 +1601,9 @@ 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"
)); ));
goto error_return; goto error_return;
@ -1695,8 +1695,8 @@ 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;
} }
else if (usekeepalives == 0) else if (usekeepalives == 0)
@ -1920,8 +1920,8 @@ 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,
libpq_gettext("could not get peer credentials: %s\n"), libpq_gettext("could not get peer credentials: %s\n"),
@ -2084,8 +2084,8 @@ 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;
} }
/* Otherwise, proceed with normal startup */ /* Otherwise, proceed with normal startup */
@ -2470,8 +2470,8 @@ 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))
{ {

View File

@ -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,