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 */
448451void
449- pqInternalNotice (const PGNoticeHooks * hooks ,const char * msgtext )
452+ pqInternalNotice (const PGNoticeHooks * hooks ,const char * fmt , ... )
450453{
454+ char msgBuf [1024 ];
455+ va_list args ;
451456PGresult * res ;
452457
453458if (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 */
457468res = PQmakeEmptyPGresult (NULL ,PGRES_NONFATAL_ERROR );
458469res -> noticeHooks = * hooks ;
459470/*
460471 * Set up fields of notice.
461472 */
462- pqSaveMessageField (res ,'M' ,msgtext );
473+ pqSaveMessageField (res ,'M' ,msgBuf );
463474pqSaveMessageField (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)
15851596static int
15861597check_field_number (const PGresult * res ,int field_num )
15871598{
1588- char noticeBuf [128 ];
1589-
15901599if (!res )
15911600return FALSE;/* no way to display error message... */
15921601if (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 );
15981606return FALSE;
15991607}
16001608return TRUE;
@@ -1604,24 +1612,20 @@ static int
16041612check_tuple_field_number (const PGresult * res ,
16051613int tup_num ,int field_num )
16061614{
1607- char noticeBuf [128 ];
1608-
16091615if (!res )
16101616return FALSE;/* no way to display error message... */
16111617if (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 );
16171622return FALSE;
16181623}
16191624if (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 );
16251629return FALSE;
16261630}
16271631return TRUE;
@@ -1822,7 +1826,6 @@ PQoidValue(const PGresult *res)
18221826char *
18231827PQcmdTuples (PGresult * res )
18241828{
1825- char noticeBuf [128 ];
18261829char * p ;
18271830
18281831if (!res )
@@ -1850,10 +1853,9 @@ PQcmdTuples(PGresult *res)
18501853
18511854if (* 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 );
18571859return "" ;
18581860}
18591861