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

Commitab5c775

Browse files
committed
Change pqInternalNotice to accept a format string and args instead of
just a preformatted message; per suggestion by Sean Chittenden.
1 parent4086253 commitab5c775

File tree

7 files changed

+70
-79
lines changed

7 files changed

+70
-79
lines changed

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

Lines changed: 4 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-connect.c,v 1.251 2003/06/2317:03:19 momjian Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.252 2003/06/2319:20:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2843,8 +2843,9 @@ static void
28432843
defaultNoticeReceiver(void*arg,constPGresult*res)
28442844
{
28452845
(void)arg;/* not used */
2846-
(*res->noticeHooks.noticeProc) (res->noticeHooks.noticeProcArg,
2847-
PQresultErrorMessage(res));
2846+
if (res->noticeHooks.noticeProc!=NULL)
2847+
(*res->noticeHooks.noticeProc) (res->noticeHooks.noticeProcArg,
2848+
PQresultErrorMessage(res));
28482849
}
28492850

28502851
/*

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

Lines changed: 30 additions & 28 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.139 2003/06/21 21:51:34 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.140 2003/06/23 19:20:24 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -440,33 +440,44 @@ pqPrepareAsyncResult(PGconn *conn)
440440
}
441441

442442
/*
443-
* pqInternalNotice - helper routine for internally-generated notices
443+
* pqInternalNotice - produce an internally-generated notice message
444+
*
445+
* A format string and optional arguments can be passed. Note that we do
446+
* libpq_gettext() here, so callers need not.
444447
*
445448
* The supplied text is taken as primary message (ie., it should not include
446449
* a trailing newline, and should not be more than one line).
447450
*/
448451
void
449-
pqInternalNotice(constPGNoticeHooks*hooks,constchar*msgtext)
452+
pqInternalNotice(constPGNoticeHooks*hooks,constchar*fmt, ...)
450453
{
454+
charmsgBuf[1024];
455+
va_listargs;
451456
PGresult*res;
452457

453458
if (hooks->noticeRec==NULL)
454-
return;/* nobody home? */
459+
return;/* nobody home to receive notice? */
460+
461+
/* Format the message */
462+
va_start(args,fmt);
463+
vsnprintf(msgBuf,sizeof(msgBuf),libpq_gettext(fmt),args);
464+
va_end(args);
465+
msgBuf[sizeof(msgBuf)-1]='\0';/* make real sure it's terminated */
455466

456467
/* Make a PGresult to pass to the notice receiver */
457468
res=PQmakeEmptyPGresult(NULL,PGRES_NONFATAL_ERROR);
458469
res->noticeHooks=*hooks;
459470
/*
460471
* Set up fields of notice.
461472
*/
462-
pqSaveMessageField(res,'M',msgtext);
473+
pqSaveMessageField(res,'M',msgBuf);
463474
pqSaveMessageField(res,'S',libpq_gettext("NOTICE"));
464475
/* XXX should provide a SQLSTATE too? */
465476
/*
466477
* Result text is always just the primary message + newline.
467478
*/
468-
res->errMsg= (char*)pqResultAlloc(res,strlen(msgtext)+2, FALSE);
469-
sprintf(res->errMsg,"%s\n",msgtext);
479+
res->errMsg= (char*)pqResultAlloc(res,strlen(msgBuf)+2, FALSE);
480+
sprintf(res->errMsg,"%s\n",msgBuf);
470481
/*
471482
* Pass to receiver, then free it.
472483
*/
@@ -1585,16 +1596,13 @@ PQbinaryTuples(const PGresult *res)
15851596
staticint
15861597
check_field_number(constPGresult*res,intfield_num)
15871598
{
1588-
charnoticeBuf[128];
1589-
15901599
if (!res)
15911600
return FALSE;/* no way to display error message... */
15921601
if (field_num<0||field_num >=res->numAttributes)
15931602
{
1594-
snprintf(noticeBuf,sizeof(noticeBuf),
1595-
libpq_gettext("column number %d is out of range 0..%d"),
1596-
field_num,res->numAttributes-1);
1597-
PGDONOTICE(res,noticeBuf);
1603+
pqInternalNotice(&res->noticeHooks,
1604+
"column number %d is out of range 0..%d",
1605+
field_num,res->numAttributes-1);
15981606
return FALSE;
15991607
}
16001608
return TRUE;
@@ -1604,24 +1612,20 @@ static int
16041612
check_tuple_field_number(constPGresult*res,
16051613
inttup_num,intfield_num)
16061614
{
1607-
charnoticeBuf[128];
1608-
16091615
if (!res)
16101616
return FALSE;/* no way to display error message... */
16111617
if (tup_num<0||tup_num >=res->ntups)
16121618
{
1613-
snprintf(noticeBuf,sizeof(noticeBuf),
1614-
libpq_gettext("row number %d is out of range 0..%d"),
1615-
tup_num,res->ntups-1);
1616-
PGDONOTICE(res,noticeBuf);
1619+
pqInternalNotice(&res->noticeHooks,
1620+
"row number %d is out of range 0..%d",
1621+
tup_num,res->ntups-1);
16171622
return FALSE;
16181623
}
16191624
if (field_num<0||field_num >=res->numAttributes)
16201625
{
1621-
snprintf(noticeBuf,sizeof(noticeBuf),
1622-
libpq_gettext("column number %d is out of range 0..%d"),
1623-
field_num,res->numAttributes-1);
1624-
PGDONOTICE(res,noticeBuf);
1626+
pqInternalNotice(&res->noticeHooks,
1627+
"column number %d is out of range 0..%d",
1628+
field_num,res->numAttributes-1);
16251629
return FALSE;
16261630
}
16271631
return TRUE;
@@ -1822,7 +1826,6 @@ PQoidValue(const PGresult *res)
18221826
char*
18231827
PQcmdTuples(PGresult*res)
18241828
{
1825-
charnoticeBuf[128];
18261829
char*p;
18271830

18281831
if (!res)
@@ -1850,10 +1853,9 @@ PQcmdTuples(PGresult *res)
18501853

18511854
if (*p==0)
18521855
{
1853-
snprintf(noticeBuf,sizeof(noticeBuf),
1854-
libpq_gettext("could not interpret result from server: %s"),
1855-
res->cmdStatus);
1856-
PGDONOTICE(res,noticeBuf);
1856+
pqInternalNotice(&res->noticeHooks,
1857+
"could not interpret result from server: %s",
1858+
res->cmdStatus);
18571859
return"";
18581860
}
18591861

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

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* Portions Copyright (c) 1994, Regents of the University of California
2424
*
2525
* IDENTIFICATION
26-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.97 2003/06/21 21:51:34 tgl Exp $
26+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.98 2003/06/23 19:20:25 tgl Exp $
2727
*
2828
*-------------------------------------------------------------------------
2929
*/
@@ -206,7 +206,6 @@ pqGetInt(int *result, size_t bytes, PGconn *conn)
206206
{
207207
uint16tmp2;
208208
uint32tmp4;
209-
charnoticeBuf[64];
210209

211210
switch (bytes)
212211
{
@@ -225,10 +224,9 @@ pqGetInt(int *result, size_t bytes, PGconn *conn)
225224
*result= (int)ntohl(tmp4);
226225
break;
227226
default:
228-
snprintf(noticeBuf,sizeof(noticeBuf),
229-
libpq_gettext("integer of size %lu not supported by pqGetInt"),
230-
(unsigned long)bytes);
231-
PGDONOTICE(conn,noticeBuf);
227+
pqInternalNotice(&conn->noticeHooks,
228+
"integer of size %lu not supported by pqGetInt",
229+
(unsigned long)bytes);
232230
returnEOF;
233231
}
234232

@@ -248,7 +246,6 @@ pqPutInt(int value, size_t bytes, PGconn *conn)
248246
{
249247
uint16tmp2;
250248
uint32tmp4;
251-
charnoticeBuf[64];
252249

253250
switch (bytes)
254251
{
@@ -263,10 +260,9 @@ pqPutInt(int value, size_t bytes, PGconn *conn)
263260
returnEOF;
264261
break;
265262
default:
266-
snprintf(noticeBuf,sizeof(noticeBuf),
267-
libpq_gettext("integer of size %lu not supported by pqPutInt"),
268-
(unsigned long)bytes);
269-
PGDONOTICE(conn,noticeBuf);
263+
pqInternalNotice(&conn->noticeHooks,
264+
"integer of size %lu not supported by pqPutInt",
265+
(unsigned long)bytes);
270266
returnEOF;
271267
}
272268

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

Lines changed: 16 additions & 21 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.3 2003/06/21 23:25:38 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.4 2003/06/23 19:20:25 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -358,7 +358,6 @@ void
358358
pqParseInput2(PGconn*conn)
359359
{
360360
charid;
361-
charnoticeWorkspace[128];
362361

363362
/*
364363
* Loop to parse successive complete messages available in the buffer.
@@ -424,10 +423,9 @@ pqParseInput2(PGconn *conn)
424423
}
425424
else
426425
{
427-
snprintf(noticeWorkspace,sizeof(noticeWorkspace),
428-
libpq_gettext("message type 0x%02x arrived from server while idle"),
429-
id);
430-
PGDONOTICE(conn,noticeWorkspace);
426+
pqInternalNotice(&conn->noticeHooks,
427+
"message type 0x%02x arrived from server while idle",
428+
id);
431429
/* Discard the unexpected message; good idea?? */
432430
conn->inStart=conn->inEnd;
433431
break;
@@ -464,12 +462,9 @@ pqParseInput2(PGconn *conn)
464462
if (pqGetc(&id,conn))
465463
return;
466464
if (id!='\0')
467-
{
468-
snprintf(noticeWorkspace,sizeof(noticeWorkspace),
469-
libpq_gettext("unexpected character %c following empty query response (\"I\" message)"),
470-
id);
471-
PGDONOTICE(conn,noticeWorkspace);
472-
}
465+
pqInternalNotice(&conn->noticeHooks,
466+
"unexpected character %c following empty query response (\"I\" message)",
467+
id);
473468
if (conn->result==NULL)
474469
conn->result=PQmakeEmptyPGresult(conn,
475470
PGRES_EMPTY_QUERY);
@@ -522,9 +517,8 @@ pqParseInput2(PGconn *conn)
522517
}
523518
else
524519
{
525-
snprintf(noticeWorkspace,sizeof(noticeWorkspace),
526-
libpq_gettext("server sent data (\"D\" message) without prior row description (\"T\" message)"));
527-
PGDONOTICE(conn,noticeWorkspace);
520+
pqInternalNotice(&conn->noticeHooks,
521+
"server sent data (\"D\" message) without prior row description (\"T\" message)");
528522
/* Discard the unexpected message; good idea?? */
529523
conn->inStart=conn->inEnd;
530524
return;
@@ -539,9 +533,8 @@ pqParseInput2(PGconn *conn)
539533
}
540534
else
541535
{
542-
snprintf(noticeWorkspace,sizeof(noticeWorkspace),
543-
libpq_gettext("server sent binary data (\"B\" message) without prior row description (\"T\" message)"));
544-
PGDONOTICE(conn,noticeWorkspace);
536+
pqInternalNotice(&conn->noticeHooks,
537+
"server sent binary data (\"B\" message) without prior row description (\"T\" message)");
545538
/* Discard the unexpected message; good idea?? */
546539
conn->inStart=conn->inEnd;
547540
return;
@@ -872,7 +865,8 @@ pqGetErrorNotice2(PGconn *conn, bool isError)
872865
}
873866
else
874867
{
875-
(*res->noticeHooks.noticeRec) (res->noticeHooks.noticeRecArg,res);
868+
if (res->noticeHooks.noticeRec!=NULL)
869+
(*res->noticeHooks.noticeRec) (res->noticeHooks.noticeRecArg,res);
876870
PQclear(res);
877871
}
878872

@@ -1196,7 +1190,7 @@ pqEndcopy2(PGconn *conn)
11961190

11971191
if (svLast=='\n')
11981192
conn->errorMessage.data[conn->errorMessage.len-1]='\0';
1199-
PGDONOTICE(conn,conn->errorMessage.data);
1193+
pqInternalNotice(&conn->noticeHooks,"%s",conn->errorMessage.data);
12001194
conn->errorMessage.data[conn->errorMessage.len-1]=svLast;
12011195
}
12021196

@@ -1207,7 +1201,8 @@ pqEndcopy2(PGconn *conn)
12071201
* entirely due to application screwup of the copy in/out protocol. To
12081202
* recover, reset the connection (talk about using a sledgehammer...)
12091203
*/
1210-
PGDONOTICE(conn,libpq_gettext("lost synchronization with server, resetting connection"));
1204+
pqInternalNotice(&conn->noticeHooks,
1205+
"lost synchronization with server, resetting connection");
12111206

12121207
/*
12131208
* Users doing non-blocking connections need to handle the reset

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

Lines changed: 7 additions & 8 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.3 2003/06/21 23:25:38 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.4 2003/06/23 19:20:25 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -57,7 +57,6 @@ pqParseInput3(PGconn *conn)
5757
charid;
5858
intmsgLength;
5959
intavail;
60-
charnoticeWorkspace[128];
6160

6261
/*
6362
* Loop to parse successive complete messages available in the buffer.
@@ -172,10 +171,9 @@ pqParseInput3(PGconn *conn)
172171
}
173172
else
174173
{
175-
snprintf(noticeWorkspace,sizeof(noticeWorkspace),
176-
libpq_gettext("message type 0x%02x arrived from server while idle"),
177-
id);
178-
PGDONOTICE(conn,noticeWorkspace);
174+
pqInternalNotice(&conn->noticeHooks,
175+
"message type 0x%02x arrived from server while idle",
176+
id);
179177
/* Discard the unexpected message */
180178
conn->inCursor+=msgLength;
181179
}
@@ -667,7 +665,8 @@ pqGetErrorNotice3(PGconn *conn, bool isError)
667665
{
668666
/* We can cheat a little here and not copy the message. */
669667
res->errMsg=workBuf.data;
670-
(*res->noticeHooks.noticeRec) (res->noticeHooks.noticeRecArg,res);
668+
if (res->noticeHooks.noticeRec!=NULL)
669+
(*res->noticeHooks.noticeRec) (res->noticeHooks.noticeRecArg,res);
671670
PQclear(res);
672671
}
673672

@@ -1119,7 +1118,7 @@ pqEndcopy3(PGconn *conn)
11191118

11201119
if (svLast=='\n')
11211120
conn->errorMessage.data[conn->errorMessage.len-1]='\0';
1122-
PGDONOTICE(conn,conn->errorMessage.data);
1121+
pqInternalNotice(&conn->noticeHooks,"%s",conn->errorMessage.data);
11231122
conn->errorMessage.data[conn->errorMessage.len-1]=svLast;
11241123
}
11251124

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $Id: libpq-int.h,v 1.75 2003/06/21 21:51:34 tgl Exp $
15+
* $Id: libpq-int.h,v 1.76 2003/06/23 19:20:25 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -360,7 +360,9 @@ extern char *pqResultStrdup(PGresult *res, const char *str);
360360
externvoidpqClearAsyncResult(PGconn*conn);
361361
externvoidpqSaveErrorResult(PGconn*conn);
362362
externPGresult*pqPrepareAsyncResult(PGconn*conn);
363-
externvoidpqInternalNotice(constPGNoticeHooks*hooks,constchar*msgtext);
363+
externvoidpqInternalNotice(constPGNoticeHooks*hooks,constchar*fmt, ...)
364+
/* This lets gcc check the format string for consistency. */
365+
__attribute__((format(printf,2,3)));
364366
externintpqAddTuple(PGresult*res,PGresAttValue*tup);
365367
externvoidpqSaveMessageField(PGresult*res,charcode,
366368
constchar*value);
@@ -435,10 +437,6 @@ extern void pqsecure_close(PGconn *);
435437
externssize_tpqsecure_read(PGconn*,void*ptr,size_tlen);
436438
externssize_tpqsecure_write(PGconn*,constvoid*ptr,size_tlen);
437439

438-
/* Note: PGDONOTICE macro will work if applied to either PGconn or PGresult */
439-
#definePGDONOTICE(conn,message) \
440-
pqInternalNotice(&(conn)->noticeHooks, (message))
441-
442440
/*
443441
* this is so that we can check if a connection is non-blocking internally
444442
* without the overhead of a function call

‎src/interfaces/libpq/nls.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# $Header: /cvsroot/pgsql/src/interfaces/libpq/nls.mk,v 1.8 2002/09/2220:57:21 petere Exp $
1+
# $Header: /cvsroot/pgsql/src/interfaces/libpq/nls.mk,v 1.9 2003/06/23 19:20:25 tgl Exp $
22
CATALOG_NAME:= libpq
33
AVAIL_LANGUAGES:= cs de es fr pt_BR ru sv zh_CN zh_TW
44
GETTEXT_FILES:= fe-auth.c fe-connect.c fe-exec.c fe-lobj.c fe-misc.c fe-secure.c
5-
GETTEXT_TRIGGERS:= libpq_gettext
5+
GETTEXT_TRIGGERS:= libpq_gettext pqInternalNotice:2

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp