/
Ao
/
MaxReport
Обзор
Документация
Войти
/
Ao
/
MaxReport
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
pgsql/doc/src/sgml/html/ecpg-concept.html
52 строки
6 KB
AoAnima
first_commit
13 июл 2026, 17:47
13 июл 2026, 17:47
f1a670a
Код
Авторство
О чём код?
<?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>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.4 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> 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="34.10. Processing Embedded SQL Programs">Section 34.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. </p><p> 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 as per the SQL standard. The C part of the program, however, follows the C standard of not accepting nested comments. Embedded <acronym class="acronym">SQL</acronym> statements likewise use SQL rules, not C rules, for parsing quoted strings and identifiers. (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 <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 ECPG assumes that <code class="varname">standard_conforming_strings</code> is <code class="literal">on</code>.) Of course, the C part of the program follows C quoting rules. </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" 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.4 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 34.2. Managing Database Connections</td></tr></table></div></body></html>