|
- <?xml version="1.0" encoding="UTF-8" standalone="no"?>
- <!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.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 V1.79.1" /><link rel="prev" href="ecpg.html" title="Chapter 35. ECPG - Embedded SQL in C" /><link rel="next" href="ecpg-connect.html" title="35.2. Managing Database Connections" /></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.1. The Concept</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="ecpg.html" title="Chapter 35. ECPG - Embedded SQL in C">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-connect.html" title="35.2. Managing Database Connections">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="ECPG-CONCEPT"><div class="titlepage"><div><div><h2 class="title" style="clear: both">35.1. The Concept</h2></div></div></div><p>
- An embedded SQL program consists of code written in an ordinary
- programming language, in this case C, mixed with SQL commands in
- specially marked sections. To build the program, the source code (<code class="filename">*.pgc</code>)
- is first passed through the embedded SQL preprocessor, which converts it
- to an ordinary C program (<code class="filename">*.c</code>), and afterwards it can be processed by a C
- compiler. (For details about the compiling and linking see <a class="xref" href="ecpg-process.html" title="35.10. Processing Embedded SQL Programs">Section 35.10</a>).
- Converted ECPG applications call functions in the libpq library
- through the embedded SQL library (ecpglib), and communicate with
- the PostgreSQL server using the normal frontend-backend protocol.
- </p><p>
- Embedded <acronym class="acronym">SQL</acronym> has advantages over other methods
- for handling <acronym class="acronym">SQL</acronym> commands from C code. First, it
- takes care of the tedious passing of information to and from
- variables in your <acronym class="acronym">C</acronym> program. Second, the SQL
- code in the program is checked at build time for syntactical
- correctness. Third, embedded <acronym class="acronym">SQL</acronym> in C is
- specified in the <acronym class="acronym">SQL</acronym> standard and supported by
- many other <acronym class="acronym">SQL</acronym> database systems. The
- <span class="productname">PostgreSQL</span> implementation is designed to match this
- standard as much as possible, and it is usually possible to port
- embedded <acronym class="acronym">SQL</acronym> programs written for other SQL
- databases to <span class="productname">PostgreSQL</span> with relative
- ease.
- </p><p>
- As already stated, programs written for the embedded
- <acronym class="acronym">SQL</acronym> interface are normal C programs with special
- code inserted to perform database-related actions. This special
- code always has the form:
- </p><pre class="programlisting">
- EXEC SQL ...;
- </pre><p>
- These statements syntactically take the place of a C statement.
- Depending on the particular statement, they can appear at the
- global level or within a function. Embedded
- <acronym class="acronym">SQL</acronym> statements follow the case-sensitivity rules of
- normal <acronym class="acronym">SQL</acronym> code, and not those of C. Also they allow nested
- C-style comments that are part of the SQL standard. The C part of the
- program, however, follows the C standard of not accepting nested comments.
- </p><p>
- The following sections explain all the embedded SQL statements.
- </p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="ecpg.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-connect.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 35. <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">Home</a></td><td width="40%" align="right" valign="top"> 35.2. Managing Database Connections</td></tr></table></div></body></html>
|