gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

86 行
6.3KB

  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.12. Notice Processing</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-misc.html" title="33.11. Miscellaneous Functions" /><link rel="next" href="libpq-events.html" title="33.13. Event System" /></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.12. Notice Processing</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="libpq-misc.html" title="33.11. Miscellaneous Functions">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-events.html" title="33.13. Event System">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="LIBPQ-NOTICE-PROCESSING"><div class="titlepage"><div><div><h2 class="title" style="clear: both">33.12. Notice Processing</h2></div></div></div><a id="id-1.7.3.19.2" class="indexterm"></a><p>
  3. Notice and warning messages generated by the server are not returned
  4. by the query execution functions, since they do not imply failure of
  5. the query. Instead they are passed to a notice handling function, and
  6. execution continues normally after the handler returns. The default
  7. notice handling function prints the message on
  8. <code class="filename">stderr</code>, but the application can override this
  9. behavior by supplying its own handling function.
  10. </p><p>
  11. For historical reasons, there are two levels of notice handling, called
  12. the notice receiver and notice processor. The default behavior is for
  13. the notice receiver to format the notice and pass a string to the notice
  14. processor for printing. However, an application that chooses to provide
  15. its own notice receiver will typically ignore the notice processor
  16. layer and just do all the work in the notice receiver.
  17. </p><p>
  18. The function <code class="function">PQsetNoticeReceiver</code>
  19. <a id="id-1.7.3.19.5.2" class="indexterm"></a>
  20. <a id="id-1.7.3.19.5.3" class="indexterm"></a> sets or
  21. examines the current notice receiver for a connection object.
  22. Similarly, <code class="function">PQsetNoticeProcessor</code>
  23. <a id="id-1.7.3.19.5.5" class="indexterm"></a>
  24. <a id="id-1.7.3.19.5.6" class="indexterm"></a> sets or
  25. examines the current notice processor.
  26. </p><pre class="synopsis">
  27. typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
  28. PQnoticeReceiver
  29. PQsetNoticeReceiver(PGconn *conn,
  30. PQnoticeReceiver proc,
  31. void *arg);
  32. typedef void (*PQnoticeProcessor) (void *arg, const char *message);
  33. PQnoticeProcessor
  34. PQsetNoticeProcessor(PGconn *conn,
  35. PQnoticeProcessor proc,
  36. void *arg);
  37. </pre><p>
  38. Each of these functions returns the previous notice receiver or
  39. processor function pointer, and sets the new value. If you supply a
  40. null function pointer, no action is taken, but the current pointer is
  41. returned.
  42. </p><p>
  43. When a notice or warning message is received from the server, or
  44. generated internally by <span class="application">libpq</span>, the notice
  45. receiver function is called. It is passed the message in the form of
  46. a <code class="symbol">PGRES_NONFATAL_ERROR</code>
  47. <code class="structname">PGresult</code>. (This allows the receiver to extract
  48. individual fields using <code class="function">PQresultErrorField</code>, or obtain a
  49. complete preformatted message using <code class="function">PQresultErrorMessage</code>
  50. or <code class="function">PQresultVerboseErrorMessage</code>.) The same
  51. void pointer passed to <code class="function">PQsetNoticeReceiver</code> is also
  52. passed. (This pointer can be used to access application-specific state
  53. if needed.)
  54. </p><p>
  55. The default notice receiver simply extracts the message (using
  56. <code class="function">PQresultErrorMessage</code>) and passes it to the notice
  57. processor.
  58. </p><p>
  59. The notice processor is responsible for handling a notice or warning
  60. message given in text form. It is passed the string text of the message
  61. (including a trailing newline), plus a void pointer that is the same
  62. one passed to <code class="function">PQsetNoticeProcessor</code>. (This pointer
  63. can be used to access application-specific state if needed.)
  64. </p><p>
  65. The default notice processor is simply:
  66. </p><pre class="programlisting">
  67. static void
  68. defaultNoticeProcessor(void *arg, const char *message)
  69. {
  70. fprintf(stderr, "%s", message);
  71. }
  72. </pre><p>
  73. </p><p>
  74. Once you have set a notice receiver or processor, you should expect
  75. that that function could be called as long as either the
  76. <code class="structname">PGconn</code> object or <code class="structname">PGresult</code> objects made
  77. from it exist. At creation of a <code class="structname">PGresult</code>, the
  78. <code class="structname">PGconn</code>'s current notice handling pointers are copied
  79. into the <code class="structname">PGresult</code> for possible use by functions like
  80. <code class="function">PQgetvalue</code>.
  81. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="libpq-misc.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-events.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">33.11. Miscellaneous Functions </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 33.13. Event System</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1