1- <!-- $PostgreSQL: pgsql/doc/src/sgml/ecpg.sgml,v 1.86 2008/06/12 19:15:40 momjian Exp $ -->
1+ <!-- $PostgreSQL: pgsql/doc/src/sgml/ecpg.sgml,v 1.87 2008/12/07 23:46:39 alvherre Exp $ -->
22
33<chapter id="ecpg">
44 <title><application>ECPG</application> - Embedded <acronym>SQL</acronym> in C</title>
@@ -717,16 +717,17 @@ EXEC SQL EXECUTE mystmt USING 42, 'foobar';
717717</programlisting>
718718 If the statement you are executing returns values, then add an
719719 <literal>INTO</literal> clause:
720- <programlisting>
720+ <programlisting><![CDATA[
721721EXEC SQL BEGIN DECLARE SECTION;
722- const char *stmt = "SELECT a, b, c FROM test1 WHERE a> ?";
722+ const char *stmt = "SELECT a, b, c FROM test1 WHERE a> ?";
723723int v1, v2;
724724VARCHAR v3;
725725EXEC SQL END DECLARE SECTION;
726726
727727EXEC SQL PREPARE mystmt FROM :stmt;
728728 ...
729729EXEC SQL EXECUTE mystmt INTO v1, v2, v3 USING 37;
730+ ]]>
730731</programlisting>
731732 An <command>EXECUTE</command> command can have an
732733 <literal>INTO</literal> clause, a <literal>USING</literal> clause,
@@ -752,20 +753,21 @@ EXEC SQL DEALLOCATE PREPARE <replaceable>name</replaceable>;
752753 functions to do basic calculations with those types within C, i.e. without
753754 the help of the <productname>PostgreSQL</productname> server. See the
754755 following example:
755- <programlisting>
756+ <programlisting><![CDATA[
756757EXEC SQL BEGIN DECLARE SECTION;
757758 date date1;
758759 timestamp ts1, tsout;
759760 interval iv1;
760761 char *out;
761762EXEC SQL END DECLARE SECTION;
762763
763- PGTYPESdate_today(& date1);
764+ PGTYPESdate_today(&date1);
764765EXEC SQL SELECT started, duration INTO :ts1, :iv1 FROM datetbl WHERE d=:date1;
765- PGTYPEStimestamp_add_interval(& ts1, & iv1, & tsout);
766- out = PGTYPEStimestamp_to_asc(& tsout);
766+ PGTYPEStimestamp_add_interval(&ts1, &iv1, &tsout);
767+ out = PGTYPEStimestamp_to_asc(&tsout);
767768printf("Started + duration: %s\n", out);
768769free(out);
770+ ]]>
769771</programlisting>
770772 </para>
771773
@@ -3449,14 +3451,15 @@ int rsetnull(int t, char *ptr);
34493451
34503452 <para>
34513453 Here is an example of a call to this function:
3452- <programlisting>
3454+ <programlisting><![CDATA[
34533455$char c[] = "abc ";
34543456$short s = 17;
34553457$int i = -74874;
34563458
34573459rsetnull(CCHARTYPE, (char *) c);
3458- rsetnull(CSHORTTYPE, (char *) &s);
3459- rsetnull(CINTTYPE, (char *) &i);
3460+ rsetnull(CSHORTTYPE, (char *) &s);
3461+ rsetnull(CINTTYPE, (char *) &i);
3462+ ]]>
34603463</programlisting>
34613464 </para>
34623465 </listitem>
@@ -3477,14 +3480,15 @@ int risnull(int t, char *ptr);
34773480 </para>
34783481 <para>
34793482 Here is an example of how to use this function:
3480- <programlisting>
3483+ <programlisting><![CDATA[
34813484$char c[] = "abc ";
34823485$short s = 17;
34833486$int i = -74874;
34843487
34853488risnull(CCHARTYPE, (char *) c);
3486- risnull(CSHORTTYPE, (char *) &s);
3487- risnull(CINTTYPE, (char *) &i);
3489+ risnull(CSHORTTYPE, (char *) &s);
3490+ risnull(CINTTYPE, (char *) &i);
3491+ ]]>
34883492</programlisting>
34893493 </para>
34903494 </listitem>
@@ -4960,11 +4964,11 @@ EXEC SQL END DECLARE SECTION;
49604964EXEC SQL SELECT res INTO :result FROM mytable WHERE index = :index;
49614965</programlisting>
49624966 is translated into:
4963- <programlisting>
4967+ <programlisting><![CDATA[
49644968/* Processed by ecpg (2.6.0) */
49654969/* These two include files are added by the preprocessor */
4966- #include< ecpgtype.h> ;
4967- #include< ecpglib.h> ;
4970+ #include< ecpgtype.h> ;
4971+ #include< ecpglib.h> ;
49684972
49694973/* exec sql begin declare section */
49704974
@@ -4975,11 +4979,12 @@ EXEC SQL SELECT res INTO :result FROM mytable WHERE index = :index;
49754979/* exec sql end declare section */
49764980...
49774981ECPGdo(__LINE__, NULL, "SELECT res FROM mytable WHERE index = ? ",
4978- ECPGt_int,& (index),1L,1L,sizeof(int),
4982+ ECPGt_int,&(index),1L,1L,sizeof(int),
49794983 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EOIT,
4980- ECPGt_int,& (result),1L,1L,sizeof(int),
4984+ ECPGt_int,&(result),1L,1L,sizeof(int),
49814985 ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L, ECPGt_EORT);
49824986#line 147 "foo.pgc"
4987+ ]]>
49834988</programlisting>
49844989 (The indentation here is added for readability and not
49854990 something the preprocessor does.)