Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit d3c4c47

Browse files
committed
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>
1 parent 2895415 commit d3c4c47

File tree

9 files changed

+19
-19
lines changed

9 files changed

+19
-19
lines changed

src/bin/scripts/clusterdb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ cluster_one_database(const char *dbname, bool verbose, const char *table,
201201
appendPQExpBufferStr(&sql, " VERBOSE");
202202
if (table)
203203
appendPQExpBuffer(&sql, " %s", table);
204-
appendPQExpBufferStr(&sql, ";\n");
204+
appendPQExpBufferStr(&sql, ";");
205205

206206
conn = connectDatabase(dbname, host, port, username, prompt_password,
207207
progname, false);

src/bin/scripts/createdb.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ main(int argc, char *argv[])
195195
if (lc_ctype)
196196
appendPQExpBuffer(&sql, " LC_CTYPE '%s'", lc_ctype);
197197

198-
appendPQExpBufferStr(&sql, ";\n");
198+
appendPQExpBufferStr(&sql, ";");
199199

200200
/* No point in trying to use postgres db when creating postgres db. */
201201
if (maintenance_db == NULL && strcmp(dbname, "postgres") == 0)
@@ -205,7 +205,7 @@ main(int argc, char *argv[])
205205
prompt_password, progname);
206206

207207
if (echo)
208-
printf("%s", sql.data);
208+
printf("%s\n", sql.data);
209209
result = PQexec(conn, sql.data);
210210

211211
if (PQresultStatus(result) != PGRES_COMMAND_OK)
@@ -222,10 +222,10 @@ main(int argc, char *argv[])
222222
{
223223
printfPQExpBuffer(&sql, "COMMENT ON DATABASE %s IS ", fmtId(dbname));
224224
appendStringLiteralConn(&sql, comment, conn);
225-
appendPQExpBufferStr(&sql, ";\n");
225+
appendPQExpBufferStr(&sql, ";");
226226

227227
if (echo)
228-
printf("%s", sql.data);
228+
printf("%s\n", sql.data);
229229
result = PQexec(conn, sql.data);
230230

231231
if (PQresultStatus(result) != PGRES_COMMAND_OK)

src/bin/scripts/createlang.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ main(int argc, char *argv[])
207207
* older server, and it's easy enough to continue supporting the old way.
208208
*/
209209
if (PQserverVersion(conn) >= 90100)
210-
printfPQExpBuffer(&sql, "CREATE EXTENSION \"%s\";\n", langname);
210+
printfPQExpBuffer(&sql, "CREATE EXTENSION \"%s\";", langname);
211211
else
212-
printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";\n", langname);
212+
printfPQExpBuffer(&sql, "CREATE LANGUAGE \"%s\";", langname);
213213

214214
if (echo)
215-
printf("%s", sql.data);
215+
printf("%s\n", sql.data);
216216
result = PQexec(conn, sql.data);
217217
if (PQresultStatus(result) != PGRES_COMMAND_OK)
218218
{

src/bin/scripts/createuser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ main(int argc, char *argv[])
320320
appendPQExpBuffer(&sql, "%s", fmtId(cell->val));
321321
}
322322
}
323-
appendPQExpBufferStr(&sql, ";\n");
323+
appendPQExpBufferStr(&sql, ";");
324324

325325
if (echo)
326-
printf("%s", sql.data);
326+
printf("%s\n", sql.data);
327327
result = PQexec(conn, sql.data);
328328

329329
if (PQresultStatus(result) != PGRES_COMMAND_OK)

src/bin/scripts/dropdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ main(int argc, char *argv[])
121121

122122
initPQExpBuffer(&sql);
123123

124-
appendPQExpBuffer(&sql, "DROP DATABASE %s%s;\n",
124+
appendPQExpBuffer(&sql, "DROP DATABASE %s%s;",
125125
(if_exists ? "IF EXISTS " : ""), fmtId(dbname));
126126

127127
/* Avoid trying to drop postgres db while we are connected to it. */
@@ -132,7 +132,7 @@ main(int argc, char *argv[])
132132
host, port, username, prompt_password, progname);
133133

134134
if (echo)
135-
printf("%s", sql.data);
135+
printf("%s\n", sql.data);
136136
result = PQexec(conn, sql.data);
137137
if (PQresultStatus(result) != PGRES_COMMAND_OK)
138138
{

src/bin/scripts/droplang.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ main(int argc, char *argv[])
211211
* Attempt to drop the language. We do not use CASCADE, so that the drop
212212
* will fail if there are any functions in the language.
213213
*/
214-
printfPQExpBuffer(&sql, "DROP EXTENSION \"%s\";\n", langname);
214+
printfPQExpBuffer(&sql, "DROP EXTENSION \"%s\";", langname);
215215

216216
if (echo)
217-
printf("%s", sql.data);
217+
printf("%s\n", sql.data);
218218
result = PQexec(conn, sql.data);
219219
if (PQresultStatus(result) != PGRES_COMMAND_OK)
220220
{

src/bin/scripts/dropuser.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,14 @@ main(int argc, char *argv[])
125125
}
126126

127127
initPQExpBuffer(&sql);
128-
appendPQExpBuffer(&sql, "DROP ROLE %s%s;\n",
128+
appendPQExpBuffer(&sql, "DROP ROLE %s%s;",
129129
(if_exists ? "IF EXISTS " : ""), fmtId(dropuser));
130130

131131
conn = connectDatabase("postgres", host, port, username, prompt_password,
132132
progname, false);
133133

134134
if (echo)
135-
printf("%s", sql.data);
135+
printf("%s\n", sql.data);
136136
result = PQexec(conn, sql.data);
137137

138138
if (PQresultStatus(result) != PGRES_COMMAND_OK)

src/bin/scripts/reindexdb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ reindex_one_database(const char *name, const char *dbname, const char *type,
253253
appendPQExpBuffer(&sql, " INDEX %s", name);
254254
else if (strcmp(type, "DATABASE") == 0)
255255
appendPQExpBuffer(&sql, " DATABASE %s", fmtId(name));
256-
appendPQExpBufferStr(&sql, ";\n");
256+
appendPQExpBufferStr(&sql, ";");
257257

258258
conn = connectDatabase(dbname, host, port, username, prompt_password,
259259
progname, false);
@@ -320,7 +320,7 @@ reindex_system_catalogs(const char *dbname, const char *host, const char *port,
320320

321321
initPQExpBuffer(&sql);
322322

323-
appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;\n", dbname);
323+
appendPQExpBuffer(&sql, "REINDEX SYSTEM %s;", dbname);
324324

325325
conn = connectDatabase(dbname, host, port, username, prompt_password,
326326
progname, false);

src/bin/scripts/vacuumdb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ vacuum_one_database(const char *dbname, bool full, bool verbose, bool and_analyz
298298
}
299299
if (table)
300300
appendPQExpBuffer(&sql, " %s", table);
301-
appendPQExpBufferStr(&sql, ";\n");
301+
appendPQExpBufferStr(&sql, ";");
302302

303303
if (!executeMaintenanceCommand(conn, sql.data, echo))
304304
{

0 commit comments

Comments
 (0)