Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
ecpg-process.html68 linesDownload Raw Back to html
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>36.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 Vsnapshot" /><link rel="prev" href="ecpg-preproc.html" title="36.9. Preprocessor Directives" /><link rel="next" href="ecpg-library.html" title="36.11. Library Functions" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">36.10. Processing Embedded SQL Programs</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="ecpg-preproc.html" title="36.9. Preprocessor Directives">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="ecpg.html" title="Chapter 36. ECPG — Embedded SQL in C">Up</a></td><th width="60%" align="center">Chapter 36. <span class="application">ECPG</span> — Embedded <acronym class="acronym">SQL</acronym> in C</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="ecpg-library.html" title="36.11. Library Functions">Next</a></td></tr></table><hr /></div><div class="sect1" id="ECPG-PROCESS"><div class="titlepage"><div><div><h2 class="title" style="clear: both">36.10. Processing Embedded SQL Programs <a href="#ECPG-PROCESS" class="id_link">#</a></h2></div></div></div><p>3   Now that you have an idea how to form embedded SQL C programs, you4   probably want to know how to compile them.  Before compiling you5   run the file through the embedded <acronym class="acronym">SQL</acronym>6   <acronym class="acronym">C</acronym> preprocessor, which converts the7   <acronym class="acronym">SQL</acronym> statements you used to special function8   calls.  After compiling, you must link with a special library that9   contains the needed functions. These functions fetch information10   from the arguments, perform the <acronym class="acronym">SQL</acronym> command using11   the <span class="application">libpq</span> interface, and put the result12   in the arguments specified for output.13  </p><p>14   The preprocessor program is called <code class="filename">ecpg</code> and is15   included in a normal <span class="productname">PostgreSQL</span> installation.16   Embedded SQL programs are typically named with an extension17   <code class="filename">.pgc</code>.  If you have a program file called18   <code class="filename">prog1.pgc</code>, you can preprocess it by simply19   calling:20</p><pre class="programlisting">21ecpg prog1.pgc22</pre><p>23   This will create a file called <code class="filename">prog1.c</code>.  If24   your input files do not follow the suggested naming pattern, you25   can specify the output file explicitly using the26   <code class="option">-o</code> option.27  </p><p>28   The preprocessed file can be compiled normally, for example:29</p><pre class="programlisting">30cc -c prog1.c31</pre><p>32   The generated C source files include header files from the33   <span class="productname">PostgreSQL</span> installation, so if you installed34   <span class="productname">PostgreSQL</span> in a location that is not searched by35   default, you have to add an option such as36   <code class="literal">-I/usr/local/pgsql/include</code> to the compilation37   command line.38  </p><p>39   To link an embedded SQL program, you need to include the40   <code class="filename">libecpg</code> library, like so:41</p><pre class="programlisting">42cc -o myprog prog1.o prog2.o ... -lecpg43</pre><p>44   Again, you might have to add an option like45   <code class="literal">-L/usr/local/pgsql/lib</code> to that command line.46  </p><p>47   You can48   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> to50   get the paths for your installation.51  </p><p>52   If you manage the build process of a larger project using53   <span class="application">make</span>, it might be convenient to include54   the following implicit rule to your makefiles:55</p><pre class="programlisting">56ECPG = ecpg57 58%.c: %.pgc59        $(ECPG) $&lt;60</pre><p>61  </p><p>62   The complete syntax of the <code class="command">ecpg</code> command is63   detailed in <a class="xref" href="app-ecpg.html" title="ecpg"><span class="refentrytitle"><span class="application">ecpg</span></span></a>.64  </p><p>65   The <span class="application">ecpg</span> library is thread-safe by66   default.  However, you might need to use some threading67   command-line options to compile your client code.68  </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" title="36.9. Preprocessor Directives">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ecpg.html" title="Chapter 36. ECPG — Embedded SQL in C">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ecpg-library.html" title="36.11. Library Functions">Next</a></td></tr><tr><td width="40%" align="left" valign="top">36.9. Preprocessor Directives </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 16.3 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 36.11. Library Functions</td></tr></table></div></body></html>
codekingpro/portable-devtools · Team Ai