just a preformatted message; per suggestion by Sean Chittenden.
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.251 2003/06/23 17:03:19 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.252 2003/06/23 19:20:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
defaultNoticeReceiver(void *arg, const PGresult *res)
{
(void) arg; /* not used */
- (*res->noticeHooks.noticeProc) (res->noticeHooks.noticeProcArg,
- PQresultErrorMessage(res));
+ if (res->noticeHooks.noticeProc != NULL)
+ (*res->noticeHooks.noticeProc) (res->noticeHooks.noticeProcArg,
+ PQresultErrorMessage(res));
}
/*
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.139 2003/06/21 21:51:34 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.140 2003/06/23 19:20:24 tgl Exp $
*
*-------------------------------------------------------------------------
*/
}
/*
- * pqInternalNotice - helper routine for internally-generated notices
+ * pqInternalNotice - produce an internally-generated notice message
+ *
+ * A format string and optional arguments can be passed. Note that we do
+ * libpq_gettext() here, so callers need not.
*
* The supplied text is taken as primary message (ie., it should not include
* a trailing newline, and should not be more than one line).
*/
void
-pqInternalNotice(const PGNoticeHooks *hooks, const char *msgtext)
+pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt, ...)
{
+ char msgBuf[1024];
+ va_list args;
PGresult *res;
if (hooks->noticeRec == NULL)
- return; /* nobody home? */
+ return; /* nobody home to receive notice? */
+
+ /* Format the message */
+ va_start(args, fmt);
+ vsnprintf(msgBuf, sizeof(msgBuf), libpq_gettext(fmt), args);
+ va_end(args);
+ msgBuf[sizeof(msgBuf)-1] = '\0'; /* make real sure it's terminated */
/* Make a PGresult to pass to the notice receiver */
res = PQmakeEmptyPGresult(NULL, PGRES_NONFATAL_ERROR);
/*
* Set up fields of notice.
*/
- pqSaveMessageField(res, 'M', msgtext);
+ pqSaveMessageField(res, 'M', msgBuf);
pqSaveMessageField(res, 'S', libpq_gettext("NOTICE"));
/* XXX should provide a SQLSTATE too? */
/*
* Result text is always just the primary message + newline.
*/
- res->errMsg = (char *) pqResultAlloc(res, strlen(msgtext) + 2, FALSE);
- sprintf(res->errMsg, "%s\n", msgtext);
+ res->errMsg = (char *) pqResultAlloc(res, strlen(msgBuf) + 2, FALSE);
+ sprintf(res->errMsg, "%s\n", msgBuf);
/*
* Pass to receiver, then free it.
*/
static int
check_field_number(const PGresult *res, int field_num)
{
- char noticeBuf[128];
-
if (!res)
return FALSE; /* no way to display error message... */
if (field_num < 0 || field_num >= res->numAttributes)
{
- snprintf(noticeBuf, sizeof(noticeBuf),
- libpq_gettext("column number %d is out of range 0..%d"),
- field_num, res->numAttributes - 1);
- PGDONOTICE(res, noticeBuf);
+ pqInternalNotice(&res->noticeHooks,
+ "column number %d is out of range 0..%d",
+ field_num, res->numAttributes - 1);
return FALSE;
}
return TRUE;
check_tuple_field_number(const PGresult *res,
int tup_num, int field_num)
{
- char noticeBuf[128];
-
if (!res)
return FALSE; /* no way to display error message... */
if (tup_num < 0 || tup_num >= res->ntups)
{
- snprintf(noticeBuf, sizeof(noticeBuf),
- libpq_gettext("row number %d is out of range 0..%d"),
- tup_num, res->ntups - 1);
- PGDONOTICE(res, noticeBuf);
+ pqInternalNotice(&res->noticeHooks,
+ "row number %d is out of range 0..%d",
+ tup_num, res->ntups - 1);
return FALSE;
}
if (field_num < 0 || field_num >= res->numAttributes)
{
- snprintf(noticeBuf, sizeof(noticeBuf),
- libpq_gettext("column number %d is out of range 0..%d"),
- field_num, res->numAttributes - 1);
- PGDONOTICE(res, noticeBuf);
+ pqInternalNotice(&res->noticeHooks,
+ "column number %d is out of range 0..%d",
+ field_num, res->numAttributes - 1);
return FALSE;
}
return TRUE;
char *
PQcmdTuples(PGresult *res)
{
- char noticeBuf[128];
char *p;
if (!res)
if (*p == 0)
{
- snprintf(noticeBuf, sizeof(noticeBuf),
- libpq_gettext("could not interpret result from server: %s"),
- res->cmdStatus);
- PGDONOTICE(res, noticeBuf);
+ pqInternalNotice(&res->noticeHooks,
+ "could not interpret result from server: %s",
+ res->cmdStatus);
return "";
}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.97 2003/06/21 21:51:34 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.98 2003/06/23 19:20:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
{
uint16 tmp2;
uint32 tmp4;
- char noticeBuf[64];
switch (bytes)
{
*result = (int) ntohl(tmp4);
break;
default:
- snprintf(noticeBuf, sizeof(noticeBuf),
- libpq_gettext("integer of size %lu not supported by pqGetInt"),
- (unsigned long) bytes);
- PGDONOTICE(conn, noticeBuf);
+ pqInternalNotice(&conn->noticeHooks,
+ "integer of size %lu not supported by pqGetInt",
+ (unsigned long) bytes);
return EOF;
}
{
uint16 tmp2;
uint32 tmp4;
- char noticeBuf[64];
switch (bytes)
{
return EOF;
break;
default:
- snprintf(noticeBuf, sizeof(noticeBuf),
- libpq_gettext("integer of size %lu not supported by pqPutInt"),
- (unsigned long) bytes);
- PGDONOTICE(conn, noticeBuf);
+ pqInternalNotice(&conn->noticeHooks,
+ "integer of size %lu not supported by pqPutInt",
+ (unsigned long) bytes);
return EOF;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.3 2003/06/21 23:25:38 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol2.c,v 1.4 2003/06/23 19:20:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
pqParseInput2(PGconn *conn)
{
char id;
- char noticeWorkspace[128];
/*
* Loop to parse successive complete messages available in the buffer.
}
else
{
- snprintf(noticeWorkspace, sizeof(noticeWorkspace),
- libpq_gettext("message type 0x%02x arrived from server while idle"),
- id);
- PGDONOTICE(conn, noticeWorkspace);
+ pqInternalNotice(&conn->noticeHooks,
+ "message type 0x%02x arrived from server while idle",
+ id);
/* Discard the unexpected message; good idea?? */
conn->inStart = conn->inEnd;
break;
if (pqGetc(&id, conn))
return;
if (id != '\0')
- {
- snprintf(noticeWorkspace, sizeof(noticeWorkspace),
- libpq_gettext("unexpected character %c following empty query response (\"I\" message)"),
- id);
- PGDONOTICE(conn, noticeWorkspace);
- }
+ pqInternalNotice(&conn->noticeHooks,
+ "unexpected character %c following empty query response (\"I\" message)",
+ id);
if (conn->result == NULL)
conn->result = PQmakeEmptyPGresult(conn,
PGRES_EMPTY_QUERY);
}
else
{
- snprintf(noticeWorkspace, sizeof(noticeWorkspace),
- libpq_gettext("server sent data (\"D\" message) without prior row description (\"T\" message)"));
- PGDONOTICE(conn, noticeWorkspace);
+ pqInternalNotice(&conn->noticeHooks,
+ "server sent data (\"D\" message) without prior row description (\"T\" message)");
/* Discard the unexpected message; good idea?? */
conn->inStart = conn->inEnd;
return;
}
else
{
- snprintf(noticeWorkspace, sizeof(noticeWorkspace),
- libpq_gettext("server sent binary data (\"B\" message) without prior row description (\"T\" message)"));
- PGDONOTICE(conn, noticeWorkspace);
+ pqInternalNotice(&conn->noticeHooks,
+ "server sent binary data (\"B\" message) without prior row description (\"T\" message)");
/* Discard the unexpected message; good idea?? */
conn->inStart = conn->inEnd;
return;
}
else
{
- (*res->noticeHooks.noticeRec) (res->noticeHooks.noticeRecArg, res);
+ if (res->noticeHooks.noticeRec != NULL)
+ (*res->noticeHooks.noticeRec) (res->noticeHooks.noticeRecArg, res);
PQclear(res);
}
if (svLast == '\n')
conn->errorMessage.data[conn->errorMessage.len-1] = '\0';
- PGDONOTICE(conn, conn->errorMessage.data);
+ pqInternalNotice(&conn->noticeHooks, "%s", conn->errorMessage.data);
conn->errorMessage.data[conn->errorMessage.len-1] = svLast;
}
* entirely due to application screwup of the copy in/out protocol. To
* recover, reset the connection (talk about using a sledgehammer...)
*/
- PGDONOTICE(conn, libpq_gettext("lost synchronization with server, resetting connection"));
+ pqInternalNotice(&conn->noticeHooks,
+ "lost synchronization with server, resetting connection");
/*
* Users doing non-blocking connections need to handle the reset
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.3 2003/06/21 23:25:38 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-protocol3.c,v 1.4 2003/06/23 19:20:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
char id;
int msgLength;
int avail;
- char noticeWorkspace[128];
/*
* Loop to parse successive complete messages available in the buffer.
}
else
{
- snprintf(noticeWorkspace, sizeof(noticeWorkspace),
- libpq_gettext("message type 0x%02x arrived from server while idle"),
- id);
- PGDONOTICE(conn, noticeWorkspace);
+ pqInternalNotice(&conn->noticeHooks,
+ "message type 0x%02x arrived from server while idle",
+ id);
/* Discard the unexpected message */
conn->inCursor += msgLength;
}
{
/* We can cheat a little here and not copy the message. */
res->errMsg = workBuf.data;
- (*res->noticeHooks.noticeRec) (res->noticeHooks.noticeRecArg, res);
+ if (res->noticeHooks.noticeRec != NULL)
+ (*res->noticeHooks.noticeRec) (res->noticeHooks.noticeRecArg, res);
PQclear(res);
}
if (svLast == '\n')
conn->errorMessage.data[conn->errorMessage.len-1] = '\0';
- PGDONOTICE(conn, conn->errorMessage.data);
+ pqInternalNotice(&conn->noticeHooks, "%s", conn->errorMessage.data);
conn->errorMessage.data[conn->errorMessage.len-1] = svLast;
}
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-int.h,v 1.75 2003/06/21 21:51:34 tgl Exp $
+ * $Id: libpq-int.h,v 1.76 2003/06/23 19:20:25 tgl Exp $
*
*-------------------------------------------------------------------------
*/
extern void pqClearAsyncResult(PGconn *conn);
extern void pqSaveErrorResult(PGconn *conn);
extern PGresult *pqPrepareAsyncResult(PGconn *conn);
-extern void pqInternalNotice(const PGNoticeHooks *hooks, const char *msgtext);
+extern void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt, ...)
+/* This lets gcc check the format string for consistency. */
+__attribute__((format(printf, 2, 3)));
extern int pqAddTuple(PGresult *res, PGresAttValue *tup);
extern void pqSaveMessageField(PGresult *res, char code,
const char *value);
extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
extern ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len);
-/* Note: PGDONOTICE macro will work if applied to either PGconn or PGresult */
-#define PGDONOTICE(conn,message) \
- pqInternalNotice(&(conn)->noticeHooks, (message))
-
/*
* this is so that we can check if a connection is non-blocking internally
* without the overhead of a function call
-# $Header: /cvsroot/pgsql/src/interfaces/libpq/nls.mk,v 1.8 2002/09/22 20:57:21 petere Exp $
+# $Header: /cvsroot/pgsql/src/interfaces/libpq/nls.mk,v 1.9 2003/06/23 19:20:25 tgl Exp $
CATALOG_NAME := libpq
AVAIL_LANGUAGES := cs de es fr pt_BR ru sv zh_CN zh_TW
GETTEXT_FILES := fe-auth.c fe-connect.c fe-exec.c fe-lobj.c fe-misc.c fe-secure.c
-GETTEXT_TRIGGERS:= libpq_gettext
+GETTEXT_TRIGGERS:= libpq_gettext pqInternalNotice:2