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.

124 lines
8.1KB

  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>35.16. Internals</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="ecpg-informix-compat.html" title="35.15. Informix Compatibility Mode" /><link rel="next" href="information-schema.html" title="Chapter 36. The Information Schema" /></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">35.16. Internals</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="ecpg-informix-compat.html" title="35.15. Informix Compatibility Mode">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="ecpg.html" title="Chapter 35. ECPG - Embedded SQL in C">Up</a></td><th width="60%" align="center">Chapter 35. <span xmlns="http://www.w3.org/1999/xhtml" class="application">ECPG</span> - Embedded <acronym xmlns="http://www.w3.org/1999/xhtml" class="acronym">SQL</acronym> in C</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="information-schema.html" title="Chapter 36. The Information Schema">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="ECPG-DEVELOP"><div class="titlepage"><div><div><h2 class="title" style="clear: both">35.16. Internals</h2></div></div></div><p>
  3. This section explains how <span class="application">ECPG</span> works
  4. internally. This information can occasionally be useful to help
  5. users understand how to use <span class="application">ECPG</span>.
  6. </p><p>
  7. The first four lines written by <code class="command">ecpg</code> to the
  8. output are fixed lines. Two are comments and two are include
  9. lines necessary to interface to the library. Then the
  10. preprocessor reads through the file and writes output. Normally
  11. it just echoes everything to the output.
  12. </p><p>
  13. When it sees an <code class="command">EXEC SQL</code> statement, it
  14. intervenes and changes it. The command starts with <code class="command">EXEC
  15. SQL</code> and ends with <code class="command">;</code>. Everything in
  16. between is treated as an <acronym class="acronym">SQL</acronym> statement and
  17. parsed for variable substitution.
  18. </p><p>
  19. Variable substitution occurs when a symbol starts with a colon
  20. (<code class="literal">:</code>). The variable with that name is looked up
  21. among the variables that were previously declared within a
  22. <code class="literal">EXEC SQL DECLARE</code> section.
  23. </p><p>
  24. The most important function in the library is
  25. <code class="function">ECPGdo</code>, which takes care of executing most
  26. commands. It takes a variable number of arguments. This can easily
  27. add up to 50 or so arguments, and we hope this will not be a
  28. problem on any platform.
  29. </p><p>
  30. The arguments are:
  31. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term">A line number</span></dt><dd><p>
  32. This is the line number of the original line; used in error
  33. messages only.
  34. </p></dd><dt><span class="term">A string</span></dt><dd><p>
  35. This is the <acronym class="acronym">SQL</acronym> command that is to be issued.
  36. It is modified by the input variables, i.e., the variables that
  37. where not known at compile time but are to be entered in the
  38. command. Where the variables should go the string contains
  39. <code class="literal">?</code>.
  40. </p></dd><dt><span class="term">Input variables</span></dt><dd><p>
  41. Every input variable causes ten arguments to be created. (See below.)
  42. </p></dd><dt><span class="term"><em class="parameter"><code>ECPGt_EOIT</code></em></span></dt><dd><p>
  43. An <code class="type">enum</code> telling that there are no more input
  44. variables.
  45. </p></dd><dt><span class="term">Output variables</span></dt><dd><p>
  46. Every output variable causes ten arguments to be created.
  47. (See below.) These variables are filled by the function.
  48. </p></dd><dt><span class="term"><em class="parameter"><code>ECPGt_EORT</code></em></span></dt><dd><p>
  49. An <code class="type">enum</code> telling that there are no more variables.
  50. </p></dd></dl></div><p>
  51. </p><p>
  52. For every variable that is part of the <acronym class="acronym">SQL</acronym>
  53. command, the function gets ten arguments:
  54. </p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p>
  55. The type as a special symbol.
  56. </p></li><li class="listitem"><p>
  57. A pointer to the value or a pointer to the pointer.
  58. </p></li><li class="listitem"><p>
  59. The size of the variable if it is a <code class="type">char</code> or <code class="type">varchar</code>.
  60. </p></li><li class="listitem"><p>
  61. The number of elements in the array (for array fetches).
  62. </p></li><li class="listitem"><p>
  63. The offset to the next element in the array (for array fetches).
  64. </p></li><li class="listitem"><p>
  65. The type of the indicator variable as a special symbol.
  66. </p></li><li class="listitem"><p>
  67. A pointer to the indicator variable.
  68. </p></li><li class="listitem"><p>
  69. 0
  70. </p></li><li class="listitem"><p>
  71. The number of elements in the indicator array (for array fetches).
  72. </p></li><li class="listitem"><p>
  73. The offset to the next element in the indicator array (for
  74. array fetches).
  75. </p></li></ol></div><p>
  76. </p><p>
  77. Note that not all SQL commands are treated in this way. For
  78. instance, an open cursor statement like:
  79. </p><pre class="programlisting">
  80. EXEC SQL OPEN <em class="replaceable"><code>cursor</code></em>;
  81. </pre><p>
  82. is not copied to the output. Instead, the cursor's
  83. <code class="command">DECLARE</code> command is used at the position of the <code class="command">OPEN</code> command
  84. because it indeed opens the cursor.
  85. </p><p>
  86. Here is a complete example describing the output of the
  87. preprocessor of a file <code class="filename">foo.pgc</code> (details might
  88. change with each particular version of the preprocessor):
  89. </p><pre class="programlisting">
  90. EXEC SQL BEGIN DECLARE SECTION;
  91. int index;
  92. int result;
  93. EXEC SQL END DECLARE SECTION;
  94. ...
  95. EXEC SQL SELECT res INTO :result FROM mytable WHERE index = :index;
  96. </pre><p>
  97. is translated into:
  98. </p><pre class="programlisting">
  99. /* Processed by ecpg (2.6.0) */
  100. /* These two include files are added by the preprocessor */
  101. #include &lt;ecpgtype.h&gt;;
  102. #include &lt;ecpglib.h&gt;;
  103. /* exec sql begin declare section */
  104. #line 1 "foo.pgc"
  105. int index;
  106. int result;
  107. /* exec sql end declare section */
  108. ...
  109. ECPGdo(__LINE__, NULL, "SELECT res FROM mytable WHERE index = ? ",
  110. ECPGt_int,&amp;(index),1L,1L,sizeof(int),
  111. ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
  112. ECPGt_int,&amp;(result),1L,1L,sizeof(int),
  113. ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
  114. #line 147 "foo.pgc"
  115. </pre><p>
  116. (The indentation here is added for readability and not
  117. something the preprocessor does.)
  118. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ecpg-informix-compat.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ecpg.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="information-schema.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">35.15. <span class="productname">Informix</span> Compatibility Mode </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 36. The Information Schema</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1