<s>
ECPG	B-Language
is	O
the	O
standard	O
,	O
in	O
the	O
PostgreSQL	B-Application
database	O
built-in	O
,	O
client	O
programming	O
interface	O
for	O
embedding	O
SQL	B-Language
in	O
programs	O
written	O
in	O
the	O
C	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
It	O
provides	O
the	O
option	O
for	O
accessing	O
the	O
PostgreSQL	B-Application
database	O
directly	O
from	O
the	O
C	B-Language
code	O
in	O
the	O
application	O
,	O
using	O
SQL	B-Language
commands	O
.	O
</s>
<s>
First	O
,	O
a	O
.pgc	O
file	O
has	O
to	O
be	O
created	O
,	O
which	O
consists	O
of	O
C	B-Language
code	O
with	O
embedded	O
SQL	B-Language
code	O
.	O
</s>
<s>
In	O
such	O
file	O
SQL	B-Language
code	O
will	O
be	O
inserted	O
directly	O
to	O
the	O
application	O
's	O
C	B-Language
code	O
.	O
</s>
<s>
The	O
SQL	B-Language
commands	O
have	O
to	O
be	O
inserted	O
into	O
the	O
C	B-Language
code	O
in	O
following	O
way	O
:	O
</s>
<s>
The	O
embedded	O
SQL	B-Language
part	O
will	O
be	O
processed	O
through	O
ECPG	B-Language
preprocessor	O
where	O
SQL	B-Language
code	O
will	O
be	O
replaced	O
with	O
the	O
calls	O
to	O
the	O
ecpg	B-Language
library	O
(	O
libecpg.a	O
or	O
libecpg.so	O
)	O
.	O
</s>
<s>
The	O
.pcg	O
file	O
will	O
be	O
also	O
preprocessed	O
with	O
ecpg	B-Language
,	O
which	O
converts	O
it	O
to	O
a	O
.c	B-Language
file	O
according	O
to	O
the	O
ANSI	O
standards	O
.	O
</s>
<s>
Therefore	O
,	O
in	O
the	O
second	O
step	O
,	O
the	O
generated	O
.c	B-Language
file	O
can	O
be	O
directly	O
compiled	O
with	O
a	O
standard	O
C	B-Language
compiler	O
.	O
</s>
<s>
Following	O
command	O
will	O
create	O
from	O
the	O
my_c_file_with_embedded_sql_commands.pcg	O
file	O
a	O
my_c_file_with_embedded_sql_commands.c	O
file	O
,	O
which	O
can	O
be	O
processed	O
further	O
as	O
a	O
pure	O
C	B-Language
code	O
.	O
</s>
<s>
There	O
is	O
also	O
source	O
code	O
of	O
the	O
ecpg	B-Language
available	O
in	O
the	O
repository	O
.	O
</s>
<s>
Note	O
:	O
While	O
compiling	O
the	O
preprocessed	O
.c	B-Language
code	O
,	O
do	O
not	O
forget	O
to	O
link	O
the	O
ecpg	B-Language
library	O
(	O
libepcg	O
)	O
,	O
so	O
that	O
the	O
generated	O
calls	O
can	O
find	O
their	O
linked	O
methods	O
.	O
</s>
<s>
An	O
important	O
part	O
when	O
embedding	O
SQL	B-Language
database	I-Language
commands	O
in	O
application	O
's	O
code	O
is	O
the	O
data	O
exchange	O
between	O
application	O
and	O
database	O
.	O
</s>
<s>
Host	O
variables	O
can	O
be	O
directly	O
used	O
from	O
the	O
embedded	O
SQL	B-Language
code	O
,	O
so	O
there	O
is	O
no	O
need	O
to	O
generate	O
SQL	B-Language
statements	O
with	O
values	O
from	O
the	O
C	B-Language
code	O
manually	O
as	O
string	O
at	O
the	O
runtime	O
.	O
</s>
<s>
Assuming	O
there	O
is	O
a	O
variable	O
named	O
variablename	O
in	O
your	O
C	B-Language
code	O
:	O
</s>
<s>
The	O
above	O
example	O
shows	O
how	O
to	O
pass	O
a	O
C	B-Language
variable	O
to	O
the	O
SQL	B-Language
,	O
but	O
data	O
can	O
be	O
passed	O
also	O
in	O
the	O
opposite	O
direction	O
:	O
back	O
to	O
the	O
application	O
.	O
</s>
<s>
The	O
following	O
example	O
shows	O
how	O
to	O
pass	O
value	O
from	O
SQL	B-Language
back	O
to	O
the	O
application	O
's	O
C	B-Language
variable	O
.	O
</s>
<s>
For	O
better	O
error	O
handling	O
,	O
ECPG	B-Language
also	O
provides	O
structure	O
called	O
SQL	B-Language
communication	O
area	O
(	O
sqlca	O
)	O
.	O
</s>
<s>
This	O
structure	O
will	O
be	O
filled	O
after	O
every	O
execution	O
of	O
sql	B-Language
statement	O
(	O
Every	O
thread	O
has	O
its	O
own	O
sqlca	O
)	O
and	O
contains	O
warning	O
and	O
error	O
information	O
,	O
e.g.	O
</s>
<s>
Since	O
ECPG	B-Language
supports	O
embedding	O
SQL	B-Language
in	O
the	O
C	B-Language
programming	I-Language
language	I-Language
,	O
it	O
also	O
indirectly	O
supports	O
embedding	O
in	O
the	O
C++	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
The	O
SQL	B-Language
parts	O
are	O
translated	O
into	O
C	B-Language
library	O
calls	O
.	O
</s>
<s>
These	O
are	O
generated	O
inside	O
of	O
an	O
extern	O
"	O
C	B-Language
"	O
clause	O
,	O
which	O
provides	O
linkage	O
between	O
modules	O
written	O
in	O
different	O
programming	O
languages	O
.	O
</s>
<s>
Using	O
ECPG	B-Language
with	O
the	O
C++	B-Language
code	I-Language
has	O
some	O
limitations	O
,	O
since	O
the	O
ECPG	B-Language
preprocessor	O
does	O
not	O
understand	O
the	O
specific	O
syntax	O
and	O
reserved	O
words	O
in	O
the	O
C++	B-Language
programming	I-Language
language	I-Language
.	O
</s>
<s>
It	O
is	O
recommended	O
to	O
separate	O
the	O
embedded	O
SQL	B-Language
commands	O
in	O
a	O
linked	O
C	B-Language
module	O
,	O
which	O
will	O
be	O
linked	O
and	O
called	O
from	O
the	O
C++	B-Language
application	O
.	O
</s>
<s>
Besides	O
the	O
internal	O
ECPG	B-Language
,	O
there	O
are	O
also	O
different	O
external	O
interfaces	O
for	O
C++	B-Language
,	O
Java	B-Language
,	O
Lua	B-Language
,	O
.NET	B-Application
,	O
Node.js	B-Language
,	O
Python	B-Language
,	O
PHP	B-Application
and	O
others	O
available	O
for	O
the	O
PostgreSQL	B-Application
database	O
,	O
that	O
can	O
be	O
added	O
in	O
order	O
to	O
extend	O
the	O
embedded	O
SQL	B-Language
options	O
.	O
</s>
<s>
There	O
are	O
also	O
other	O
databases	O
that	O
support	O
embedded	O
SQL	B-Language
,	O
also	O
in	O
other	O
languages	O
than	O
C	B-Language
such	O
as	O
Java	B-Language
,	O
.NET	B-Application
,	O
Fortran	B-Application
,	O
COBOL	B-Application
,	O
PL/I	B-Language
.	O
</s>
