Commit d3c4c471 authored by Peter Eisentraut's avatar Peter Eisentraut

scripts: Remove newlines from end of generated SQL

This results in spurious empty lines in the server log.  Instead, add
the newlines only when printing out the --echo output.  In some cases,
this was already done, leading to two newlines being printed.  Clean
that up as well.

From: Fabrízio de Royes Mello <fabriziomello@gmail.com>
parent 28954152
......@@ -201,7 +201,7 @@ cluster_one_database(const char *dbname, bool verbose, const char *table,
appendPQExpBufferStr(&sql, " VERBOSE");
if (table)
appendPQExpBuffer(&sql, " %s", table);
appendPQExpBufferStr(&sql, ";\n");
appendPQExpBufferStr(&sql, ";");
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);
appendPQExpBufferStr(&sql, ";\n");
appendPQExpBufferStr(&sql, ";");
/* No point in trying to use postgres db when creating postgres db. */
if (maintenance_db == NULL && strcmp(dbname, "postgres") == 0)
......@@ -205,7 +205,7 @@ main(int argc, char *argv[])
prompt_password, progname);
if (echo)
printf("%s", sql.data);
printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
......@@ -222,10 +222,10 @@ main(int argc, char *argv[])
{
printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname));
appendStringLiteralConn(&sql, comment, conn);
appendPQExpBufferStr(&sql, ";\n");
appendPQExpBufferStr(&sql, ";");
if (echo)
printf("%s", sql.data);
printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
......
......@@ -207,12 +207,12 @@ main(int argc, char *argv[])
* older server, and it's easy enough to continue supporting the old way.
*/
if (PQserverVersion(conn) >= 90100)
printfPQExpBuffer(&sql, "CREATE EXTENSION \"%s\";\n", langname);
printfPQExpBuffer(&sql, "CREATE EXTENSION \"%s\";", langname);
else
printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";\n", langname);
printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";", langname);
if (echo)
printf("%s", sql.data);
printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
{
......
......@@ -320,10 +320,10 @@ main(int argc, char *argv[])
appendPQExpBuffer(&sql, "%s", fmtId(cell->val));
}
}
appendPQExpBufferStr(&sql, ";\n");
appendPQExpBufferStr(&sql, ";");
if (echo)
printf("%s", sql.data);
printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
......
......@@ -121,7 +121,7 @@ main(int argc, char *argv[])
initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "DROP DATABASE %s%s;\n",
appendPQExpBuffer(&sql, "DROP DATABASE %s%s;",
(if_exists ? "IF EXISTS " : ""), fmtId(dbname));
/* Avoid trying to drop postgres db while we are connected to it. */
......@@ -132,7 +132,7 @@ main(int argc, char *argv[])
host, port, username, prompt_password, progname);
if (echo)
printf("%s", sql.data);
printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
{
......
......@@ -211,10 +211,10 @@ main(int argc, char *argv[])
* Attempt to drop the language. We do not use CASCADE, so that the drop
* will fail if there are any functions in the language.
*/
printfPQExpBuffer(&sql, "DROP EXTENSION \"%s\";\n", langname);
printfPQExpBuffer(&sql, "DROP EXTENSION \"%s\";", langname);
if (echo)
printf("%s", sql.data);
printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
{
......
......@@ -125,14 +125,14 @@ main(int argc, char *argv[])
}
initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "DROP ROLE %s%s;\n",
appendPQExpBuffer(&sql, "DROP ROLE %s%s;",
(if_exists ? "IF EXISTS " : ""), fmtId(dropuser));
conn = connectDatabase("postgres", host, port, username, prompt_password,
progname, false);
if (echo)
printf("%s", sql.data);
printf("%s\n", sql.data);
result = PQexec(conn, sql.data);
if (PQresultStatus(result) != PGRES_COMMAND_OK)
......
......@@ -253,7 +253,7 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
appendPQExpBuffer(&sql, " INDEX %s", name);
else if (strcmp(type, "DATABASE") == 0)
appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name));
appendPQExpBufferStr(&sql, ";\n");
appendPQExpBufferStr(&sql, ";");
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false);
......@@ -320,7 +320,7 @@ reindex_system_catalogs(const char *dbname, const char *host, const char *port,
initPQExpBuffer(&sql);
appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;\n", dbname);
appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;", dbname);
conn = connectDatabase(dbname, host, port, username, prompt_password,
progname, false);
......
......@@ -298,7 +298,7 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
}
if (table)
appendPQExpBuffer(&sql, " %s", table);
appendPQExpBufferStr(&sql, ";\n");
appendPQExpBufferStr(&sql, ";");
if (!executeMaintenanceCommand(conn, sql.data, echo))
{
......
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