mirror of
https://github.com/postgres/postgres.git
synced 2025-06-27 23:21:58 +03:00
Share PG_DIAG_* macros between client and server and use them internally.
This commit is contained in:
@ -37,7 +37,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.120 2003/08/26 21:15:27 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.121 2003/08/27 00:33:34 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -1165,7 +1165,7 @@ send_message_to_frontend(ErrorData *edata)
|
||||
int ssval;
|
||||
int i;
|
||||
|
||||
pq_sendbyte(&msgbuf, 'S');
|
||||
pq_sendbyte(&msgbuf, PG_DIAG_SEVERITY);
|
||||
pq_sendstring(&msgbuf, error_severity(edata->elevel));
|
||||
|
||||
/* unpack MAKE_SQLSTATE code */
|
||||
@ -1177,11 +1177,11 @@ send_message_to_frontend(ErrorData *edata)
|
||||
}
|
||||
tbuf[i] = '\0';
|
||||
|
||||
pq_sendbyte(&msgbuf, 'C');
|
||||
pq_sendbyte(&msgbuf, PG_DIAG_SQLSTATE);
|
||||
pq_sendstring(&msgbuf, tbuf);
|
||||
|
||||
/* M field is required per protocol, so always send something */
|
||||
pq_sendbyte(&msgbuf, 'M');
|
||||
pq_sendbyte(&msgbuf, PG_DIAG_MESSAGE_PRIMARY);
|
||||
if (edata->message)
|
||||
pq_sendstring(&msgbuf, edata->message);
|
||||
else
|
||||
@ -1189,45 +1189,45 @@ send_message_to_frontend(ErrorData *edata)
|
||||
|
||||
if (edata->detail)
|
||||
{
|
||||
pq_sendbyte(&msgbuf, 'D');
|
||||
pq_sendbyte(&msgbuf, PG_DIAG_MESSAGE_DETAIL);
|
||||
pq_sendstring(&msgbuf, edata->detail);
|
||||
}
|
||||
|
||||
if (edata->hint)
|
||||
{
|
||||
pq_sendbyte(&msgbuf, 'H');
|
||||
pq_sendbyte(&msgbuf, PG_DIAG_MESSAGE_HINT);
|
||||
pq_sendstring(&msgbuf, edata->hint);
|
||||
}
|
||||
|
||||
if (edata->context)
|
||||
{
|
||||
pq_sendbyte(&msgbuf, 'W');
|
||||
pq_sendbyte(&msgbuf, PG_DIAG_CONTEXT);
|
||||
pq_sendstring(&msgbuf, edata->context);
|
||||
}
|
||||
|
||||
if (edata->cursorpos > 0)
|
||||
{
|
||||
snprintf(tbuf, sizeof(tbuf), "%d", edata->cursorpos);
|
||||
pq_sendbyte(&msgbuf, 'P');
|
||||
pq_sendbyte(&msgbuf, PG_DIAG_STATEMENT_POSITION);
|
||||
pq_sendstring(&msgbuf, tbuf);
|
||||
}
|
||||
|
||||
if (edata->filename)
|
||||
{
|
||||
pq_sendbyte(&msgbuf, 'F');
|
||||
pq_sendbyte(&msgbuf, PG_DIAG_SOURCE_FILE);
|
||||
pq_sendstring(&msgbuf, edata->filename);
|
||||
}
|
||||
|
||||
if (edata->lineno > 0)
|
||||
{
|
||||
snprintf(tbuf, sizeof(tbuf), "%d", edata->lineno);
|
||||
pq_sendbyte(&msgbuf, 'L');
|
||||
pq_sendbyte(&msgbuf, PG_DIAG_SOURCE_LINE);
|
||||
pq_sendstring(&msgbuf, tbuf);
|
||||
}
|
||||
|
||||
if (edata->funcname)
|
||||
{
|
||||
pq_sendbyte(&msgbuf, 'R');
|
||||
pq_sendbyte(&msgbuf, PG_DIAG_SOURCE_FUNCTION);
|
||||
pq_sendstring(&msgbuf, edata->funcname);
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
* use header files that are otherwise internal to Postgres to interface
|
||||
* with the backend.
|
||||
*
|
||||
* $Id: postgres_ext.h,v 1.12 2003/03/18 17:21:07 momjian Exp $
|
||||
* $Id: postgres_ext.h,v 1.13 2003/08/27 00:33:34 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -47,4 +47,21 @@ typedef unsigned int Oid;
|
||||
*/
|
||||
#define NAMEDATALEN 64
|
||||
|
||||
|
||||
/*
|
||||
* Identifiers of error message fields. Kept here to keep common
|
||||
* between frontend and backend, and also to export them to libpq
|
||||
* applications.
|
||||
*/
|
||||
#define PG_DIAG_SEVERITY 'S'
|
||||
#define PG_DIAG_SQLSTATE 'C'
|
||||
#define PG_DIAG_MESSAGE_PRIMARY 'M'
|
||||
#define PG_DIAG_MESSAGE_DETAIL 'D'
|
||||
#define PG_DIAG_MESSAGE_HINT 'H'
|
||||
#define PG_DIAG_STATEMENT_POSITION 'P'
|
||||
#define PG_DIAG_CONTEXT 'W'
|
||||
#define PG_DIAG_SOURCE_FILE 'F'
|
||||
#define PG_DIAG_SOURCE_LINE 'L'
|
||||
#define PG_DIAG_SOURCE_FUNCTION 'R'
|
||||
|
||||
#endif
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.145 2003/08/13 18:56:21 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.146 2003/08/27 00:33:34 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -480,8 +480,8 @@ pqInternalNotice(const PGNoticeHooks * hooks, const char *fmt,...)
|
||||
/*
|
||||
* Set up fields of notice.
|
||||
*/
|
||||
pqSaveMessageField(res, 'M', msgBuf);
|
||||
pqSaveMessageField(res, 'S', libpq_gettext("NOTICE"));
|
||||
pqSaveMessageField(res, PG_DIAG_MESSAGE_PRIMARY, msgBuf);
|
||||
pqSaveMessageField(res, PG_DIAG_SEVERITY, libpq_gettext("NOTICE"));
|
||||
/* XXX should provide a SQLSTATE too? */
|
||||
|
||||
/*
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.6 2003/08/04 02:40:20 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.7 2003/08/27 00:33:34 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -828,7 +828,7 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
|
||||
{
|
||||
/* what comes before the colon is severity */
|
||||
*splitp = '\0';
|
||||
pqSaveMessageField(res, 'S', workBuf.data);
|
||||
pqSaveMessageField(res, PG_DIAG_SEVERITY, workBuf.data);
|
||||
startp = splitp + 3;
|
||||
}
|
||||
else
|
||||
@ -841,16 +841,16 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
|
||||
{
|
||||
/* what comes before the newline is primary message */
|
||||
*splitp++ = '\0';
|
||||
pqSaveMessageField(res, 'M', startp);
|
||||
pqSaveMessageField(res, PG_DIAG_MESSAGE_PRIMARY, startp);
|
||||
/* the rest is detail; strip any leading whitespace */
|
||||
while (*splitp && isspace((unsigned char) *splitp))
|
||||
splitp++;
|
||||
pqSaveMessageField(res, 'D', splitp);
|
||||
pqSaveMessageField(res, PG_DIAG_MESSAGE_DETAIL, splitp);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* single-line message, so all primary */
|
||||
pqSaveMessageField(res, 'M', startp);
|
||||
pqSaveMessageField(res, PG_DIAG_MESSAGE_PRIMARY, startp);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.8 2003/08/13 18:56:21 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.9 2003/08/27 00:33:34 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -614,19 +614,19 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
|
||||
* Now build the "overall" error message for PQresultErrorMessage.
|
||||
*/
|
||||
resetPQExpBuffer(&workBuf);
|
||||
val = PQresultErrorField(res, 'S'); /* Severity */
|
||||
val = PQresultErrorField(res, PG_DIAG_SEVERITY);
|
||||
if (val)
|
||||
appendPQExpBuffer(&workBuf, "%s: ", val);
|
||||
if (conn->verbosity == PQERRORS_VERBOSE)
|
||||
{
|
||||
val = PQresultErrorField(res, 'C'); /* SQLSTATE Code */
|
||||
val = PQresultErrorField(res, PG_DIAG_SQLSTATE);
|
||||
if (val)
|
||||
appendPQExpBuffer(&workBuf, "%s: ", val);
|
||||
}
|
||||
val = PQresultErrorField(res, 'M'); /* Primary message */
|
||||
val = PQresultErrorField(res, PG_DIAG_MESSAGE_PRIMARY);
|
||||
if (val)
|
||||
appendPQExpBufferStr(&workBuf, val);
|
||||
val = PQresultErrorField(res, 'P'); /* Position */
|
||||
val = PQresultErrorField(res, PG_DIAG_STATEMENT_POSITION);
|
||||
if (val)
|
||||
{
|
||||
/* translator: %s represents a digit string */
|
||||
@ -635,13 +635,13 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
|
||||
appendPQExpBufferChar(&workBuf, '\n');
|
||||
if (conn->verbosity != PQERRORS_TERSE)
|
||||
{
|
||||
val = PQresultErrorField(res, 'D'); /* Detail */
|
||||
val = PQresultErrorField(res, PG_DIAG_MESSAGE_DETAIL);
|
||||
if (val)
|
||||
appendPQExpBuffer(&workBuf, libpq_gettext("DETAIL: %s\n"), val);
|
||||
val = PQresultErrorField(res, 'H'); /* Hint */
|
||||
val = PQresultErrorField(res, PG_DIAG_MESSAGE_HINT);
|
||||
if (val)
|
||||
appendPQExpBuffer(&workBuf, libpq_gettext("HINT: %s\n"), val);
|
||||
val = PQresultErrorField(res, 'W'); /* Where */
|
||||
val = PQresultErrorField(res, PG_DIAG_CONTEXT);
|
||||
if (val)
|
||||
appendPQExpBuffer(&workBuf, libpq_gettext("CONTEXT: %s\n"), val);
|
||||
}
|
||||
@ -650,9 +650,9 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
|
||||
const char *valf;
|
||||
const char *vall;
|
||||
|
||||
valf = PQresultErrorField(res, 'F'); /* File */
|
||||
vall = PQresultErrorField(res, 'L'); /* Line */
|
||||
val = PQresultErrorField(res, 'R'); /* Routine */
|
||||
valf = PQresultErrorField(res, PG_DIAG_SOURCE_FILE);
|
||||
vall = PQresultErrorField(res, PG_DIAG_SOURCE_LINE);
|
||||
val = PQresultErrorField(res, PG_DIAG_SOURCE_FUNCTION);
|
||||
if (val || valf || vall)
|
||||
{
|
||||
appendPQExpBufferStr(&workBuf, libpq_gettext("LOCATION: "));
|
||||
|
@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: libpq-fe.h,v 1.99 2003/08/24 18:36:38 petere Exp $
|
||||
* $Id: libpq-fe.h,v 1.100 2003/08/27 00:33:34 petere Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -104,18 +104,6 @@ typedef enum
|
||||
PQERRORS_VERBOSE /* all the facts, ma'am */
|
||||
} PGVerbosity;
|
||||
|
||||
/* for PQresultErrorField() */
|
||||
#define PG_DIAG_SEVERITY 'S'
|
||||
#define PG_DIAG_SQLSTATE 'C'
|
||||
#define PG_DIAG_MESSAGE_PRIMARY 'M'
|
||||
#define PG_DIAG_MESSAGE_DETAIL 'D'
|
||||
#define PG_DIAG_MESSAGE_HINT 'H'
|
||||
#define PG_DIAG_STATEMENT_POSITION 'P'
|
||||
#define PG_DIAG_CONTEXT 'W'
|
||||
#define PG_DIAG_SOURCE_FILE 'F'
|
||||
#define PG_DIAG_SOURCE_LINE 'L'
|
||||
#define PG_DIAG_SOURCE_FUNCTION 'R'
|
||||
|
||||
/* PGconn encapsulates a connection to the backend.
|
||||
* The contents of this struct are not supposed to be known to applications.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user