diff options
| author | Tom Lane | 2004-03-21 22:29:11 +0000 |
|---|---|---|
| committer | Tom Lane | 2004-03-21 22:29:11 +0000 |
| commit | f938c2b91bebb7f436a3615cf86347d7261f71e8 (patch) | |
| tree | 012d53c3414a88b0d35a4210becbcadf3b81a09c /src/bin | |
| parent | bee3b2a0a01eab4b9e8d795fd2e3b5515bf22df3 (diff) | |
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.
Diffstat (limited to 'src/bin')
| -rw-r--r-- | src/bin/psql/command.c | 12 | ||||
| -rw-r--r-- | src/bin/psql/common.c | 23 | ||||
| -rw-r--r-- | src/bin/psql/settings.h | 6 | ||||
| -rw-r--r-- | src/bin/psql/startup.c | 3 |
4 files changed, 24 insertions, 20 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c index 6b03e35c6f6..97b338efea7 100644 --- a/src/bin/psql/command.c +++ b/src/bin/psql/command.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.113 2004/02/19 19:40:08 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/command.c,v 1.114 2004/03/21 22:29:11 tgl Exp $ */ #include "postgres_fe.h" #include "command.h" @@ -1042,18 +1042,20 @@ SyncVerbosityVariable(void) "default", "terse", "verbose", NULL)) { case 1: /* default */ - PQsetErrorVerbosity(pset.db, PQERRORS_DEFAULT); + pset.verbosity = PQERRORS_DEFAULT; break; case 2: /* terse */ - PQsetErrorVerbosity(pset.db, PQERRORS_TERSE); + pset.verbosity = PQERRORS_TERSE; break; case 3: /* verbose */ - PQsetErrorVerbosity(pset.db, PQERRORS_VERBOSE); + pset.verbosity = PQERRORS_VERBOSE; break; default: /* not set or unrecognized value */ - PQsetErrorVerbosity(pset.db, PQERRORS_DEFAULT); + pset.verbosity = PQERRORS_DEFAULT; break; } + + PQsetErrorVerbosity(pset.db, pset.verbosity); } diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 2a6be545caf..3b1a1228c1e 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -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) { diff --git a/src/bin/psql/settings.h b/src/bin/psql/settings.h index 9c16402ac4c..e28383b16be 100644 --- a/src/bin/psql/settings.h +++ b/src/bin/psql/settings.h @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.16 2003/11/29 19:52:07 pgsql Exp $ + * $PostgreSQL: pgsql/src/bin/psql/settings.h,v 1.17 2004/03/21 22:29:11 tgl Exp $ */ #ifndef SETTINGS_H #define SETTINGS_H @@ -36,8 +36,6 @@ typedef struct _psqlSettings bool notty; /* stdin or stdout is not a tty (as * determined on startup) */ - bool useReadline; /* use libreadline routines */ - bool useHistory; bool getPassword; /* prompt the user for a username and * password */ FILE *cur_cmd_source; /* describe the status of the current main @@ -49,6 +47,8 @@ typedef struct _psqlSettings unsigned lineno; /* also for error reporting */ bool timing; /* enable timing of all queries */ + + PGVerbosity verbosity; /* current error verbosity level */ } PsqlSettings; extern PsqlSettings pset; diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 400f7d45786..03f4e97d918 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2003, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.85 2004/02/19 19:40:09 tgl Exp $ + * $PostgreSQL: pgsql/src/bin/psql/startup.c,v 1.86 2004/03/21 22:29:11 tgl Exp $ */ #include "postgres_fe.h" @@ -143,6 +143,7 @@ main(int argc, char *argv[]) /* Default values for variables that are used in noninteractive cases */ SetVariableBool(pset.vars, "AUTOCOMMIT"); SetVariable(pset.vars, "VERBOSITY", "default"); + pset.verbosity = PQERRORS_DEFAULT; pset.notty = (!isatty(fileno(stdin)) || !isatty(fileno(stdout))); |
