1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-13 16:22:44 +03:00

Infrastructure for upgraded error reporting mechanism. elog.c is

rewritten and the protocol is changed, but most elog calls are still
elog calls.  Also, we need to contemplate mechanisms for controlling
all this functionality --- eg, how much stuff should appear in the
postmaster log?  And what API should libpq expose for it?
This commit is contained in:
Tom Lane
2003-04-24 21:16:45 +00:00
parent a91c5be6a4
commit f690920a75
33 changed files with 1713 additions and 728 deletions

View File

@@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.49 2003/03/20 03:34:55 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.50 2003/04/24 21:16:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1280,7 +1280,7 @@ NameListToString(List *names)
{
if (l != names)
appendStringInfoChar(&string, '.');
appendStringInfo(&string, "%s", strVal(lfirst(l)));
appendStringInfoString(&string, strVal(lfirst(l)));
}
return string.data;
@@ -1305,7 +1305,7 @@ NameListToQuotedString(List *names)
{
if (l != names)
appendStringInfoChar(&string, '.');
appendStringInfo(&string, "%s", quote_identifier(strVal(lfirst(l))));
appendStringInfoString(&string, quote_identifier(strVal(lfirst(l))));
}
return string.data;

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.195 2003/04/22 00:08:06 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.196 2003/04/24 21:16:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -100,13 +100,13 @@ static const char BinarySignature[12] = "PGBCOPY\n\377\r\n\0";
* Static communication variables ... pretty grotty, but COPY has
* never been reentrant...
*/
int copy_lineno = 0; /* exported for use by elog() -- dz */
static CopyDest copy_dest;
static FILE *copy_file; /* if copy_dest == COPY_FILE */
static StringInfo copy_msgbuf; /* if copy_dest == COPY_NEW_FE */
static bool fe_eof; /* true if detected end of copy data */
static EolType eol_type;
static EolType eol_type; /* EOL type of input */
static int copy_lineno; /* line number for error messages */
/*
* These static variables are used to avoid incurring overhead for each
@@ -1000,6 +1000,16 @@ CopyTo(Relation rel, List *attnumlist, bool binary, bool oids,
}
/*
* error context callback for COPY FROM
*/
static void
copy_in_error_callback(void *arg)
{
errcontext("COPY FROM, line %d", copy_lineno);
}
/*
* Copy FROM file to relation.
*/
@@ -1032,6 +1042,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
ExprState **defexprs; /* array of default att expressions */
ExprContext *econtext; /* used for ExecEvalExpr for default atts */
MemoryContext oldcontext = CurrentMemoryContext;
ErrorContextCallback errcontext;
tupDesc = RelationGetDescr(rel);
attr = tupDesc->attrs;
@@ -1188,16 +1199,22 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
values = (Datum *) palloc(num_phys_attrs * sizeof(Datum));
nulls = (char *) palloc(num_phys_attrs * sizeof(char));
/* Initialize static variables */
copy_lineno = 0;
eol_type = EOL_UNKNOWN;
fe_eof = false;
/* Make room for a PARAM_EXEC value for domain constraint checks */
if (hasConstraints)
econtext->ecxt_param_exec_vals = (ParamExecData *)
palloc0(sizeof(ParamExecData));
/* Initialize static variables */
fe_eof = false;
eol_type = EOL_UNKNOWN;
copy_lineno = 0;
/* Set up callback to identify error line number */
errcontext.callback = copy_in_error_callback;
errcontext.arg = NULL;
errcontext.previous = error_context_stack;
error_context_stack = &errcontext;
while (!done)
{
bool skip_tuple;
@@ -1502,7 +1519,7 @@ CopyFrom(Relation rel, List *attnumlist, bool binary, bool oids,
/*
* Done, clean up
*/
copy_lineno = 0;
error_context_stack = errcontext.previous;
MemoryContextSwitchTo(oldcontext);

View File

@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994-5, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.105 2003/04/03 22:35:48 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.106 2003/04/24 21:16:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -320,7 +320,7 @@ explain_outNode(StringInfo str,
if (plan == NULL)
{
appendStringInfo(str, "\n");
appendStringInfoChar(str, '\n');
return;
}
@@ -476,13 +476,13 @@ explain_outNode(StringInfo str,
break;
}
appendStringInfo(str, pname);
appendStringInfoString(str, pname);
switch (nodeTag(plan))
{
case T_IndexScan:
if (ScanDirectionIsBackward(((IndexScan *) plan)->indxorderdir))
appendStringInfo(str, " Backward");
appendStringInfo(str, " using ");
appendStringInfoString(str, " Backward");
appendStringInfoString(str, " using ");
i = 0;
foreach(l, ((IndexScan *) plan)->indxid)
{
@@ -590,7 +590,7 @@ explain_outNode(StringInfo str,
appendStringInfo(str, " (never executed)");
}
}
appendStringInfo(str, "\n");
appendStringInfoChar(str, '\n');
/* quals, sort keys, etc */
switch (nodeTag(plan))

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.89 2003/03/27 16:51:28 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/spi.c,v 1.90 2003/04/24 21:16:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -995,7 +995,7 @@ _SPI_execute(const char *src, int tcount, _SPI_plan *plan)
* Parse the request string into a list of raw parse trees.
*/
initStringInfo(&stri);
appendStringInfo(&stri, "%s", src);
appendStringInfoString(&stri, src);
raw_parsetree_list = pg_parse_query(&stri, argtypes, nargs);

View File

@@ -9,7 +9,7 @@
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
* $Id: stringinfo.c,v 1.33 2003/04/19 00:02:29 tgl Exp $
* $Id: stringinfo.c,v 1.34 2003/04/24 21:16:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -56,61 +56,102 @@ initStringInfo(StringInfo str)
/*
* appendStringInfo
*
* Format text data under the control of fmt (an sprintf-like format string)
* Format text data under the control of fmt (an sprintf-style format string)
* and append it to whatever is already in str. More space is allocated
* to str if necessary. This is sort of like a combination of sprintf and
* strcat.
*/
void
appendStringInfo(StringInfo str, const char *fmt,...)
appendStringInfo(StringInfo str, const char *fmt, ...)
{
for (;;)
{
va_list args;
bool success;
/* Try to format the data. */
va_start(args, fmt);
success = appendStringInfoVA(str, fmt, args);
va_end(args);
if (success)
break;
/* Double the buffer size and try again. */
enlargeStringInfo(str, str->maxlen);
}
}
/*
* appendStringInfoVA
*
* Attempt to format text data under the control of fmt (an sprintf-style
* format string) and append it to whatever is already in str. If successful
* return true; if not (because there's not enough space), return false
* without modifying str. Typically the caller would enlarge str and retry
* on false return --- see appendStringInfo for standard usage pattern.
*
* XXX This API is ugly, but there seems no alternative given the C spec's
* restrictions on what can portably be done with va_list arguments: you have
* to redo va_start before you can rescan the argument list, and we can't do
* that from here.
*/
bool
appendStringInfoVA(StringInfo str, const char *fmt, va_list args)
{
va_list args;
int avail,
nprinted;
Assert(str != NULL);
for (;;)
{
/*
* Try to format the given string into the available space; but if
* there's hardly any space, don't bother trying, just fall
* through to enlarge the buffer first.
*/
avail = str->maxlen - str->len - 1;
if (avail > 16)
{
/*
* Assert check here is to catch buggy vsnprintf that overruns
* the specified buffer length. Solaris 7 in 64-bit mode is
* an example of a platform with such a bug.
*/
/*
* If there's hardly any space, don't bother trying, just fail to make
* the caller enlarge the buffer first.
*/
avail = str->maxlen - str->len - 1;
if (avail < 16)
return false;
/*
* Assert check here is to catch buggy vsnprintf that overruns
* the specified buffer length. Solaris 7 in 64-bit mode is
* an example of a platform with such a bug.
*/
#ifdef USE_ASSERT_CHECKING
str->data[str->maxlen - 1] = '\0';
str->data[str->maxlen - 1] = '\0';
#endif
va_start(args, fmt);
nprinted = vsnprintf(str->data + str->len, avail,
fmt, args);
va_end(args);
nprinted = vsnprintf(str->data + str->len, avail, fmt, args);
Assert(str->data[str->maxlen - 1] == '\0');
Assert(str->data[str->maxlen - 1] == '\0');
/*
* Note: some versions of vsnprintf return the number of chars
* actually stored, but at least one returns -1 on failure. Be
* conservative about believing whether the print worked.
*/
if (nprinted >= 0 && nprinted < avail - 1)
{
/* Success. Note nprinted does not include trailing null. */
str->len += nprinted;
break;
}
}
/* Double the buffer size and try again. */
enlargeStringInfo(str, str->maxlen);
/*
* Note: some versions of vsnprintf return the number of chars
* actually stored, but at least one returns -1 on failure. Be
* conservative about believing whether the print worked.
*/
if (nprinted >= 0 && nprinted < avail - 1)
{
/* Success. Note nprinted does not include trailing null. */
str->len += nprinted;
return true;
}
/* Restore the trailing null so that str is unmodified. */
str->data[str->len] = '\0';
return false;
}
/*
* appendStringInfoString
*
* Append a null-terminated string to str.
* Like appendStringInfo(str, "%s", s) but faster.
*/
void
appendStringInfoString(StringInfo str, const char *s)
{
appendBinaryStringInfo(str, s, strlen(s));
}
/*
@@ -163,8 +204,8 @@ appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
* Make sure there is enough space for 'needed' more bytes
* ('needed' does not include the terminating null).
*
* External callers need not concern themselves with this, since all
* stringinfo.c routines do it automatically. However, if a caller
* External callers usually need not concern themselves with this, since
* all stringinfo.c routines do it automatically. However, if a caller
* knows that a StringInfo will eventually become X bytes large, it
* can save some palloc overhead by enlarging the buffer before starting
* to store data in it.

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.202 2003/04/08 23:20:01 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.203 2003/04/24 21:16:43 tgl Exp $
*
* NOTES
* Every node type that can appear in stored rules' parsetrees *must*
@@ -39,7 +39,7 @@
/* Write the label for the node type */
#define WRITE_NODE_TYPE(nodelabel) \
appendStringInfo(str, nodelabel)
appendStringInfoString(str, nodelabel)
/* Write an integer field (anything written as ":fldname %d") */
#define WRITE_INT_FIELD(fldname) \

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.145 2003/04/08 23:20:02 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.146 2003/04/24 21:16:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1288,8 +1288,8 @@ func_error(const char *caller, List *funcname,
for (i = 0; i < nargs; i++)
{
if (i)
appendStringInfo(&argbuf, ", ");
appendStringInfo(&argbuf, format_type_be(argtypes[i]));
appendStringInfoString(&argbuf, ", ");
appendStringInfoString(&argbuf, format_type_be(argtypes[i]));
}
if (caller == NULL)

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.54 2003/03/10 03:53:51 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/parse_type.c,v 1.55 2003/04/24 21:16:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -153,13 +153,13 @@ TypeNameToString(const TypeName *typename)
{
if (l != typename->names)
appendStringInfoChar(&string, '.');
appendStringInfo(&string, "%s", strVal(lfirst(l)));
appendStringInfoString(&string, strVal(lfirst(l)));
}
}
else
{
/* Look up internally-specified type */
appendStringInfo(&string, "%s", format_type_be(typename->typeid));
appendStringInfoString(&string, format_type_be(typename->typeid));
}
/*
@@ -167,10 +167,10 @@ TypeNameToString(const TypeName *typename)
* LookupTypeName
*/
if (typename->pct_type)
appendStringInfo(&string, "%%TYPE");
appendStringInfoString(&string, "%TYPE");
if (typename->arrayBounds != NIL)
appendStringInfo(&string, "[]");
appendStringInfoString(&string, "[]");
return string.data;
}

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.103 2002/11/11 03:33:38 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/parser/scan.l,v 1.104 2003/04/24 21:16:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -33,7 +33,7 @@
#define YY_READ_BUF_SIZE 16777216
/* Avoid exit() on fatal scanner errors (a bit ugly -- see yy_fatal_error) */
#define fprintf(file, fmt, msg) elog(FATAL, "%s", (msg))
#define fprintf(file, fmt, msg) ereport(FATAL, (errmsg_internal("%s", msg)))
extern YYSTYPE yylval;
@@ -575,12 +575,19 @@ void
yyerror(const char *message)
{
const char *loc = token_start ? token_start : yytext;
int cursorpos;
/* in multibyte encodings, return index in characters not bytes */
cursorpos = pg_mbstrlen_with_len(scanbuf, loc - scanbuf) + 1;
if (*loc == YY_END_OF_BUFFER_CHAR)
elog(ERROR, "parser: %s at end of input", message);
ereport(ERROR,
(errmsg("parser: %s at end of input", message),
errposition(cursorpos)));
else
elog(ERROR, "parser: %s at or near \"%s\" at character %d",
message, loc, (int) (loc - scanbuf + 1));
ereport(ERROR,
(errmsg("parser: %s at or near \"%s\"", message, loc),
errposition(cursorpos)));
}
@@ -591,7 +598,7 @@ void
scanner_init(StringInfo str)
{
/*
* Might be left over after elog()
* Might be left over after ereport()
*/
if (YY_CURRENT_BUFFER)
yy_delete_buffer(YY_CURRENT_BUFFER);

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.323 2003/04/22 00:08:07 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.324 2003/04/24 21:16:43 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@@ -349,7 +349,7 @@ pg_parse_and_rewrite(char *query_string, /* string to execute */
StringInfoData stri;
initStringInfo(&stri);
appendStringInfo(&stri, "%s", query_string);
appendStringInfoString(&stri, query_string);
/*
* (1) parse the request string into a list of raw parse trees.
@@ -1831,7 +1831,7 @@ PostgresMain(int argc, char *argv[], const char *username)
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.323 $ $Date: 2003/04/22 00:08:07 $\n");
puts("$Revision: 1.324 $ $Date: 2003/04/24 21:16:43 $\n");
}
/*

View File

@@ -3,7 +3,7 @@
* back to source text
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.138 2003/04/08 23:20:02 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/ruleutils.c,v 1.139 2003/04/24 21:16:43 tgl Exp $
*
* This software is copyrighted by Jan Wieck - Hamburg.
*
@@ -921,7 +921,7 @@ pg_get_constraintdef(PG_FUNCTION_ARGS)
constraintId);
/* Append the constraint source */
appendStringInfo(&buf, DatumGetCString(DirectFunctionCall1(textout, val)));
appendStringInfoString(&buf, DatumGetCString(DirectFunctionCall1(textout, val)));
break;
}
@@ -2846,7 +2846,7 @@ get_const_expr(Const *constval, deparse_context *context)
*/
if (strspn(extval, "0123456789+-eE.") == strlen(extval))
{
appendStringInfo(buf, extval);
appendStringInfoString(buf, extval);
if (strcspn(extval, "eE.") != strlen(extval))
isfloat = true; /* it looks like a float */
}

View File

@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.95 2003/03/10 22:28:18 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.96 2003/04/24 21:16:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -1696,8 +1696,8 @@ replace_text(PG_FUNCTION_ARGS)
left_text = LEFT(buf_text, from_sub_text);
right_text = RIGHT(buf_text, from_sub_text, from_sub_text_len);
appendStringInfo(str, PG_TEXT_GET_STR(left_text));
appendStringInfo(str, to_sub_str);
appendStringInfoString(str, PG_TEXT_GET_STR(left_text));
appendStringInfoString(str, to_sub_str);
pfree(buf_text);
pfree(left_text);
@@ -1705,7 +1705,7 @@ replace_text(PG_FUNCTION_ARGS)
curr_posn = TEXTPOS(buf_text, from_sub_text);
}
appendStringInfo(str, PG_TEXT_GET_STR(buf_text));
appendStringInfoString(str, PG_TEXT_GET_STR(buf_text));
pfree(buf_text);
ret_text = PG_STR_GET_TEXT(str->data);

File diff suppressed because it is too large Load Diff