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.

68 satır
5.6KB

  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.10. Processing Embedded SQL Programs</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-preproc.html" title="35.9. Preprocessor Directives" /><link rel="next" href="ecpg-library.html" title="35.11. Library Functions" /></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.10. Processing Embedded SQL Programs</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="ecpg-preproc.html" title="35.9. Preprocessor Directives">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="ecpg-library.html" title="35.11. Library Functions">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="ECPG-PROCESS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">35.10. Processing Embedded SQL Programs</h2></div></div></div><p>
  3. Now that you have an idea how to form embedded SQL C programs, you
  4. probably want to know how to compile them. Before compiling you
  5. run the file through the embedded <acronym class="acronym">SQL</acronym>
  6. <acronym class="acronym">C</acronym> preprocessor, which converts the
  7. <acronym class="acronym">SQL</acronym> statements you used to special function
  8. calls. After compiling, you must link with a special library that
  9. contains the needed functions. These functions fetch information
  10. from the arguments, perform the <acronym class="acronym">SQL</acronym> command using
  11. the <span class="application">libpq</span> interface, and put the result
  12. in the arguments specified for output.
  13. </p><p>
  14. The preprocessor program is called <code class="filename">ecpg</code> and is
  15. included in a normal <span class="productname">PostgreSQL</span> installation.
  16. Embedded SQL programs are typically named with an extension
  17. <code class="filename">.pgc</code>. If you have a program file called
  18. <code class="filename">prog1.pgc</code>, you can preprocess it by simply
  19. calling:
  20. </p><pre class="programlisting">
  21. ecpg prog1.pgc
  22. </pre><p>
  23. This will create a file called <code class="filename">prog1.c</code>. If
  24. your input files do not follow the suggested naming pattern, you
  25. can specify the output file explicitly using the
  26. <code class="option">-o</code> option.
  27. </p><p>
  28. The preprocessed file can be compiled normally, for example:
  29. </p><pre class="programlisting">
  30. cc -c prog1.c
  31. </pre><p>
  32. The generated C source files include header files from the
  33. <span class="productname">PostgreSQL</span> installation, so if you installed
  34. <span class="productname">PostgreSQL</span> in a location that is not searched by
  35. default, you have to add an option such as
  36. <code class="literal">-I/usr/local/pgsql/include</code> to the compilation
  37. command line.
  38. </p><p>
  39. To link an embedded SQL program, you need to include the
  40. <code class="filename">libecpg</code> library, like so:
  41. </p><pre class="programlisting">
  42. cc -o myprog prog1.o prog2.o ... -lecpg
  43. </pre><p>
  44. Again, you might have to add an option like
  45. <code class="literal">-L/usr/local/pgsql/lib</code> to that command line.
  46. </p><p>
  47. You can
  48. use <code class="command">pg_config</code><a id="id-1.7.5.16.6.2" class="indexterm"></a>
  49. or <code class="command">pkg-config</code><a id="id-1.7.5.16.6.4" class="indexterm"></a> with package name <code class="literal">libecpg</code> to
  50. get the paths for your installation.
  51. </p><p>
  52. If you manage the build process of a larger project using
  53. <span class="application">make</span>, it might be convenient to include
  54. the following implicit rule to your makefiles:
  55. </p><pre class="programlisting">
  56. ECPG = ecpg
  57. %.c: %.pgc
  58. $(ECPG) $&lt;
  59. </pre><p>
  60. </p><p>
  61. The complete syntax of the <code class="command">ecpg</code> command is
  62. detailed in <a class="xref" href="app-ecpg.html" title="ecpg"><span class="refentrytitle"><span class="application">ecpg</span></span></a>.
  63. </p><p>
  64. The <span class="application">ecpg</span> library is thread-safe by
  65. default. However, you might need to use some threading
  66. command-line options to compile your client code.
  67. </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ecpg-preproc.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="ecpg-library.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">35.9. Preprocessor Directives </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> 35.11. Library Functions</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1