Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf2c2943

Browse files
committed
Share PG_DIAG_* macros between client and server and use them internally.
1 parent73e3edf commitf2c2943

File tree

6 files changed

+49
-44
lines changed

6 files changed

+49
-44
lines changed

‎src/backend/utils/error/elog.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.120 2003/08/26 21:15:27 tgl Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.121 2003/08/27 00:33:34 petere Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -1165,7 +1165,7 @@ send_message_to_frontend(ErrorData *edata)
11651165
intssval;
11661166
inti;
11671167

1168-
pq_sendbyte(&msgbuf,'S');
1168+
pq_sendbyte(&msgbuf,PG_DIAG_SEVERITY);
11691169
pq_sendstring(&msgbuf,error_severity(edata->elevel));
11701170

11711171
/* unpack MAKE_SQLSTATE code */
@@ -1177,57 +1177,57 @@ send_message_to_frontend(ErrorData *edata)
11771177
}
11781178
tbuf[i]='\0';
11791179

1180-
pq_sendbyte(&msgbuf,'C');
1180+
pq_sendbyte(&msgbuf,PG_DIAG_SQLSTATE);
11811181
pq_sendstring(&msgbuf,tbuf);
11821182

11831183
/* M field is required per protocol, so always send something */
1184-
pq_sendbyte(&msgbuf,'M');
1184+
pq_sendbyte(&msgbuf,PG_DIAG_MESSAGE_PRIMARY);
11851185
if (edata->message)
11861186
pq_sendstring(&msgbuf,edata->message);
11871187
else
11881188
pq_sendstring(&msgbuf,gettext("missing error text"));
11891189

11901190
if (edata->detail)
11911191
{
1192-
pq_sendbyte(&msgbuf,'D');
1192+
pq_sendbyte(&msgbuf,PG_DIAG_MESSAGE_DETAIL);
11931193
pq_sendstring(&msgbuf,edata->detail);
11941194
}
11951195

11961196
if (edata->hint)
11971197
{
1198-
pq_sendbyte(&msgbuf,'H');
1198+
pq_sendbyte(&msgbuf,PG_DIAG_MESSAGE_HINT);
11991199
pq_sendstring(&msgbuf,edata->hint);
12001200
}
12011201

12021202
if (edata->context)
12031203
{
1204-
pq_sendbyte(&msgbuf,'W');
1204+
pq_sendbyte(&msgbuf,PG_DIAG_CONTEXT);
12051205
pq_sendstring(&msgbuf,edata->context);
12061206
}
12071207

12081208
if (edata->cursorpos>0)
12091209
{
12101210
snprintf(tbuf,sizeof(tbuf),"%d",edata->cursorpos);
1211-
pq_sendbyte(&msgbuf,'P');
1211+
pq_sendbyte(&msgbuf,PG_DIAG_STATEMENT_POSITION);
12121212
pq_sendstring(&msgbuf,tbuf);
12131213
}
12141214

12151215
if (edata->filename)
12161216
{
1217-
pq_sendbyte(&msgbuf,'F');
1217+
pq_sendbyte(&msgbuf,PG_DIAG_SOURCE_FILE);
12181218
pq_sendstring(&msgbuf,edata->filename);
12191219
}
12201220

12211221
if (edata->lineno>0)
12221222
{
12231223
snprintf(tbuf,sizeof(tbuf),"%d",edata->lineno);
1224-
pq_sendbyte(&msgbuf,'L');
1224+
pq_sendbyte(&msgbuf,PG_DIAG_SOURCE_LINE);
12251225
pq_sendstring(&msgbuf,tbuf);
12261226
}
12271227

12281228
if (edata->funcname)
12291229
{
1230-
pq_sendbyte(&msgbuf,'R');
1230+
pq_sendbyte(&msgbuf,PG_DIAG_SOURCE_FUNCTION);
12311231
pq_sendstring(&msgbuf,edata->funcname);
12321232
}
12331233

‎src/include/postgres_ext.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*use header files that are otherwise internal to Postgres to interface
1616
*with the backend.
1717
*
18-
* $Id: postgres_ext.h,v 1.12 2003/03/18 17:21:07 momjian Exp $
18+
* $Id: postgres_ext.h,v 1.13 2003/08/27 00:33:34 petere Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -47,4 +47,21 @@ typedef unsigned int Oid;
4747
*/
4848
#defineNAMEDATALEN 64
4949

50+
51+
/*
52+
* Identifiers of error message fields. Kept here to keep common
53+
* between frontend and backend, and also to export them to libpq
54+
* applications.
55+
*/
56+
#definePG_DIAG_SEVERITY'S'
57+
#definePG_DIAG_SQLSTATE'C'
58+
#definePG_DIAG_MESSAGE_PRIMARY'M'
59+
#definePG_DIAG_MESSAGE_DETAIL'D'
60+
#definePG_DIAG_MESSAGE_HINT'H'
61+
#definePG_DIAG_STATEMENT_POSITION 'P'
62+
#definePG_DIAG_CONTEXT'W'
63+
#definePG_DIAG_SOURCE_FILE'F'
64+
#definePG_DIAG_SOURCE_LINE'L'
65+
#definePG_DIAG_SOURCE_FUNCTION'R'
66+
5067
#endif

‎src/interfaces/libpq/fe-exec.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.145 2003/08/13 18:56:21 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.146 2003/08/27 00:33:34 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -480,8 +480,8 @@ pqInternalNotice(const PGNoticeHooks * hooks, const char *fmt,...)
480480
/*
481481
* Set up fields of notice.
482482
*/
483-
pqSaveMessageField(res,'M',msgBuf);
484-
pqSaveMessageField(res,'S',libpq_gettext("NOTICE"));
483+
pqSaveMessageField(res,PG_DIAG_MESSAGE_PRIMARY,msgBuf);
484+
pqSaveMessageField(res,PG_DIAG_SEVERITY,libpq_gettext("NOTICE"));
485485
/* XXX should provide a SQLSTATE too? */
486486

487487
/*

‎src/interfaces/libpq/fe-protocol2.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.6 2003/08/04 02:40:20 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.7 2003/08/27 00:33:34 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -828,7 +828,7 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
828828
{
829829
/* what comes before the colon is severity */
830830
*splitp='\0';
831-
pqSaveMessageField(res,'S',workBuf.data);
831+
pqSaveMessageField(res,PG_DIAG_SEVERITY,workBuf.data);
832832
startp=splitp+3;
833833
}
834834
else
@@ -841,16 +841,16 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
841841
{
842842
/* what comes before the newline is primary message */
843843
*splitp++='\0';
844-
pqSaveMessageField(res,'M',startp);
844+
pqSaveMessageField(res,PG_DIAG_MESSAGE_PRIMARY,startp);
845845
/* the rest is detail; strip any leading whitespace */
846846
while (*splitp&&isspace((unsignedchar)*splitp))
847847
splitp++;
848-
pqSaveMessageField(res,'D',splitp);
848+
pqSaveMessageField(res,PG_DIAG_MESSAGE_DETAIL,splitp);
849849
}
850850
else
851851
{
852852
/* single-line message, so all primary */
853-
pqSaveMessageField(res,'M',startp);
853+
pqSaveMessageField(res,PG_DIAG_MESSAGE_PRIMARY,startp);
854854
}
855855

856856
/*

‎src/interfaces/libpq/fe-protocol3.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.8 2003/08/13 18:56:21 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.9 2003/08/27 00:33:34 petere Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -614,19 +614,19 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
614614
* Now build the "overall" error message for PQresultErrorMessage.
615615
*/
616616
resetPQExpBuffer(&workBuf);
617-
val=PQresultErrorField(res,'S');/* Severity */
617+
val=PQresultErrorField(res,PG_DIAG_SEVERITY);
618618
if (val)
619619
appendPQExpBuffer(&workBuf,"%s: ",val);
620620
if (conn->verbosity==PQERRORS_VERBOSE)
621621
{
622-
val=PQresultErrorField(res,'C');/* SQLSTATE Code */
622+
val=PQresultErrorField(res,PG_DIAG_SQLSTATE);
623623
if (val)
624624
appendPQExpBuffer(&workBuf,"%s: ",val);
625625
}
626-
val=PQresultErrorField(res,'M');/* Primary message */
626+
val=PQresultErrorField(res,PG_DIAG_MESSAGE_PRIMARY);
627627
if (val)
628628
appendPQExpBufferStr(&workBuf,val);
629-
val=PQresultErrorField(res,'P');/* Position */
629+
val=PQresultErrorField(res,PG_DIAG_STATEMENT_POSITION);
630630
if (val)
631631
{
632632
/* translator: %s represents a digit string */
@@ -635,13 +635,13 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
635635
appendPQExpBufferChar(&workBuf,'\n');
636636
if (conn->verbosity!=PQERRORS_TERSE)
637637
{
638-
val=PQresultErrorField(res,'D');/* Detail */
638+
val=PQresultErrorField(res,PG_DIAG_MESSAGE_DETAIL);
639639
if (val)
640640
appendPQExpBuffer(&workBuf,libpq_gettext("DETAIL: %s\n"),val);
641-
val=PQresultErrorField(res,'H');/* Hint */
641+
val=PQresultErrorField(res,PG_DIAG_MESSAGE_HINT);
642642
if (val)
643643
appendPQExpBuffer(&workBuf,libpq_gettext("HINT: %s\n"),val);
644-
val=PQresultErrorField(res,'W');/* Where */
644+
val=PQresultErrorField(res,PG_DIAG_CONTEXT);
645645
if (val)
646646
appendPQExpBuffer(&workBuf,libpq_gettext("CONTEXT: %s\n"),val);
647647
}
@@ -650,9 +650,9 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
650650
constchar*valf;
651651
constchar*vall;
652652

653-
valf=PQresultErrorField(res,'F');/* File */
654-
vall=PQresultErrorField(res,'L');/* Line */
655-
val=PQresultErrorField(res,'R');/* Routine */
653+
valf=PQresultErrorField(res,PG_DIAG_SOURCE_FILE);
654+
vall=PQresultErrorField(res,PG_DIAG_SOURCE_LINE);
655+
val=PQresultErrorField(res,PG_DIAG_SOURCE_FUNCTION);
656656
if (val||valf||vall)
657657
{
658658
appendPQExpBufferStr(&workBuf,libpq_gettext("LOCATION: "));

‎src/interfaces/libpq/libpq-fe.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
10-
* $Id: libpq-fe.h,v 1.99 2003/08/24 18:36:38 petere Exp $
10+
* $Id: libpq-fe.h,v 1.100 2003/08/27 00:33:34 petere Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -104,18 +104,6 @@ typedef enum
104104
PQERRORS_VERBOSE/* all the facts, ma'am */
105105
}PGVerbosity;
106106

107-
/* for PQresultErrorField() */
108-
#definePG_DIAG_SEVERITY'S'
109-
#definePG_DIAG_SQLSTATE'C'
110-
#definePG_DIAG_MESSAGE_PRIMARY'M'
111-
#definePG_DIAG_MESSAGE_DETAIL'D'
112-
#definePG_DIAG_MESSAGE_HINT'H'
113-
#definePG_DIAG_STATEMENT_POSITION 'P'
114-
#definePG_DIAG_CONTEXT'W'
115-
#definePG_DIAG_SOURCE_FILE'F'
116-
#definePG_DIAG_SOURCE_LINE'L'
117-
#definePG_DIAG_SOURCE_FUNCTION'R'
118-
119107
/* PGconn encapsulates a connection to the backend.
120108
* The contents of this struct are not supposed to be known to applications.
121109
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp