pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
10+ messages / 5 participants
[nested] [flat]

* SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
@ 2018-10-31 07:53  Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Takahashi, Ryohei @ 2018-10-31 07:53 UTC (permalink / raw)
  To: pgsql-odbc

Hi,


I have a problem in psqlODBC.

SQLExecDirectW() returns SQL_SUCCESS even if sql finishes with error when client_min_messages = fatal.
It works correctly when client_min_messages = error.

I think the cause is following.


connection.c
CC_send_query_append()

...
	while (self->pqconn && (pgres = PQgetResult(self->pqconn)) != NULL) // (1)
	{
		int status = PQresultStatus(pgres); // (2)

		if (discardTheRest)
			continue;
		switch (status) 
		{
			...
			case PGRES_BAD_RESPONSE:
			case PGRES_FATAL_ERROR:
				handle_pgres_error(self, pgres, "send_query", res, TRUE); // (3)
		...



When client_min_messages = error and sql finishes with error,
PostgreSQL server sends 'E' message to the client.
(https://www.postgresql.org/docs/11/static/protocol-message-formats.html)

In this case, PQgetResult() returns non-NULL in (1) and PQresultStatus() returns PGRES_FATAL_ERROR in (2).
Then, handle_pgres_error() is called in (3) and finally SQLExecDirectW() returns SQL_ERROR.


However, when client_min_messages = fatal and sql finishes with error,
PostgreSQL server sends only 'Z' message to the client.

In this case, PQgetResult() returns NULL in (1) and handle_pgres_error() is never called in (3).
Then, SQLExecDirectW() returns SQL_SUCCESS.


Is this right?



Regards,
Ryohei Takahashi






^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
@ 2018-10-31 08:54  Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
  parent: Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
  0 siblings, 1 reply; 10+ messages in thread

From: Inoue, Hiroshi @ 2018-10-31 08:54 UTC (permalink / raw)
  To: Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>; +Cc: pgsql-odbc

Hi Takahashi-san,

Thanks for the report.

On 2018/10/31 16:53, Takahashi, Ryohei wrote:
> Hi,
>
>
> I have a problem in psqlODBC.
>
> SQLExecDirectW() returns SQL_SUCCESS even if sql finishes with error when client_min_messages = fatal.
> It works correctly when client_min_messages = error.

Why do you set client_min_messages to fatal in the first place?

regards,
Hiroshi Inoue

>
> I think the cause is following.
>
>
> connection.c
> CC_send_query_append()
>
> ...
> 	while (self->pqconn && (pgres = PQgetResult(self->pqconn)) != NULL) // (1)
> 	{
> 		int status = PQresultStatus(pgres); // (2)
>
> 		if (discardTheRest)
> 			continue;
> 		switch (status)
> 		{
> 			...
> 			case PGRES_BAD_RESPONSE:
> 			case PGRES_FATAL_ERROR:
> 				handle_pgres_error(self, pgres, "send_query", res, TRUE); // (3)
> 		...
>
>
>
> When client_min_messages = error and sql finishes with error,
> PostgreSQL server sends 'E' message to the client.
> (https://www.postgresql.org/docs/11/static/protocol-message-formats.html)
>
> In this case, PQgetResult() returns non-NULL in (1) and PQresultStatus() returns PGRES_FATAL_ERROR in (2).
> Then, handle_pgres_error() is called in (3) and finally SQLExecDirectW() returns SQL_ERROR.
>
>
> However, when client_min_messages = fatal and sql finishes with error,
> PostgreSQL server sends only 'Z' message to the client.
>
> In this case, PQgetResult() returns NULL in (1) and handle_pgres_error() is never called in (3).
> Then, SQLExecDirectW() returns SQL_SUCCESS.
>
>
> Is this right?
>
>
>
> Regards,
> Ryohei Takahashi




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* RE: SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
@ 2018-11-01 06:57  Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
  parent: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
  0 siblings, 2 replies; 10+ messages in thread

From: Takahashi, Ryohei @ 2018-11-01 06:57 UTC (permalink / raw)
  To: 'Inoue, Hiroshi' <h-inoue@dream.email.ne.jp>; +Cc: pgsql-odbc

Hi Inoue-san,


Thank you for replying.


> Why do you set client_min_messages to fatal in the first place?

Actually, my customer used PostgreSQL with default settings at first.
He wanted to reduce server logs later and set log_min_messages = fatal and client_min_messages = fatal.

I know client_min_messages does not reduce server logs and recommended him to change client_min_messages again.


Anyway, I think it is a problem that SQLExecDirectW() returns SQL_SUCCESS even if sql finishes with error.


Regards,
Ryohei Takahashi






^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
@ 2018-11-01 09:01  Clemens Ladisch <clemens@ladisch.de>
  parent: Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Clemens Ladisch @ 2018-11-01 09:01 UTC (permalink / raw)
  To: pgsql-odbc@lists.postgresql.org

Takahashi, Ryohei wrote:
> Anyway, I think it is a problem that SQLExecDirectW() returns SQL_SUCCESS even if sql finishes with error.

When client_min_messages set that high, the server never reports the
error.  So the ODBC driver cannot do much about it; at best, it could
report something like "I do not know the status", but that is not
actually possible in the ODBC API.

> He wanted to reduce server logs later and set ... client_min_messages = fatal.

Setting "client_min_messages = fatal" literally means "I do not want to
know about normal errors."

This is an error in the documentation.
I've submitted a bug report: <https://www.postgresql.org/message-id/flat/15479-ef0f4cc2fd995ca2%40postgresql.org;


Regards,
Clemens




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
@ 2018-11-01 23:59  Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
  parent: Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
  1 sibling, 1 reply; 10+ messages in thread

From: Inoue, Hiroshi @ 2018-11-01 23:59 UTC (permalink / raw)
  To: Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>; +Cc: pgsql-odbc

Hi Takahashi-san,

Could you please tell the customer that it's meaningless to set  
client_min_messages to 'fatal' or 'panic'?

regards,
Hiroshi Inoue

On 2018/11/01 15:57, Takahashi, Ryohei wrote:
> Hi Inoue-san,
>
>
> Thank you for replying.
>
>
>> Why do you set client_min_messages to fatal in the first place?
> Actually, my customer used PostgreSQL with default settings at first.
> He wanted to reduce server logs later and set log_min_messages = fatal and client_min_messages = fatal.
>
> I know client_min_messages does not reduce server logs and recommended him to change client_min_messages again.
>
>
> Anyway, I think it is a problem that SQLExecDirectW() returns SQL_SUCCESS even if sql finishes with error.
>
>
> Regards,
> Ryohei Takahashi




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
@ 2018-11-02 02:50  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
  0 siblings, 1 reply; 10+ messages in thread

From: Tom Lane @ 2018-11-02 02:50 UTC (permalink / raw)
  To: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>; +Cc: Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>; pgsql-odbc

"Inoue, Hiroshi" <h-inoue@dream.email.ne.jp> writes:
> Could you please tell the customer that it's meaningless to set  
> client_min_messages to 'fatal' or 'panic'?

Yeah, I wonder why we allow that at all.  It's basically breaking
the wire protocol ...

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
@ 2018-11-02 16:08  Jonah H. Harris <jonah.harris@gmail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 10+ messages in thread

From: Jonah H. Harris @ 2018-11-02 16:08 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: h-inoue@dream.email.ne.jp; r.takahashi_2@jp.fujitsu.com; pgsql-odbc

On Thu, Nov 1, 2018 at 10:50 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

> "Inoue, Hiroshi" <h-inoue@dream.email.ne.jp> writes:
> > Could you please tell the customer that it's meaningless to set
> > client_min_messages to 'fatal' or 'panic'?
>
> Yeah, I wonder why we allow that at all.  It's basically breaking
> the wire protocol ...
>

Agreed. I'll send in a patch if you want. It appears the fatal and panic
members of client_message_level_options in guc.c could be removed. The same
options are similarly used by trace_recovery_messages, but that seems to
make sense even in that regard. Likewise, postgresql.conf.sample only shows
debug5-error as options; omitting fatal and panic. The web docs, however,
show fatal and panic as options.

Thoughts?

-- 
Jonah H. Harris

^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* RE: SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
@ 2018-11-05 08:05  Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
  parent: Clemens Ladisch <clemens@ladisch.de>
  0 siblings, 0 replies; 10+ messages in thread

From: Takahashi, Ryohei @ 2018-11-05 08:05 UTC (permalink / raw)
  To: Clemens Ladisch <clemens@ladisch.de>; pgsql-odbc@lists.postgresql.org <pgsql-odbc@lists.postgresql.org>

Hi Clemens,

Thank you for replying.

> This is an error in the documentation.
> I've submitted a bug report:

I understand.
Thank you for submitting the bug report.


Regards,
Ryohei Takahashi







^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* RE: SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
@ 2018-11-05 08:46  Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
  parent: Jonah H. Harris <jonah.harris@gmail.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Takahashi, Ryohei @ 2018-11-05 08:46 UTC (permalink / raw)
  To: 'Jonah H. Harris' <jonah.harris@gmail.com>; Tom Lane <tgl@sss.pgh.pa.us>; +Cc: h-inoue@dream.email.ne.jp <h-inoue@dream.email.ne.jp>; pgsql-odbc

Hi Inoue-san, Tom and Jonah,

Thank you for replying.

I understand the problem is that PostgreSQL allows users to set client_min_messages = fatal or panic.
I told my customer this problem and that it's meaningless to set client_min_messages to 'fatal' to reduce server logs.


Regards,
Ryohei Takahashi



^ permalink  raw  reply  [nested|flat] 10+ messages in thread

* Re: SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error
@ 2018-11-06 16:29  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Jonah H. Harris <jonah.harris@gmail.com>
  1 sibling, 0 replies; 10+ messages in thread

From: Tom Lane @ 2018-11-06 16:29 UTC (permalink / raw)
  To: Jonah H. Harris <jonah.harris@gmail.com>; +Cc: h-inoue@dream.email.ne.jp; r.takahashi_2@jp.fujitsu.com; pgsql-odbc

"Jonah H. Harris" <jonah.harris@gmail.com> writes:
> On Thu, Nov 1, 2018 at 10:50 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Yeah, I wonder why we allow that at all.  It's basically breaking
>> the wire protocol ...

> Agreed. I'll send in a patch if you want.

I started a thread about this on -hackers,

https://www.postgresql.org/message-id/7809.1541521180@sss.pgh.pa.us

If you have or want to start on a patch, please do so and follow up
there.

			regards, tom lane




^ permalink  raw  reply  [nested|flat] 10+ messages in thread


end of thread, other threads:[~2018-11-06 16:29 UTC | newest]

Thread overview: 10+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-10-31 07:53 SQLExecDirectW returns SQL_SUCCESS even if sql finishes with error Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
2018-10-31 08:54 ` Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
2018-11-01 06:57   ` Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
2018-11-01 09:01     ` Clemens Ladisch <clemens@ladisch.de>
2018-11-05 08:05       ` Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
2018-11-01 23:59     ` Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
2018-11-02 02:50       ` Tom Lane <tgl@sss.pgh.pa.us>
2018-11-02 16:08         ` Jonah H. Harris <jonah.harris@gmail.com>
2018-11-05 08:46           ` Takahashi, Ryohei <r.takahashi_2@jp.fujitsu.com>
2018-11-06 16:29           ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox