1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-12 02:37:31 +03:00

Revise syntax-error reporting behavior to give pleasant results for

errors in internally-generated queries, such as those submitted by
plpgsql functions.  Per recent discussions with Fabien Coelho.
This commit is contained in:
Tom Lane
2004-03-21 22:29:11 +00:00
parent bee3b2a0a0
commit f938c2b91b
25 changed files with 671 additions and 124 deletions

View File

@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2003, PostgreSQL Global Development Group
*
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.84 2004/03/15 10:41:26 ishii Exp $
* $PostgreSQL: pgsql/src/bin/psql/common.c,v 1.85 2004/03/21 22:29:11 tgl Exp $
*/
#include "postgres_fe.h"
#include "common.h"
@@ -364,18 +364,19 @@ ReportSyntaxErrorPosition(const PGresult *result, const char *query)
bool beg_trunc, end_trunc;
PQExpBufferData msg;
if (query == NULL)
return; /* nothing to do */
if (pset.verbosity == PQERRORS_TERSE)
return;
sp = PQresultErrorField(result, PG_DIAG_STATEMENT_POSITION);
if (sp == NULL)
return; /* no syntax error location */
/*
* We punt if the report contains any CONTEXT. This typically means that
* the syntax error is from inside a function, and the cursor position
* is not relevant to the original query string.
*/
if (PQresultErrorField(result, PG_DIAG_CONTEXT) != NULL)
return;
{
sp = PQresultErrorField(result, PG_DIAG_INTERNAL_POSITION);
if (sp == NULL)
return; /* no syntax error */
query = PQresultErrorField(result, PG_DIAG_INTERNAL_QUERY);
}
if (query == NULL)
return; /* nothing to reference location to */
if (sscanf(sp, "%d", &loc) != 1)
{