From f2c2943aae143cd6cfa6e3195658e7e15de16000 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 27 Aug 2003 00:33:34 +0000 Subject: [PATCH] Share PG_DIAG_* macros between client and server and use them internally. --- src/backend/utils/error/elog.c | 22 +++++++++++----------- src/include/postgres_ext.h | 19 ++++++++++++++++++- src/interfaces/libpq/fe-exec.c | 6 +++--- src/interfaces/libpq/fe-protocol2.c | 10 +++++----- src/interfaces/libpq/fe-protocol3.c | 22 +++++++++++----------- src/interfaces/libpq/libpq-fe.h | 14 +------------- 6 files changed, 49 insertions(+), 44 deletions(-) diff --git a/src/backend/utils/error/elog.c b/src/backend/utils/error/elog.c index 15d6a1bb68..2f0e7dc7ea 100644 --- a/src/backend/utils/error/elog.c +++ b/src/backend/utils/error/elog.c @@ -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); } diff --git a/src/include/postgres_ext.h b/src/include/postgres_ext.h index b252453bbf..c61bd4de0f 100644 --- a/src/include/postgres_ext.h +++ b/src/include/postgres_ext.h @@ -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 diff --git a/src/interfaces/libpq/fe-exec.c b/src/interfaces/libpq/fe-exec.c index 3e65276681..f9ce9564a7 100644 --- a/src/interfaces/libpq/fe-exec.c +++ b/src/interfaces/libpq/fe-exec.c @@ -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? */ /* diff --git a/src/interfaces/libpq/fe-protocol2.c b/src/interfaces/libpq/fe-protocol2.c index 834aa69bbf..1b76699691 100644 --- a/src/interfaces/libpq/fe-protocol2.c +++ b/src/interfaces/libpq/fe-protocol2.c @@ -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); } /* diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c index 0591d63da9..ba06a37848 100644 --- a/src/interfaces/libpq/fe-protocol3.c +++ b/src/interfaces/libpq/fe-protocol3.c @@ -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: ")); diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h index 3e068cc6dc..bafe0ddd6c 100644 --- a/src/interfaces/libpq/libpq-fe.h +++ b/src/interfaces/libpq/libpq-fe.h @@ -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. */ -- 2.40.0