]> granicus.if.org Git - postgresql/commitdiff
scripts: Remove newlines from end of generated SQL
authorPeter Eisentraut <peter_e@gmx.net>
Tue, 11 Feb 2014 02:47:19 +0000 (21:47 -0500)
committerPeter Eisentraut <peter_e@gmx.net>
Tue, 11 Feb 2014 02:47:19 +0000 (21:47 -0500)
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>

src/bin/scripts/clusterdb.c
src/bin/scripts/createdb.c
src/bin/scripts/createlang.c
src/bin/scripts/createuser.c
src/bin/scripts/dropdb.c
src/bin/scripts/droplang.c
src/bin/scripts/dropuser.c
src/bin/scripts/reindexdb.c
src/bin/scripts/vacuumdb.c

index 504b337a647d79ada7078d7518e4a44c5d7a01e1..5ad1d01a1afb47aac20ac0a289d6ae5c44d81474 100644 (file)
@@ -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);
index edd18f7423eb1cfbe3f11ee7ce3e158ae3a6ac29..64badd6bd30029caa50ebbdb3ac4be5da9fc9558 100644 (file)
@@ -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)
index 7737cb8b26b66b68403875572fbc924d80e65770..9bbd67de7bd7358e89d0d7a911a418fad62d499f 100644 (file)
@@ -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)
        {
index 6b1a00790a66e7eee000dec10eea19e6edc73a47..24c4beb2437e082b5431269f8426de8c5a731469 100644 (file)
@@ -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)
index fa6ea3ebb804a6aabf0ec0afaeca09a7e0d50129..e750b449d6bb571432623b98c4ad727cbe9f0e4f 100644 (file)
@@ -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)
        {
index d1a3e73afab659682ec573d829aabfbc385dca84..09f7b66a47d191e64ff8f1c167dc2fbafda47e78 100644 (file)
@@ -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)
        {
index b4b153bfa10e402d9f6e6afdcd37fabb8abade9d..69a5a493ae3ae0e5af5f6b641b58e2172cf1367a 100644 (file)
@@ -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)
index e627d82c4b840e797cef2cacbb35288395514cd4..561bbcebd233016eb866930ae262ce92c61854e4 100644 (file)
@@ -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);
index f0340327c313ddc3651aa30a0c901bac9d3e966f..07a60d0b6d4db4c5ed90ab17a610158ab8389b22 100644 (file)
@@ -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))
        {