postgres_fdw: Fix bug in checking of return value of PQsendQuery().
authorFujii Masao <fujii@postgresql.org>
Thu, 21 Jul 2022 13:52:50 +0000 (22:52 +0900)
committerFujii Masao <fujii@postgresql.org>
Fri, 22 Jul 2022 03:01:38 +0000 (12:01 +0900)
commit169d50ba34a91a1c3e2535b8ef49480bad4b9867
treed54b88f1c3381009b67df8ae3ac55d062f4ae45a
parente613466e46c86d6c64bac062b35ef5d0ca539d19
postgres_fdw: Fix bug in checking of return value of PQsendQuery().

When postgres_fdw begins an asynchronous data fetch, it submits FETCH query
by using PQsendQuery(). If PQsendQuery() fails and returns 0, postgres_fdw
should report an error. But, previously, postgres_fdw reported an error
only when the return value is less than 0, though PQsendQuery() never return
the values other than 0 and 1. Therefore postgres_fdw could not handle
the failure to send FETCH query in an asynchronous data fetch.

This commit fixes postgres_fdw so that it reports an error
when PQsendQuery() returns 0.

Back-patch to v14 where asynchronous execution was supported in postgres_fdw.

Author: Fujii Masao
Reviewed-by: Japin Li, Tom Lane
Discussion: http://postgr.es/m/b187a7cf-d4e3-5a32-4d01-8383677797f3@oss.nttdata.com
contrib/postgres_fdw/postgres_fdw.c