diff options
| author | Peter Eisentraut | 2017-02-27 13:30:06 +0000 |
|---|---|---|
| committer | Peter Eisentraut | 2017-02-27 13:54:51 +0000 |
| commit | 2ed193c904679a533d5e26a27c97119793bcae52 (patch) | |
| tree | 20750d69786c8fc97f345e40521334e962221215 /contrib/dblink | |
| parent | 9fab40ad32efa4038d19eaed975bb4c1713ccbc0 (diff) | |
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/dblink')
| -rw-r--r-- | contrib/dblink/dblink.c | 14 | ||||
| -rw-r--r-- | contrib/dblink/expected/dblink.out | 2 |
2 files changed, 7 insertions, 9 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index ac43c458cb..e0d6778a08 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -166,7 +166,7 @@ typedef struct remoteConnHashEnt #define DBLINK_RES_INTERNALERROR(p2) \ do { \ - msg = pstrdup(PQerrorMessage(conn)); \ + msg = pchomp(PQerrorMessage(conn)); \ if (res) \ PQclear(res); \ elog(ERROR, "%s: %s", p2, msg); \ @@ -204,7 +204,7 @@ typedef struct remoteConnHashEnt conn = PQconnectdb(connstr); \ if (PQstatus(conn) == CONNECTION_BAD) \ { \ - msg = pstrdup(PQerrorMessage(conn)); \ + msg = pchomp(PQerrorMessage(conn)); \ PQfinish(conn); \ ereport(ERROR, \ (errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION), \ @@ -278,7 +278,7 @@ dblink_connect(PG_FUNCTION_ARGS) if (PQstatus(conn) == CONNECTION_BAD) { - msg = pstrdup(PQerrorMessage(conn)); + msg = pchomp(PQerrorMessage(conn)); PQfinish(conn); if (rconn) pfree(rconn); @@ -651,7 +651,7 @@ dblink_send_query(PG_FUNCTION_ARGS) /* async query send */ retval = PQsendQuery(conn, sql); if (retval != 1) - elog(NOTICE, "could not send query: %s", PQerrorMessage(conn)); + elog(NOTICE, "could not send query: %s", pchomp(PQerrorMessage(conn))); PG_RETURN_INT32(retval); } @@ -1087,7 +1087,7 @@ storeQueryResult(volatile storeInfo *sinfo, PGconn *conn, const char *sql) PGresult *res; if (!PQsendQuery(conn, sql)) - elog(ERROR, "could not send query: %s", PQerrorMessage(conn)); + elog(ERROR, "could not send query: %s", pchomp(PQerrorMessage(conn))); if (!PQsetSingleRowMode(conn)) /* shouldn't fail */ elog(ERROR, "failed to set single-row mode for dblink query"); @@ -1370,7 +1370,7 @@ dblink_error_message(PG_FUNCTION_ARGS) if (msg == NULL || msg[0] == '\0') PG_RETURN_TEXT_P(cstring_to_text("OK")); else - PG_RETURN_TEXT_P(cstring_to_text(msg)); + PG_RETURN_TEXT_P(cstring_to_text(pchomp(msg))); } /* @@ -2709,7 +2709,7 @@ dblink_res_error(PGconn *conn, const char *conname, PGresult *res, * return NULL, not a PGresult at all. */ if (message_primary == NULL) - message_primary = PQerrorMessage(conn); + message_primary = pchomp(PQerrorMessage(conn)); if (res) PQclear(res); diff --git a/contrib/dblink/expected/dblink.out b/contrib/dblink/expected/dblink.out index 5acaaf225a..4b6d26e574 100644 --- a/contrib/dblink/expected/dblink.out +++ b/contrib/dblink/expected/dblink.out @@ -377,7 +377,6 @@ FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[]) WHERE t.a > 7; ERROR: could not establish connection DETAIL: missing "=" after "myconn" in connection info string - -- create a named persistent connection SELECT dblink_connect('myconn',connection_parameters()); dblink_connect @@ -604,7 +603,6 @@ FROM dblink('myconn','SELECT * FROM foo') AS t(a int, b text, c text[]) WHERE t.a > 7; ERROR: could not establish connection DETAIL: missing "=" after "myconn" in connection info string - -- create a named persistent connection SELECT dblink_connect('myconn',connection_parameters()); dblink_connect |
