gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
7.0KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>33.6. Canceling Queries in Progress</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="libpq-single-row-mode.html" title="33.5. Retrieving Query Results Row-by-Row" /><link rel="next" href="libpq-fastpath.html" title="33.7. The Fast-Path Interface" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">33.6. Canceling Queries in Progress</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="libpq-single-row-mode.html" title="33.5. Retrieving Query Results Row-by-Row">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="libpq.html" title="Chapter 33. libpq - C Library">Up</a></td><th width="60%" align="center">Chapter 33. <span xmlns="http://www.w3.org/1999/xhtml" class="application">libpq</span> - C Library</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="libpq-fastpath.html" title="33.7. The Fast-Path Interface">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="LIBPQ-CANCEL"><div class="titlepage"><div><div><h2 class="title" style="clear: both">33.6. Canceling Queries in Progress</h2></div></div></div><a id="id-1.7.3.13.2" class="indexterm"></a><p>
  3. A client application can request cancellation of a command that is
  4. still being processed by the server, using the functions described in
  5. this section.
  6. </p><div class="variablelist"><dl class="variablelist"><dt id="LIBPQ-PQGETCANCEL"><span class="term">
  7. <code class="function">PQgetCancel</code>
  8. <a id="id-1.7.3.13.3.1.1.1.2" class="indexterm"></a>
  9. </span></dt><dd><p>
  10. Creates a data structure containing the information needed to cancel
  11. a command issued through a particular database connection.
  12. </p><pre class="synopsis">
  13. PGcancel *PQgetCancel(PGconn *conn);
  14. </pre><p>
  15. </p><p>
  16. <code class="function">PQgetCancel</code> creates a
  17. <code class="structname">PGcancel</code><a id="id-1.7.3.13.3.1.1.2.2.3" class="indexterm"></a> object
  18. given a <code class="structname">PGconn</code> connection object. It will return
  19. <code class="symbol">NULL</code> if the given <em class="parameter"><code>conn</code></em> is <code class="symbol">NULL</code> or an invalid
  20. connection. The <code class="structname">PGcancel</code> object is an opaque
  21. structure that is not meant to be accessed directly by the
  22. application; it can only be passed to <code class="function">PQcancel</code>
  23. or <code class="function">PQfreeCancel</code>.
  24. </p></dd><dt id="LIBPQ-PQFREECANCEL"><span class="term">
  25. <code class="function">PQfreeCancel</code>
  26. <a id="id-1.7.3.13.3.1.2.1.2" class="indexterm"></a>
  27. </span></dt><dd><p>
  28. Frees a data structure created by <code class="function">PQgetCancel</code>.
  29. </p><pre class="synopsis">
  30. void PQfreeCancel(PGcancel *cancel);
  31. </pre><p>
  32. </p><p>
  33. <code class="function">PQfreeCancel</code> frees a data object previously created
  34. by <code class="function">PQgetCancel</code>.
  35. </p></dd><dt id="LIBPQ-PQCANCEL"><span class="term">
  36. <code class="function">PQcancel</code>
  37. <a id="id-1.7.3.13.3.1.3.1.2" class="indexterm"></a>
  38. </span></dt><dd><p>
  39. Requests that the server abandon processing of the current command.
  40. </p><pre class="synopsis">
  41. int PQcancel(PGcancel *cancel, char *errbuf, int errbufsize);
  42. </pre><p>
  43. </p><p>
  44. The return value is 1 if the cancel request was successfully
  45. dispatched and 0 if not. If not, <em class="parameter"><code>errbuf</code></em> is filled
  46. with an explanatory error message. <em class="parameter"><code>errbuf</code></em>
  47. must be a char array of size <em class="parameter"><code>errbufsize</code></em> (the
  48. recommended size is 256 bytes).
  49. </p><p>
  50. Successful dispatch is no guarantee that the request will have
  51. any effect, however. If the cancellation is effective, the current
  52. command will terminate early and return an error result. If the
  53. cancellation fails (say, because the server was already done
  54. processing the command), then there will be no visible result at
  55. all.
  56. </p><p>
  57. <code class="function">PQcancel</code> can safely be invoked from a signal
  58. handler, if the <em class="parameter"><code>errbuf</code></em> is a local variable in the
  59. signal handler. The <code class="structname">PGcancel</code> object is read-only
  60. as far as <code class="function">PQcancel</code> is concerned, so it can
  61. also be invoked from a thread that is separate from the one
  62. manipulating the <code class="structname">PGconn</code> object.
  63. </p></dd></dl></div><p>
  64. </p><div class="variablelist"><dl class="variablelist"><dt id="LIBPQ-PQREQUESTCANCEL"><span class="term">
  65. <code class="function">PQrequestCancel</code>
  66. <a id="id-1.7.3.13.3.2.1.1.2" class="indexterm"></a>
  67. </span></dt><dd><p>
  68. <code class="function">PQrequestCancel</code> is a deprecated variant of
  69. <code class="function">PQcancel</code>.
  70. </p><pre class="synopsis">
  71. int PQrequestCancel(PGconn *conn);
  72. </pre><p>
  73. </p><p>
  74. Requests that the server abandon processing of the current
  75. command. It operates directly on the
  76. <code class="structname">PGconn</code> object, and in case of failure stores the
  77. error message in the <code class="structname">PGconn</code> object (whence it can
  78. be retrieved by <code class="function">PQerrorMessage</code>). Although
  79. the functionality is the same, this approach creates hazards for
  80. multiple-thread programs and signal handlers, since it is possible
  81. that overwriting the <code class="structname">PGconn</code>'s error message will
  82. mess up the operation currently in progress on the connection.
  83. </p></dd></dl></div><p>
  84. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="libpq-single-row-mode.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="libpq.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="libpq-fastpath.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">33.5. Retrieving Query Results Row-by-Row </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 33.7. The Fast-Path Interface</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1