pgjdbc/pgjdbc GitHub issues and pull requests (mirror)
help / color / mirror / Atom feedFrom: maimai3478 (@maimai3478) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: Re: [pgjdbc/pgjdbc] issue #1136: Show SQL text (and/or binds) in SQLException message
Date: Wed, 24 Jul 2019 05:06:14 +0000
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
> In this case, are more details not possible to be retrieved from the server?
I saw the PostgreSQL codes and it seems me it only generate the error message like "syntax error at or near...". I couldn't find the logic which add more details to error message by the server settings during seeing codes.
That error is generated in during parsing SQL statement.
https://github.com/postgres/postgres/blob/7d81bdc8c0ce838efa248928065e9b2da829f981/src/backend/parse...
```
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
/* translator: first %s is typically the translation of "syntax error" */
errmsg("%s at or near \"%s\"", _(message), loc),
lexer_errposition()));
```
ereport() is defined like this.
https://github.com/postgres/postgres/blob/fd7d387e0548fd371c06a91d75bc4632541ccfdd/src/include/utils...
```
#ifdef HAVE__BUILTIN_CONSTANT_P
#define ereport_domain(elevel, domain, rest) \
do { \
pg_prevent_errno_in_scope(); \
if (errstart(elevel, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain)) \
errfinish rest; \
if (__builtin_constant_p(elevel) && (elevel) >= ERROR) \
pg_unreachable(); \
} while(0)
#else /* !HAVE__BUILTIN_CONSTANT_P */
#define ereport_domain(elevel, domain, rest) \
do { \
const int elevel_ = (elevel); \
pg_prevent_errno_in_scope(); \
if (errstart(elevel_, __FILE__, __LINE__, PG_FUNCNAME_MACRO, domain)) \
errfinish rest; \
if (elevel_ >= ERROR) \
pg_unreachable(); \
} while(0)
#endif /* HAVE__BUILTIN_CONSTANT_P */
#define ereport(elevel, rest) \
ereport_domain(elevel, TEXTDOMAIN, rest)
```
errstart() creates an error stack entry and store the given parameters in it.
https://github.com/postgres/postgres/blob/fd7d387e0548fd371c06a91d75bc4632541ccfdd/src/backend/utils...
```
bool
errstart(int elevel, const char *filename, int lineno,
const char *funcname, const char *domain)
{
...
/* Initialize data for this error frame */
edata = &errordata[errordata_stack_depth];
MemSet(edata, 0, sizeof(ErrorData));
edata->elevel = elevel;
edata->output_to_server = output_to_server;
edata->output_to_client = output_to_client;
```
The message "syntax error at or near..." is stored in stack entry at errmsg().
https://github.com/postgres/postgres/blob/fd7d387e0548fd371c06a91d75bc4632541ccfdd/src/backend/utils...
```
errmsg(const char *fmt,...)
{
...
edata->message_id = fmt;
```
errfinish() actually process the error report.
https://github.com/postgres/postgres/blob/fd7d387e0548fd371c06a91d75bc4632541ccfdd/src/backend/utils...
https://github.com/postgres/postgres/blob/fd7d387e0548fd371c06a91d75bc4632541ccfdd/src/backend/utils...
Process jump to Postgresmain and finally EmitErrorReport() will send the error message to client.
https://github.com/postgres/postgres/blob/fd7d387e0548fd371c06a91d75bc4632541ccfdd/src/backend/tcop/...
```
PostgresMain(int argc, char *argv[],
const char *dbname,
const char *username)
{
...
EmitErrorReport();
```
(I'm sorry for not knowing how to cite other repositories source code correctly...)
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: github://pgjdbc/pgjdbc
Cc: [email protected], [email protected]
Subject: Re: [pgjdbc/pgjdbc] issue #1136: Show SQL text (and/or binds) in SQLException message
In-Reply-To: <<[email protected]>>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox