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

68 行
6.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>39.3. Writing Event Trigger Functions in C</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="event-trigger-matrix.html" title="39.2. Event Trigger Firing Matrix" /><link rel="next" href="event-trigger-example.html" title="39.4. A Complete Event Trigger Example" /></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">39.3. Writing Event Trigger Functions in C</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="event-trigger-matrix.html" title="39.2. Event Trigger Firing Matrix">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="event-triggers.html" title="Chapter 39. Event Triggers">Up</a></td><th width="60%" align="center">Chapter 39. Event Triggers</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="event-trigger-example.html" title="39.4. A Complete Event Trigger Example">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="EVENT-TRIGGER-INTERFACE"><div class="titlepage"><div><div><h2 class="title" style="clear: both">39.3. Writing Event Trigger Functions in C</h2></div></div></div><a id="id-1.8.5.7.2" class="indexterm"></a><p>
  3. This section describes the low-level details of the interface to an
  4. event trigger function. This information is only needed when writing
  5. event trigger functions in C. If you are using a higher-level language
  6. then these details are handled for you. In most cases you should
  7. consider using a procedural language before writing your event triggers
  8. in C. The documentation of each procedural language explains how to
  9. write an event trigger in that language.
  10. </p><p>
  11. Event trigger functions must use the <span class="quote">“<span class="quote">version 1</span>”</span> function
  12. manager interface.
  13. </p><p>
  14. When a function is called by the event trigger manager, it is not passed
  15. any normal arguments, but it is passed a <span class="quote">“<span class="quote">context</span>”</span> pointer
  16. pointing to a <code class="structname">EventTriggerData</code> structure. C functions can
  17. check whether they were called from the event trigger manager or not by
  18. executing the macro:
  19. </p><pre class="programlisting">
  20. CALLED_AS_EVENT_TRIGGER(fcinfo)
  21. </pre><p>
  22. which expands to:
  23. </p><pre class="programlisting">
  24. ((fcinfo)-&gt;context != NULL &amp;&amp; IsA((fcinfo)-&gt;context, EventTriggerData))
  25. </pre><p>
  26. If this returns true, then it is safe to cast
  27. <code class="literal">fcinfo-&gt;context</code> to type <code class="literal">EventTriggerData
  28. *</code> and make use of the pointed-to
  29. <code class="structname">EventTriggerData</code> structure. The function must
  30. <span class="emphasis"><em>not</em></span> alter the <code class="structname">EventTriggerData</code>
  31. structure or any of the data it points to.
  32. </p><p>
  33. <code class="structname">struct EventTriggerData</code> is defined in
  34. <code class="filename">commands/event_trigger.h</code>:
  35. </p><pre class="programlisting">
  36. typedef struct EventTriggerData
  37. {
  38. NodeTag type;
  39. const char *event; /* event name */
  40. Node *parsetree; /* parse tree */
  41. const char *tag; /* command tag */
  42. } EventTriggerData;
  43. </pre><p>
  44. where the members are defined as follows:
  45. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><code class="structfield">type</code></span></dt><dd><p>
  46. Always <code class="literal">T_EventTriggerData</code>.
  47. </p></dd><dt><span class="term"><code class="structfield">event</code></span></dt><dd><p>
  48. Describes the event for which the function is called, one of
  49. <code class="literal">"ddl_command_start"</code>, <code class="literal">"ddl_command_end"</code>,
  50. <code class="literal">"sql_drop"</code>, <code class="literal">"table_rewrite"</code>.
  51. See <a class="xref" href="event-trigger-definition.html" title="39.1. Overview of Event Trigger Behavior">Section 39.1</a> for the meaning of these
  52. events.
  53. </p></dd><dt><span class="term"><code class="structfield">parsetree</code></span></dt><dd><p>
  54. A pointer to the parse tree of the command. Check the PostgreSQL
  55. source code for details. The parse tree structure is subject to change
  56. without notice.
  57. </p></dd><dt><span class="term"><code class="structfield">tag</code></span></dt><dd><p>
  58. The command tag associated with the event for which the event trigger
  59. is run, for example <code class="literal">"CREATE FUNCTION"</code>.
  60. </p></dd></dl></div><p>
  61. </p><p>
  62. An event trigger function must return a <code class="symbol">NULL</code> pointer
  63. (<span class="emphasis"><em>not</em></span> an SQL null value, that is, do not
  64. set <em class="parameter"><code>isNull</code></em> true).
  65. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="event-trigger-matrix.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="event-triggers.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="event-trigger-example.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">39.2. Event Trigger Firing Matrix </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 39.4. A Complete Event Trigger Example</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1