aboutsummaryrefslogtreecommitdiff
path: root/contrib/postgres_fdw/connection.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2017-02-27 08:30:06 -0500
committerPeter Eisentraut <peter_e@gmx.net>2017-02-27 08:54:51 -0500
commit2ed193c904679a533d5e26a27c97119793bcae52 (patch)
tree20750d69786c8fc97f345e40521334e962221215 /contrib/postgres_fdw/connection.c
parent9fab40ad32efa4038d19eaed975bb4c1713ccbc0 (diff)
downloadpostgresql-2ed193c904679a533d5e26a27c97119793bcae52.tar.gz
postgresql-2ed193c904679a533d5e26a27c97119793bcae52.zip
chomp PQerrorMessage() in backend uses
PQerrorMessage() returns an error message with a trailing newline, but in backend use (dblink, postgres_fdw, libpqwalreceiver), we want to have the error message without that for emitting via ereport(). To simplify that, add a function pchomp() that returns a pstrdup'ed string with the trailing newline characters removed.
Diffstat (limited to 'contrib/postgres_fdw/connection.c')
-rw-r--r--contrib/postgres_fdw/connection.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/contrib/postgres_fdw/connection.c b/contrib/postgres_fdw/connection.c
index 7f7a744ac0a..c6e3d445155 100644
--- a/contrib/postgres_fdw/connection.c
+++ b/contrib/postgres_fdw/connection.c
@@ -226,21 +226,11 @@ connect_pg_server(ForeignServer *server, UserMapping *user)
conn = PQconnectdbParams(keywords, values, false);
if (!conn || PQstatus(conn) != CONNECTION_OK)
- {
- char *connmessage;
- int msglen;
-
- /* libpq typically appends a newline, strip that */
- connmessage = pstrdup(PQerrorMessage(conn));
- msglen = strlen(connmessage);
- if (msglen > 0 && connmessage[msglen - 1] == '\n')
- connmessage[msglen - 1] = '\0';
ereport(ERROR,
(errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
errmsg("could not connect to server \"%s\"",
server->servername),
- errdetail_internal("%s", connmessage)));
- }
+ errdetail_internal("%s", pchomp(PQerrorMessage(conn)))));
/*
* Check that non-superuser has used password to establish connection;
@@ -563,7 +553,7 @@ pgfdw_report_error(int elevel, PGresult *res, PGconn *conn,
* return NULL, not a PGresult at all.
*/
if (message_primary == NULL)
- message_primary = PQerrorMessage(conn);
+ message_primary = pchomp(PQerrorMessage(conn));
ereport(elevel,
(errcode(sqlstate),