8
8
*
9
9
*
10
10
* 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 $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -440,33 +440,44 @@ pqPrepareAsyncResult(PGconn *conn)
440
440
}
441
441
442
442
/*
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.
444
447
*
445
448
* The supplied text is taken as primary message (ie., it should not include
446
449
* a trailing newline, and should not be more than one line).
447
450
*/
448
451
void
449
- pqInternalNotice (const PGNoticeHooks * hooks ,const char * msgtext )
452
+ pqInternalNotice (const PGNoticeHooks * hooks ,const char * fmt , ... )
450
453
{
454
+ char msgBuf [1024 ];
455
+ va_list args ;
451
456
PGresult * res ;
452
457
453
458
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 */
455
466
456
467
/* Make a PGresult to pass to the notice receiver */
457
468
res = PQmakeEmptyPGresult (NULL ,PGRES_NONFATAL_ERROR );
458
469
res -> noticeHooks = * hooks ;
459
470
/*
460
471
* Set up fields of notice.
461
472
*/
462
- pqSaveMessageField (res ,'M' ,msgtext );
473
+ pqSaveMessageField (res ,'M' ,msgBuf );
463
474
pqSaveMessageField (res ,'S' ,libpq_gettext ("NOTICE" ));
464
475
/* XXX should provide a SQLSTATE too? */
465
476
/*
466
477
* Result text is always just the primary message + newline.
467
478
*/
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 );
470
481
/*
471
482
* Pass to receiver, then free it.
472
483
*/
@@ -1585,16 +1596,13 @@ PQbinaryTuples(const PGresult *res)
1585
1596
static int
1586
1597
check_field_number (const PGresult * res ,int field_num )
1587
1598
{
1588
- char noticeBuf [128 ];
1589
-
1590
1599
if (!res )
1591
1600
return FALSE;/* no way to display error message... */
1592
1601
if (field_num < 0 || field_num >=res -> numAttributes )
1593
1602
{
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 );
1598
1606
return FALSE;
1599
1607
}
1600
1608
return TRUE;
@@ -1604,24 +1612,20 @@ static int
1604
1612
check_tuple_field_number (const PGresult * res ,
1605
1613
int tup_num ,int field_num )
1606
1614
{
1607
- char noticeBuf [128 ];
1608
-
1609
1615
if (!res )
1610
1616
return FALSE;/* no way to display error message... */
1611
1617
if (tup_num < 0 || tup_num >=res -> ntups )
1612
1618
{
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 );
1617
1622
return FALSE;
1618
1623
}
1619
1624
if (field_num < 0 || field_num >=res -> numAttributes )
1620
1625
{
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 );
1625
1629
return FALSE;
1626
1630
}
1627
1631
return TRUE;
@@ -1822,7 +1826,6 @@ PQoidValue(const PGresult *res)
1822
1826
char *
1823
1827
PQcmdTuples (PGresult * res )
1824
1828
{
1825
- char noticeBuf [128 ];
1826
1829
char * p ;
1827
1830
1828
1831
if (!res )
@@ -1850,10 +1853,9 @@ PQcmdTuples(PGresult *res)
1850
1853
1851
1854
if (* p == 0 )
1852
1855
{
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 );
1857
1859
return "" ;
1858
1860
}
1859
1861