aboutsummaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2020-08-03 09:46:12 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2020-08-03 09:46:12 -0400
commit5f28b21eb3c5c2fb72c24608bc686acd7c9b113c (patch)
treec198f481dbb9eeb7b01d6dc65a5add0a6579d3ac /doc/src
parentb8fdee7d0ca8bd2165d46fb1468f75571b706a01 (diff)
downloadpostgresql-5f28b21eb3c5c2fb72c24608bc686acd7c9b113c.tar.gz
postgresql-5f28b21eb3c5c2fb72c24608bc686acd7c9b113c.zip
Fix behavior of ecpg's "EXEC SQL elif name".
This ought to work much like C's "#elif defined(name)"; but the code implemented it in a way equivalent to endif followed by ifdef, so that it didn't matter whether any previous branch of the IF construct had succeeded. Fix that; add some test cases covering elif and nested IFs; and improve the documentation, which also seemed a bit confused. AFAICS the code has been like this since the feature was added in 1999 (commit b57b0e044). So while it's surely wrong, there might be code out there relying on the current behavior. Hence, don't back-patch into stable branches. It seems all right to fix it in v13 though. Per report from Ashutosh Sharma. Reviewed by Ashutosh Sharma and Michael Meskes. Discussion: https://postgr.es/m/CAE9k0P=dQk9X0cU2tN49S7a9tv733-e1pVdpB1P-pWJ5PdTktg@mail.gmail.com
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/sgml/ecpg.sgml50
1 files changed, 34 insertions, 16 deletions
diff --git a/doc/src/sgml/ecpg.sgml b/doc/src/sgml/ecpg.sgml
index 106ae0984e8..1f9d35eeb3e 100644
--- a/doc/src/sgml/ecpg.sgml
+++ b/doc/src/sgml/ecpg.sgml
@@ -5695,7 +5695,7 @@ EXEC SQL UPDATE Tbl SET col = MYNUMBER;
</sect2>
<sect2 id="ecpg-ifdef">
- <title>ifdef, ifndef, else, elif, and endif Directives</title>
+ <title>ifdef, ifndef, elif, else, and endif Directives</title>
<para>
You can use the following directives to compile code sections conditionally:
@@ -5705,7 +5705,7 @@ EXEC SQL UPDATE Tbl SET col = MYNUMBER;
<listitem>
<para>
Checks a <replaceable>name</replaceable> and processes subsequent lines if
- <replaceable>name</replaceable> has been created with <literal>EXEC SQL define
+ <replaceable>name</replaceable> has been defined via <literal>EXEC SQL define
<replaceable>name</replaceable></literal>.
</para>
</listitem>
@@ -5716,30 +5716,40 @@ EXEC SQL UPDATE Tbl SET col = MYNUMBER;
<listitem>
<para>
Checks a <replaceable>name</replaceable> and processes subsequent lines if
- <replaceable>name</replaceable> has <emphasis>not</emphasis> been created with
+ <replaceable>name</replaceable> has <emphasis>not</emphasis> been defined via
<literal>EXEC SQL define <replaceable>name</replaceable></literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><literal>EXEC SQL else;</literal></term>
+ <term><literal>EXEC SQL elif <replaceable>name</replaceable>;</literal></term>
<listitem>
<para>
- Starts processing an alternative section to a section introduced by
- either <literal>EXEC SQL ifdef <replaceable>name</replaceable></literal> or
- <literal>EXEC SQL ifndef <replaceable>name</replaceable></literal>.
+ Begins an optional alternative section after an
+ <literal>EXEC SQL ifdef <replaceable>name</replaceable></literal> or
+ <literal>EXEC SQL ifndef <replaceable>name</replaceable></literal>
+ directive. Any number of <literal>elif</literal> sections can appear.
+ Lines following an <literal>elif</literal> will be processed
+ if <replaceable>name</replaceable> has been
+ defined <emphasis>and</emphasis> no previous section of the same
+ <literal>ifdef</literal>/<literal>ifndef</literal>...<literal>endif</literal>
+ construct has been processed.
</para>
</listitem>
</varlistentry>
<varlistentry>
- <term><literal>EXEC SQL elif <replaceable>name</replaceable>;</literal></term>
+ <term><literal>EXEC SQL else;</literal></term>
<listitem>
<para>
- Checks <replaceable>name</replaceable> and starts an alternative section if
- <replaceable>name</replaceable> has been created with <literal>EXEC SQL define
- <replaceable>name</replaceable></literal>.
+ Begins an optional, final alternative section after an
+ <literal>EXEC SQL ifdef <replaceable>name</replaceable></literal> or
+ <literal>EXEC SQL ifndef <replaceable>name</replaceable></literal>
+ directive. Subsequent lines will be processed if no previous section
+ of the same
+ <literal>ifdef</literal>/<literal>ifndef</literal>...<literal>endif</literal>
+ construct has been processed.
</para>
</listitem>
</varlistentry>
@@ -5748,7 +5758,9 @@ EXEC SQL UPDATE Tbl SET col = MYNUMBER;
<term><literal>EXEC SQL endif;</literal></term>
<listitem>
<para>
- Ends an alternative section.
+ Ends an
+ <literal>ifdef</literal>/<literal>ifndef</literal>...<literal>endif</literal>
+ construct. Subsequent lines are processed normally.
</para>
</listitem>
</varlistentry>
@@ -5756,14 +5768,20 @@ EXEC SQL UPDATE Tbl SET col = MYNUMBER;
</para>
<para>
- Example:
+ <literal>ifdef</literal>/<literal>ifndef</literal>...<literal>endif</literal>
+ constructs can be nested, up to 127 levels deep.
+ </para>
+
+ <para>
+ This example will compile exactly one of the three <literal>SET
+ TIMEZONE</literal> commands:
<programlisting>
-EXEC SQL ifndef TZVAR;
-EXEC SQL SET TIMEZONE TO 'GMT';
+EXEC SQL ifdef TZVAR;
+EXEC SQL SET TIMEZONE TO TZVAR;
EXEC SQL elif TZNAME;
EXEC SQL SET TIMEZONE TO TZNAME;
EXEC SQL else;
-EXEC SQL SET TIMEZONE TO TZVAR;
+EXEC SQL SET TIMEZONE TO 'GMT';
EXEC SQL endif;
</programlisting>
</para>