gooderp18绿色标准版
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

45 lines
4.9KB

  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>43.4. Global Data in PL/Tcl</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="pltcl-data.html" title="43.3. Data Values in PL/Tcl" /><link rel="next" href="pltcl-dbaccess.html" title="43.5. Database Access from PL/Tcl" /></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">43.4. Global Data in PL/Tcl</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="pltcl-data.html" title="43.3. Data Values in PL/Tcl">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="pltcl.html" title="Chapter 43. PL/Tcl - Tcl Procedural Language">Up</a></td><th width="60%" align="center">Chapter 43. PL/Tcl - Tcl Procedural Language</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="pltcl-dbaccess.html" title="43.5. Database Access from PL/Tcl">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="PLTCL-GLOBAL"><div class="titlepage"><div><div><h2 class="title" style="clear: both">43.4. Global Data in PL/Tcl</h2></div></div></div><a id="id-1.8.9.8.2" class="indexterm"></a><p>
  3. Sometimes it
  4. is useful to have some global data that is held between two
  5. calls to a function or is shared between different functions.
  6. This is easily done in PL/Tcl, but there are some restrictions that
  7. must be understood.
  8. </p><p>
  9. For security reasons, PL/Tcl executes functions called by any one SQL
  10. role in a separate Tcl interpreter for that role. This prevents
  11. accidental or malicious interference by one user with the behavior of
  12. another user's PL/Tcl functions. Each such interpreter will have its own
  13. values for any <span class="quote">“<span class="quote">global</span>”</span> Tcl variables. Thus, two PL/Tcl
  14. functions will share the same global variables if and only if they are
  15. executed by the same SQL role. In an application wherein a single
  16. session executes code under multiple SQL roles (via <code class="literal">SECURITY
  17. DEFINER</code> functions, use of <code class="command">SET ROLE</code>, etc) you may need to
  18. take explicit steps to ensure that PL/Tcl functions can share data. To
  19. do that, make sure that functions that should communicate are owned by
  20. the same user, and mark them <code class="literal">SECURITY DEFINER</code>. You must of
  21. course take care that such functions can't be used to do anything
  22. unintended.
  23. </p><p>
  24. All PL/TclU functions used in a session execute in the same Tcl
  25. interpreter, which of course is distinct from the interpreter(s)
  26. used for PL/Tcl functions. So global data is automatically shared
  27. between PL/TclU functions. This is not considered a security risk
  28. because all PL/TclU functions execute at the same trust level,
  29. namely that of a database superuser.
  30. </p><p>
  31. To help protect PL/Tcl functions from unintentionally interfering
  32. with each other, a global
  33. array is made available to each function via the <code class="function">upvar</code>
  34. command. The global name of this variable is the function's internal
  35. name, and the local name is <code class="literal">GD</code>. It is recommended that
  36. <code class="literal">GD</code> be used
  37. for persistent private data of a function. Use regular Tcl global
  38. variables only for values that you specifically intend to be shared among
  39. multiple functions. (Note that the <code class="literal">GD</code> arrays are only
  40. global within a particular interpreter, so they do not bypass the
  41. security restrictions mentioned above.)
  42. </p><p>
  43. An example of using <code class="literal">GD</code> appears in the
  44. <code class="function">spi_execp</code> example below.
  45. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="pltcl-data.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="pltcl.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="pltcl-dbaccess.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">43.3. Data Values in PL/Tcl </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 43.5. Database Access from PL/Tcl</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1