diff options
author | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2024-03-18 19:28:58 +0100 |
---|---|---|
committer | Alvaro Herrera <alvherre@alvh.no-ip.org> | 2024-03-18 19:28:58 +0100 |
commit | 66ab9371a23320cf608e68e8e5d2811992941bea (patch) | |
tree | e9b23d614dc8879a6233f60c24aaca94aea74a45 /contrib/dblink/dblink.c | |
parent | 61f352ece9e7eb89c7154da178d0c3bc69fc72c9 (diff) | |
download | postgresql-66ab9371a23320cf608e68e8e5d2811992941bea.tar.gz postgresql-66ab9371a23320cf608e68e8e5d2811992941bea.zip |
dblink/isolationtester/fe_utils: Use new cancel API
Commit 61461a300c1c introduced new functions to libpq for cancelling
queries. This replaces the usage of the old ones in parts of the
codebase with these newer ones. This specifically leaves out changes to
psql and pgbench, as those would need a much larger refactor to be able
to call them due to the new functions not being signal-safe; and also
postgres_fdw, because the original code there is not clear to me
(Álvaro) and not fully tested.
Author: Jelte Fennema-Nio <postgres@jeltef.nl>
Discussion: https://postgr.es/m/CAGECzQT_VgOWWENUqvUV9xQmbaCyXjtRRAYO8W07oqashk_N+g@mail.gmail.com
Diffstat (limited to 'contrib/dblink/dblink.c')
-rw-r--r-- | contrib/dblink/dblink.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index 19a362526d2..edbc9ab02ac 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -1346,22 +1346,28 @@ PG_FUNCTION_INFO_V1(dblink_cancel_query); Datum dblink_cancel_query(PG_FUNCTION_ARGS) { - int res; PGconn *conn; - PGcancel *cancel; - char errbuf[256]; + PGcancelConn *cancelConn; + char *msg; dblink_init(); conn = dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0))); - cancel = PQgetCancel(conn); + cancelConn = PQcancelCreate(conn); - res = PQcancel(cancel, errbuf, 256); - PQfreeCancel(cancel); + PG_TRY(); + { + if (!PQcancelBlocking(cancelConn)) + msg = pchomp(PQcancelErrorMessage(cancelConn)); + else + msg = "OK"; + } + PG_FINALLY(); + { + PQcancelFinish(cancelConn); + } + PG_END_TRY(); - if (res == 1) - PG_RETURN_TEXT_P(cstring_to_text("OK")); - else - PG_RETURN_TEXT_P(cstring_to_text(errbuf)); + PG_RETURN_TEXT_P(cstring_to_text(msg)); } |