]> begriffs open source - ai-pg/blob - full-docs/src/sgml/html/ecpg-concept.html
WIP: toc builder
[ai-pg] / full-docs / src / sgml / html / ecpg-concept.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>34.1. The Concept</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.html" title="Chapter 34. ECPG — Embedded SQL in C" /><link rel="next" href="ecpg-connect.html" title="34.2. Managing Database Connections" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">34.1. The Concept</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="ecpg.html" title="Chapter 34. ECPG — Embedded SQL in C">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="ecpg.html" title="Chapter 34. ECPG — Embedded SQL in C">Up</a></td><th width="60%" align="center">Chapter 34. <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 18.0 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="ecpg-connect.html" title="34.2. Managing Database Connections">Next</a></td></tr></table><hr /></div><div class="sect1" id="ECPG-CONCEPT"><div class="titlepage"><div><div><h2 class="title" style="clear: both">34.1. The Concept <a href="#ECPG-CONCEPT" class="id_link">#</a></h2></div></div></div><p>
3    An embedded SQL program consists of code written in an ordinary
4    programming language, in this case C, mixed with SQL commands in
5    specially marked sections.  To build the program, the source code (<code class="filename">*.pgc</code>)
6    is first passed through the embedded SQL preprocessor, which converts it
7    to an ordinary C program (<code class="filename">*.c</code>), and afterwards it can be processed by a C
8    compiler.  (For details about the compiling and linking see <a class="xref" href="ecpg-process.html" title="34.10. Processing Embedded SQL Programs">Section 34.10</a>.)
9    Converted ECPG applications call functions in the libpq library
10    through the embedded SQL library (ecpglib), and communicate with
11    the PostgreSQL server using the normal frontend-backend protocol.
12   </p><p>
13    Embedded <acronym class="acronym">SQL</acronym> has advantages over other methods
14    for handling <acronym class="acronym">SQL</acronym> commands from C code. First, it
15    takes care of the tedious passing of information to and from
16    variables in your <acronym class="acronym">C</acronym> program.  Second, the SQL
17    code in the program is checked at build time for syntactical
18    correctness.  Third, embedded <acronym class="acronym">SQL</acronym> in C is
19    specified in the <acronym class="acronym">SQL</acronym> standard and supported by
20    many other <acronym class="acronym">SQL</acronym> database systems.  The
21    <span class="productname">PostgreSQL</span> implementation is designed to match this
22    standard as much as possible, and it is usually possible to port
23    embedded <acronym class="acronym">SQL</acronym> programs written for other SQL
24    databases to <span class="productname">PostgreSQL</span> with relative
25    ease.
26   </p><p>
27    As already stated, programs written for the embedded
28    <acronym class="acronym">SQL</acronym> interface are normal C programs with special
29    code inserted to perform database-related actions.  This special
30    code always has the form:
31 </p><pre class="programlisting">
32 EXEC SQL ...;
33 </pre><p>
34    These statements syntactically take the place of a C statement.
35    Depending on the particular statement, they can appear at the
36    global level or within a function.
37   </p><p>
38    Embedded
39    <acronym class="acronym">SQL</acronym> statements follow the case-sensitivity rules of
40    normal <acronym class="acronym">SQL</acronym> code, and not those of C. Also they allow nested
41    C-style comments as per the SQL standard. The C part of the
42    program, however, follows the C standard of not accepting nested comments.
43    Embedded <acronym class="acronym">SQL</acronym> statements likewise use SQL rules, not
44    C rules, for parsing quoted strings and identifiers.
45    (See <a class="xref" href="sql-syntax-lexical.html#SQL-SYNTAX-STRINGS" title="4.1.2.1. String Constants">Section 4.1.2.1</a> and
46    <a class="xref" href="sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS" title="4.1.1. Identifiers and Key Words">Section 4.1.1</a> respectively.  Note that
47    ECPG assumes that <code class="varname">standard_conforming_strings</code>
48    is <code class="literal">on</code>.)
49    Of course, the C part of the program follows C quoting rules.
50   </p><p>
51    The following sections explain all the embedded SQL statements.
52   </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ecpg.html" title="Chapter 34. ECPG — Embedded SQL in C">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="ecpg.html" title="Chapter 34. ECPG — Embedded SQL in C">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="ecpg-connect.html" title="34.2. Managing Database Connections">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 34. <span class="application">ECPG</span> — Embedded <acronym class="acronym">SQL</acronym> in C </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 18.0 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 34.2. Managing Database Connections</td></tr></table></div></body></html>