aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-exec.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces/libpq/fe-exec.c')
-rw-r--r--src/interfaces/libpq/fe-exec.c119
1 files changed, 40 insertions, 79 deletions
diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c
index 64701b562bf..da229d632a1 100644
--- a/src/interfaces/libpq/fe-exec.c
+++ b/src/interfaces/libpq/fe-exec.c
@@ -828,8 +828,7 @@ pqSaveWriteError(PGconn *conn)
conn->write_err_msg[0] = '\0';
}
else
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("write to server failed\n"));
+ libpq_append_conn_error(conn, "write to server failed");
pqSaveErrorResult(conn);
}
@@ -867,8 +866,7 @@ pqPrepareAsyncResult(PGconn *conn)
* text.
*/
if (!conn->error_result)
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("no error text available\n"));
+ libpq_append_conn_error(conn, "no error text available");
/* Paranoia: be sure errorReported offset is sane */
if (conn->errorReported < 0 ||
@@ -1316,8 +1314,7 @@ pqAllocCmdQueueEntry(PGconn *conn)
entry = (PGcmdQueueEntry *) malloc(sizeof(PGcmdQueueEntry));
if (entry == NULL)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("out of memory\n"));
+ libpq_append_conn_error(conn, "out of memory");
return NULL;
}
}
@@ -1440,15 +1437,13 @@ PQsendQueryInternal(PGconn *conn, const char *query, bool newQuery)
/* check the argument */
if (!query)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("command string is a null pointer\n"));
+ libpq_append_conn_error(conn, "command string is a null pointer");
return 0;
}
if (conn->pipelineStatus != PQ_PIPELINE_OFF)
{
- appendPQExpBuffer(&conn->errorMessage,
- libpq_gettext("%s not allowed in pipeline mode\n"),
+ libpq_append_conn_error(conn, "%s not allowed in pipeline mode",
"PQsendQuery");
return 0;
}
@@ -1511,15 +1506,13 @@ PQsendQueryParams(PGconn *conn,
/* check the arguments */
if (!command)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("command string is a null pointer\n"));
+ libpq_append_conn_error(conn, "command string is a null pointer");
return 0;
}
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
{
- appendPQExpBuffer(&conn->errorMessage,
- libpq_gettext("number of parameters must be between 0 and %d\n"),
- PQ_QUERY_PARAM_MAX_LIMIT);
+ libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
+ PQ_QUERY_PARAM_MAX_LIMIT);
return 0;
}
@@ -1554,21 +1547,18 @@ PQsendPrepare(PGconn *conn,
/* check the arguments */
if (!stmtName)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("statement name is a null pointer\n"));
+ libpq_append_conn_error(conn, "statement name is a null pointer");
return 0;
}
if (!query)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("command string is a null pointer\n"));
+ libpq_append_conn_error(conn, "command string is a null pointer");
return 0;
}
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
{
- appendPQExpBuffer(&conn->errorMessage,
- libpq_gettext("number of parameters must be between 0 and %d\n"),
- PQ_QUERY_PARAM_MAX_LIMIT);
+ libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
+ PQ_QUERY_PARAM_MAX_LIMIT);
return 0;
}
@@ -1656,15 +1646,13 @@ PQsendQueryPrepared(PGconn *conn,
/* check the arguments */
if (!stmtName)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("statement name is a null pointer\n"));
+ libpq_append_conn_error(conn, "statement name is a null pointer");
return 0;
}
if (nParams < 0 || nParams > PQ_QUERY_PARAM_MAX_LIMIT)
{
- appendPQExpBuffer(&conn->errorMessage,
- libpq_gettext("number of parameters must be between 0 and %d\n"),
- PQ_QUERY_PARAM_MAX_LIMIT);
+ libpq_append_conn_error(conn, "number of parameters must be between 0 and %d",
+ PQ_QUERY_PARAM_MAX_LIMIT);
return 0;
}
@@ -1700,8 +1688,7 @@ PQsendQueryStart(PGconn *conn, bool newQuery)
/* Don't try to send if we know there's no live connection. */
if (conn->status != CONNECTION_OK)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("no connection to the server\n"));
+ libpq_append_conn_error(conn, "no connection to the server");
return false;
}
@@ -1709,8 +1696,7 @@ PQsendQueryStart(PGconn *conn, bool newQuery)
if (conn->asyncStatus != PGASYNC_IDLE &&
conn->pipelineStatus == PQ_PIPELINE_OFF)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("another command is already in progress\n"));
+ libpq_append_conn_error(conn, "another command is already in progress");
return false;
}
@@ -1740,8 +1726,7 @@ PQsendQueryStart(PGconn *conn, bool newQuery)
case PGASYNC_COPY_IN:
case PGASYNC_COPY_OUT:
case PGASYNC_COPY_BOTH:
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("cannot queue commands during COPY\n"));
+ libpq_append_conn_error(conn, "cannot queue commands during COPY");
return false;
}
}
@@ -1858,8 +1843,7 @@ PQsendQueryGuts(PGconn *conn,
nbytes = paramLengths[i];
else
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("length must be given for binary parameter\n"));
+ libpq_append_conn_error(conn, "length must be given for binary parameter");
goto sendFailed;
}
}
@@ -2181,9 +2165,7 @@ PQgetResult(PGconn *conn)
res = getCopyResult(conn, PGRES_COPY_BOTH);
break;
default:
- appendPQExpBuffer(&conn->errorMessage,
- libpq_gettext("unexpected asyncStatus: %d\n"),
- (int) conn->asyncStatus);
+ libpq_append_conn_error(conn, "unexpected asyncStatus: %d", (int) conn->asyncStatus);
pqSaveErrorResult(conn);
conn->asyncStatus = PGASYNC_IDLE; /* try to restore valid state */
res = pqPrepareAsyncResult(conn);
@@ -2339,8 +2321,7 @@ PQexecStart(PGconn *conn)
if (conn->pipelineStatus != PQ_PIPELINE_OFF)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("synchronous command execution functions are not allowed in pipeline mode\n"));
+ libpq_append_conn_error(conn, "synchronous command execution functions are not allowed in pipeline mode");
return false;
}
@@ -2373,8 +2354,7 @@ PQexecStart(PGconn *conn)
else if (resultStatus == PGRES_COPY_BOTH)
{
/* We don't allow PQexec during COPY BOTH */
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("PQexec not allowed during COPY BOTH\n"));
+ libpq_append_conn_error(conn, "PQexec not allowed during COPY BOTH");
return false;
}
/* check for loss of connection, too */
@@ -2600,8 +2580,7 @@ PQputCopyData(PGconn *conn, const char *buffer, int nbytes)
if (conn->asyncStatus != PGASYNC_COPY_IN &&
conn->asyncStatus != PGASYNC_COPY_BOTH)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("no COPY in progress\n"));
+ libpq_append_conn_error(conn, "no COPY in progress");
return -1;
}
@@ -2656,8 +2635,7 @@ PQputCopyEnd(PGconn *conn, const char *errormsg)
if (conn->asyncStatus != PGASYNC_COPY_IN &&
conn->asyncStatus != PGASYNC_COPY_BOTH)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("no COPY in progress\n"));
+ libpq_append_conn_error(conn, "no COPY in progress");
return -1;
}
@@ -2725,8 +2703,7 @@ PQgetCopyData(PGconn *conn, char **buffer, int async)
if (conn->asyncStatus != PGASYNC_COPY_OUT &&
conn->asyncStatus != PGASYNC_COPY_BOTH)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("no COPY in progress\n"));
+ libpq_append_conn_error(conn, "no COPY in progress");
return -2;
}
return pqGetCopyData3(conn, buffer, async);
@@ -2905,17 +2882,14 @@ PQfn(PGconn *conn,
if (conn->pipelineStatus != PQ_PIPELINE_OFF)
{
- appendPQExpBuffer(&conn->errorMessage,
- libpq_gettext("%s not allowed in pipeline mode\n"),
- "PQfn");
+ libpq_append_conn_error(conn, "%s not allowed in pipeline mode", "PQfn");
return NULL;
}
if (conn->sock == PGINVALID_SOCKET || conn->asyncStatus != PGASYNC_IDLE ||
pgHavePendingResult(conn))
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("connection in wrong state\n"));
+ libpq_append_conn_error(conn, "connection in wrong state");
return NULL;
}
@@ -2958,8 +2932,7 @@ PQenterPipelineMode(PGconn *conn)
if (conn->asyncStatus != PGASYNC_IDLE)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("cannot enter pipeline mode, connection not idle\n"));
+ libpq_append_conn_error(conn, "cannot enter pipeline mode, connection not idle");
return 0;
}
@@ -2995,13 +2968,11 @@ PQexitPipelineMode(PGconn *conn)
case PGASYNC_READY:
case PGASYNC_READY_MORE:
/* there are some uncollected results */
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("cannot exit pipeline mode with uncollected results\n"));
+ libpq_append_conn_error(conn, "cannot exit pipeline mode with uncollected results");
return 0;
case PGASYNC_BUSY:
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("cannot exit pipeline mode while busy\n"));
+ libpq_append_conn_error(conn, "cannot exit pipeline mode while busy");
return 0;
case PGASYNC_IDLE:
@@ -3012,15 +2983,13 @@ PQexitPipelineMode(PGconn *conn)
case PGASYNC_COPY_IN:
case PGASYNC_COPY_OUT:
case PGASYNC_COPY_BOTH:
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("cannot exit pipeline mode while in COPY\n"));
+ libpq_append_conn_error(conn, "cannot exit pipeline mode while in COPY");
}
/* still work to process */
if (conn->cmd_queue_head != NULL)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("cannot exit pipeline mode with uncollected results\n"));
+ libpq_append_conn_error(conn, "cannot exit pipeline mode with uncollected results");
return 0;
}
@@ -3135,8 +3104,7 @@ pqPipelineProcessQueue(PGconn *conn)
conn->result = PQmakeEmptyPGresult(conn, PGRES_PIPELINE_ABORTED);
if (!conn->result)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("out of memory\n"));
+ libpq_append_conn_error(conn, "out of memory");
pqSaveErrorResult(conn);
return;
}
@@ -3179,8 +3147,7 @@ PQpipelineSync(PGconn *conn)
if (conn->pipelineStatus == PQ_PIPELINE_OFF)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("cannot send pipeline when not in pipeline mode\n"));
+ libpq_append_conn_error(conn, "cannot send pipeline when not in pipeline mode");
return 0;
}
@@ -3246,8 +3213,7 @@ PQsendFlushRequest(PGconn *conn)
/* Don't try to send if we know there's no live connection. */
if (conn->status != CONNECTION_OK)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("no connection to the server\n"));
+ libpq_append_conn_error(conn, "no connection to the server");
return 0;
}
@@ -3255,8 +3221,7 @@ PQsendFlushRequest(PGconn *conn)
if (conn->asyncStatus != PGASYNC_IDLE &&
conn->pipelineStatus == PQ_PIPELINE_OFF)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("another command is already in progress\n"));
+ libpq_append_conn_error(conn, "another command is already in progress");
return 0;
}
@@ -3992,8 +3957,7 @@ PQescapeStringInternal(PGconn *conn,
if (error)
*error = 1;
if (conn)
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("incomplete multibyte character\n"));
+ libpq_append_conn_error(conn, "incomplete multibyte character");
for (; i < len; i++)
{
if (((size_t) (target - to)) / 2 >= length)
@@ -4083,8 +4047,7 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident)
/* Multibyte character overruns allowable length. */
if ((s - str) + charlen > len || memchr(s, 0, charlen) != NULL)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("incomplete multibyte character\n"));
+ libpq_append_conn_error(conn, "incomplete multibyte character");
return NULL;
}
@@ -4101,8 +4064,7 @@ PQescapeInternal(PGconn *conn, const char *str, size_t len, bool as_ident)
result = rp = (char *) malloc(result_size);
if (rp == NULL)
{
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("out of memory\n"));
+ libpq_append_conn_error(conn, "out of memory");
return NULL;
}
@@ -4266,8 +4228,7 @@ PQescapeByteaInternal(PGconn *conn,
if (rp == NULL)
{
if (conn)
- appendPQExpBufferStr(&conn->errorMessage,
- libpq_gettext("out of memory\n"));
+ libpq_append_conn_error(conn, "out of memory");
return NULL;
}