From d3c4c471553265e7517be24bae64b81967f6df40 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Mon, 10 Feb 2014 21:47:19 -0500 Subject: [PATCH] scripts: Remove newlines from end of generated SQL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/bin/scripts/clusterdb.c | 2 +- src/bin/scripts/createdb.c | 8 ++++---- src/bin/scripts/createlang.c | 6 +++--- src/bin/scripts/createuser.c | 4 ++-- src/bin/scripts/dropdb.c | 4 ++-- src/bin/scripts/droplang.c | 4 ++-- src/bin/scripts/dropuser.c | 4 ++-- src/bin/scripts/reindexdb.c | 4 ++-- src/bin/scripts/vacuumdb.c | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index 504b337a64..5ad1d01a1a 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -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); diff --git a/src/bin/scripts/createdb.c b/src/bin/scripts/createdb.c index edd18f7423..64badd6bd3 100644 --- a/src/bin/scripts/createdb.c +++ b/src/bin/scripts/createdb.c @@ -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) diff --git a/src/bin/scripts/createlang.c b/src/bin/scripts/createlang.c index 7737cb8b26..9bbd67de7b 100644 --- a/src/bin/scripts/createlang.c +++ b/src/bin/scripts/createlang.c @@ -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) { diff --git a/src/bin/scripts/createuser.c b/src/bin/scripts/createuser.c index 6b1a00790a..24c4beb243 100644 --- a/src/bin/scripts/createuser.c +++ b/src/bin/scripts/createuser.c @@ -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) diff --git a/src/bin/scripts/dropdb.c b/src/bin/scripts/dropdb.c index fa6ea3ebb8..e750b449d6 100644 --- a/src/bin/scripts/dropdb.c +++ b/src/bin/scripts/dropdb.c @@ -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) { diff --git a/src/bin/scripts/droplang.c b/src/bin/scripts/droplang.c index d1a3e73afa..09f7b66a47 100644 --- a/src/bin/scripts/droplang.c +++ b/src/bin/scripts/droplang.c @@ -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) { diff --git a/src/bin/scripts/dropuser.c b/src/bin/scripts/dropuser.c index b4b153bfa1..69a5a493ae 100644 --- a/src/bin/scripts/dropuser.c +++ b/src/bin/scripts/dropuser.c @@ -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) diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index e627d82c4b..561bbcebd2 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -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); diff --git a/src/bin/scripts/vacuumdb.c b/src/bin/scripts/vacuumdb.c index f0340327c3..07a60d0b6d 100644 --- a/src/bin/scripts/vacuumdb.c +++ b/src/bin/scripts/vacuumdb.c @@ -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)) {