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)
{
appendPQExpBuffer(lcl_pqexp, "%s.", fmtId(schema));
}
appendPQExpBuffer(lcl_pqexp, "%s", fmtId(id));
appendPQExpBufferStr(lcl_pqexp, fmtId(id));
id_return = getLocalPQExpBuffer();
appendPQExpBuffer(id_return, "%s", lcl_pqexp->data);
appendPQExpBufferStr(id_return, lcl_pqexp->data);
destroyPQExpBuffer(lcl_pqexp);
return id_return->data;
......@@ -625,7 +625,7 @@ buildACLCommands(const char *name, const char *subname,
appendPQExpBuffer(secondsql, "%sGRANT %s ON %s %s TO ",
prefix, privs->data, type, name);
if (grantee->len == 0)
appendPQExpBuffer(secondsql, "PUBLIC;\n");
appendPQExpBufferStr(secondsql, "PUBLIC;\n");
else if (strncmp(grantee->data, "group ",
strlen("group ")) == 0)
appendPQExpBuffer(secondsql, "GROUP %s;\n",
......@@ -638,19 +638,19 @@ buildACLCommands(const char *name, const char *subname,
appendPQExpBuffer(secondsql, "%sGRANT %s ON %s %s TO ",
prefix, privswgo->data, type, name);
if (grantee->len == 0)
appendPQExpBuffer(secondsql, "PUBLIC");
appendPQExpBufferStr(secondsql, "PUBLIC");
else if (strncmp(grantee->data, "group ",
strlen("group ")) == 0)
appendPQExpBuffer(secondsql, "GROUP %s",
fmtId(grantee->data + strlen("group ")));
else
appendPQExpBuffer(secondsql, "%s", fmtId(grantee->data));
appendPQExpBuffer(secondsql, " WITH GRANT OPTION;\n");
appendPQExpBufferStr(secondsql, fmtId(grantee->data));
appendPQExpBufferStr(secondsql, " WITH GRANT OPTION;\n");
}
if (grantor->len > 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)
appendPQExpBufferChar(aclbuf, ',');
appendPQExpBuffer(aclbuf, "%s", keyword);
appendPQExpBufferStr(aclbuf, keyword);
if (subname)
appendPQExpBuffer(aclbuf, "(%s)", subname);
}
......@@ -1205,7 +1205,7 @@ emitShSecLabels(PGconn *conn, PGresult *res, PQExpBuffer buffer,
" %s IS ",
fmtId(objname));
appendStringLiteralConn(buffer, label, conn);
appendPQExpBuffer(buffer, ";\n");
appendPQExpBufferStr(buffer, ";\n");
}
}
......
......@@ -2619,7 +2619,7 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user)
{
PQExpBuffer cmd = createPQExpBuffer();
appendPQExpBuffer(cmd, "SET SESSION AUTHORIZATION ");
appendPQExpBufferStr(cmd, "SET SESSION AUTHORIZATION ");
/*
* SQL requires a string literal here. Might as well be correct.
......@@ -2627,8 +2627,8 @@ _doSetSessionAuth(ArchiveHandle *AH, const char *user)
if (user && *user)
appendStringLiteralAHX(cmd, user, AH);
else
appendPQExpBuffer(cmd, "DEFAULT");
appendPQExpBuffer(cmd, ";");
appendPQExpBufferStr(cmd, "DEFAULT");
appendPQExpBufferChar(cmd, ';');
if (RestoringToDB(AH))
{
......@@ -2798,7 +2798,7 @@ _selectOutputSchema(ArchiveHandle *AH, const char *schemaName)
appendPQExpBuffer(qry, "SET search_path = %s",
fmtId(schemaName));
if (strcmp(schemaName, "pg_catalog") != 0)
appendPQExpBuffer(qry, ", pg_catalog");
appendPQExpBufferStr(qry, ", pg_catalog");
if (RestoringToDB(AH))
{
......@@ -2853,7 +2853,7 @@ _selectTablespace(ArchiveHandle *AH, const char *tablespace)
if (strcmp(want, "") == 0)
{
/* We want the tablespace to be the database's default */
appendPQExpBuffer(qry, "SET default_tablespace = ''");
appendPQExpBufferStr(qry, "SET default_tablespace = ''");
}
else
{
......@@ -3119,7 +3119,7 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
{
PQExpBuffer temp = createPQExpBuffer();
appendPQExpBuffer(temp, "ALTER ");
appendPQExpBufferStr(temp, "ALTER ");
_getObjectDescription(temp, te, AH);
appendPQExpBuffer(temp, " OWNER TO %s;", fmtId(te->owner));
ahprintf(AH, "%s\n\n", temp->data);
......
This diff is collapsed.
This diff is collapsed.
......@@ -2786,7 +2786,7 @@ lookup_function_oid(PGconn *conn, const char *desc, Oid *foid)
PGresult *res;
query = createPQExpBuffer();
printfPQExpBuffer(query, "SELECT ");
appendPQExpBufferStr(query, "SELECT ");
appendStringLiteralConn(query, desc, conn);
appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
strchr(desc, '(') ? "regprocedure" : "regproc");
......
......@@ -362,9 +362,9 @@ do_copy(const char *args)
printfPQExpBuffer(&query, "COPY ");
appendPQExpBufferStr(&query, options->before_tofrom);
if (options->from)
appendPQExpBuffer(&query, " FROM STDIN ");
appendPQExpBufferStr(&query, " FROM STDIN ");
else
appendPQExpBuffer(&query, " TO STDOUT ");
appendPQExpBufferStr(&query, " TO STDOUT ");
if (options->after_tofrom)
appendPQExpBufferStr(&query, options->after_tofrom);
......
This diff is collapsed.
......@@ -3613,8 +3613,8 @@ _complete_from_query(int is_schema_query, const char *text, int state)
"pg_catalog.pg_class c") == 0 &&
strncmp(text, "pg_", 3) !=0)
{
appendPQExpBuffer(&query_buffer,
" AND c.relnamespace <> (SELECT oid FROM"
appendPQExpBufferStr(&query_buffer,
" AND c.relnamespace <> (SELECT oid FROM"
" pg_catalog.pg_namespace WHERE nspname = 'pg_catalog')");
}
......
......@@ -196,12 +196,12 @@ cluster_one_database(const char *dbname, bool verbose, const char *table,
initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "CLUSTER");
appendPQExpBufferStr(&sql, "CLUSTER");
if (verbose)
appendPQExpBuffer(&sql, " VERBOSE");
appendPQExpBufferStr(&sql, " VERBOSE");
if (table)
appendPQExpBuffer(&sql, " %s", table);
appendPQExpBuffer(&sql, ";\n");
appendPQExpBufferStr(&sql, ";\n");
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false);
......
......@@ -195,7 +195,7 @@ main(int argc, char *argv[])
if (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. */
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));
appendStringLiteralConn(&sql, comment, conn);
appendPQExpBuffer(&sql, ";\n");
appendPQExpBufferStr(&sql, ";\n");
if (echo)
printf("%s", sql.data);
......
......@@ -254,10 +254,10 @@ main(int argc, char *argv[])
if (newpassword)
{
if (encrypted == TRI_YES)
appendPQExpBuffer(&sql, " ENCRYPTED");
appendPQExpBufferStr(&sql, " ENCRYPTED");
if (encrypted == TRI_NO)
appendPQExpBuffer(&sql, " UNENCRYPTED");
appendPQExpBuffer(&sql, " PASSWORD ");
appendPQExpBufferStr(&sql, " UNENCRYPTED");
appendPQExpBufferStr(&sql, " PASSWORD ");
if (encrypted != TRI_NO)
{
......@@ -277,32 +277,32 @@ main(int argc, char *argv[])
appendStringLiteralConn(&sql, newpassword, conn);
}
if (superuser == TRI_YES)
appendPQExpBuffer(&sql, " SUPERUSER");
appendPQExpBufferStr(&sql, " SUPERUSER");
if (superuser == TRI_NO)
appendPQExpBuffer(&sql, " NOSUPERUSER");
appendPQExpBufferStr(&sql, " NOSUPERUSER");
if (createdb == TRI_YES)
appendPQExpBuffer(&sql, " CREATEDB");
appendPQExpBufferStr(&sql, " CREATEDB");
if (createdb == TRI_NO)
appendPQExpBuffer(&sql, " NOCREATEDB");
appendPQExpBufferStr(&sql, " NOCREATEDB");
if (createrole == TRI_YES)
appendPQExpBuffer(&sql, " CREATEROLE");
appendPQExpBufferStr(&sql, " CREATEROLE");
if (createrole == TRI_NO)
appendPQExpBuffer(&sql, " NOCREATEROLE");
appendPQExpBufferStr(&sql, " NOCREATEROLE");
if (inherit == TRI_YES)
appendPQExpBuffer(&sql, " INHERIT");
appendPQExpBufferStr(&sql, " INHERIT");
if (inherit == TRI_NO)
appendPQExpBuffer(&sql, " NOINHERIT");
appendPQExpBufferStr(&sql, " NOINHERIT");
if (login == TRI_YES)
appendPQExpBuffer(&sql, " LOGIN");
appendPQExpBufferStr(&sql, " LOGIN");
if (login == TRI_NO)
appendPQExpBuffer(&sql, " NOLOGIN");
appendPQExpBufferStr(&sql, " NOLOGIN");
if (replication == TRI_YES)
appendPQExpBuffer(&sql, " REPLICATION");
appendPQExpBufferStr(&sql, " REPLICATION");
if (replication == TRI_NO)
appendPQExpBuffer(&sql, " NOREPLICATION");
appendPQExpBufferStr(&sql, " NOREPLICATION");
if (conn_limit != NULL)
appendPQExpBuffer(&sql, " CONNECTION LIMIT %s", conn_limit);
appendPQExpBuffer(&sql, ";\n");
appendPQExpBufferStr(&sql, ";\n");
if (echo)
printf("%s", sql.data);
......
......@@ -246,14 +246,14 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "REINDEX");
appendPQExpBufferStr(&sql, "REINDEX");
if (strcmp(type, "TABLE") == 0)
appendPQExpBuffer(&sql, " TABLE %s", name);
else if (strcmp(type, "INDEX") == 0)
appendPQExpBuffer(&sql, " INDEX %s", name);
else if (strcmp(type, "DATABASE") == 0)
appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name));
appendPQExpBuffer(&sql, ";\n");
appendPQExpBufferStr(&sql, ";\n");
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false);
......
......@@ -248,13 +248,13 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
if (analyze_only)
{
appendPQExpBuffer(&sql, "ANALYZE");
appendPQExpBufferStr(&sql, "ANALYZE");
if (verbose)
appendPQExpBuffer(&sql, " VERBOSE");
appendPQExpBufferStr(&sql, " VERBOSE");
}
else
{
appendPQExpBuffer(&sql, "VACUUM");
appendPQExpBufferStr(&sql, "VACUUM");
if (PQserverVersion(conn) >= 90000)
{
const char *paren = " (";
......@@ -282,23 +282,23 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
sep = comma;
}
if (sep != paren)
appendPQExpBuffer(&sql, ")");
appendPQExpBufferStr(&sql, ")");
}
else
{
if (full)
appendPQExpBuffer(&sql, " FULL");
appendPQExpBufferStr(&sql, " FULL");
if (freeze)
appendPQExpBuffer(&sql, " FREEZE");
appendPQExpBufferStr(&sql, " FREEZE");
if (verbose)
appendPQExpBuffer(&sql, " VERBOSE");
appendPQExpBufferStr(&sql, " VERBOSE");
if (and_analyze)
appendPQExpBuffer(&sql, " ANALYZE");
appendPQExpBufferStr(&sql, " ANALYZE");
}
}
if (table)
appendPQExpBuffer(&sql, " %s", table);
appendPQExpBuffer(&sql, ";\n");
appendPQExpBufferStr(&sql, ";\n");
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
......
......@@ -1601,9 +1601,9 @@ PQconnectPoll(PGconn *conn)
break;
default:
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext(
"invalid connection state, "
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext(
"invalid connection state, "
"probably indicative of memory corruption\n"
));
goto error_return;
......@@ -1695,8 +1695,8 @@ keep_going: /* We will come back to here until there is
if (usekeepalives < 0)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("keepalives parameter must be an integer\n"));
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("keepalives parameter must be an integer\n"));
err = 1;
}
else if (usekeepalives == 0)
......@@ -1920,8 +1920,8 @@ keep_going: /* We will come back to here until there is
* stub
*/
if (errno == ENOSYS)
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("requirepeer parameter is not supported on this platform\n"));
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("requirepeer parameter is not supported on this platform\n"));
else
appendPQExpBuffer(&conn->errorMessage,
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" */
{
/* Require SSL, but server does not want it */
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("server does not support SSL, but SSL was required\n"));
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("server does not support SSL, but SSL was required\n"));
goto error_return;
}
/* Otherwise, proceed with normal startup */
......@@ -2470,8 +2470,8 @@ keep_going: /* We will come back to here until there is
if (res)
{
if (res->resultStatus != PGRES_FATAL_ERROR)
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("unexpected message from server during startup\n"));
appendPQExpBufferStr(&conn->errorMessage,
libpq_gettext("unexpected message from server during startup\n"));
else if (conn->send_appname &&
(conn->appname || conn->fbappname))
{
......
......@@ -204,7 +204,7 @@ main(int argc, char **argv)
"AND holder.granted "
"AND holder.pid <> $1 AND holder.pid IN (");
/* 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++)
appendPQExpBuffer(&wait_query, ", %s", backend_pids[i]);
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