

        if (ic_flag == 1) {
        /*only select those non-IC/Spyder nodes that has full update set*/
        EXEC SQL DECLARE full_dyn_node CURSOR FOR
                 SELECT node_name FROM NODE
                 WHERE dynamic_community = 'f' AND ic_flag='n' AND machine_type!=22
                 AND node_id != 0 AND NODE_NAME != :nodename;
        }
        else{
        EXEC SQL DECLARE full_dyn_node CURSOR FOR
                 SELECT node_name FROM NODE
                 WHERE dynamic_community = 'f'
                 AND node_id != 0 AND NODE_NAME != :nodename; (line#493)
        }

the above code generates the following error:

The compiler complains:
../subapi.pgc:493: ERROR: cursor full_dyn_node already defined

since its envelop'd in an if/else clause, shouldn't it work?




Tue, 12 Nov 2002 14:58:17 -0400 (AST)
"Marc G. Fournier" <scrappy@hub.org>
ecpg "problem" ... 
hi,

i think that ecpg is only text preprocessor. it doesn't understand the c
semantics - it goes from the top to the end of the file row by row and
sees your declaration twice.

kuba

On Tue, 12 Nov 2002, Marc G. Fournier wrote:

>
>
>         if (ic_flag == 1) {
>         /*only select those non-IC/Spyder nodes that has full update set*/
>         EXEC SQL DECLARE full_dyn_node CURSOR FOR
>                  SELECT node_name FROM NODE
>                  WHERE dynamic_community = 'f' AND ic_flag='n' AND machine_type!=22
>                  AND node_id != 0 AND NODE_NAME != :nodename;
>         }
>         else{
>         EXEC SQL DECLARE full_dyn_node CURSOR FOR
>                  SELECT node_name FROM NODE
>                  WHERE dynamic_community = 'f'
>                  AND node_id != 0 AND NODE_NAME != :nodename; (line#493)
>         }
>
> the above code generates the following error:
>
> The compiler complains:
> ../subapi.pgc:493: ERROR: cursor full_dyn_node already defined
>
> since its envelop'd in an if/else clause, shouldn't it work?
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo@postgresql.org so that your
> message can get through to the mailing list cleanly
>


Tue, 12 Nov 2002 21:05:52 +0100 (CET)
Jakub Ouhrabka <jouh8664@ss1000.ms.mff.cuni.cz>
Re: ecpg "problem" ... 
Marc,

Marc G. Fournier writes:
 >         if (ic_flag == 1) {
 >         /*only select those non-IC/Spyder nodes that has full update set*/
 >         EXEC SQL DECLARE full_dyn_node CURSOR FOR
 >                  SELECT node_name FROM NODE
 >                  WHERE dynamic_community = 'f' AND ic_flag='n' AND machine_type!=22
 >                  AND node_id != 0 AND NODE_NAME != :nodename;
 >         }
 >         else{
 >         EXEC SQL DECLARE full_dyn_node CURSOR FOR
 >                  SELECT node_name FROM NODE
 >                  WHERE dynamic_community = 'f'
 >                  AND node_id != 0 AND NODE_NAME != :nodename; (line#493)
 >         }
 > 
 > the above code generates the following error:
 > 
 > The compiler complains:
 > ../subapi.pgc:493: ERROR: cursor full_dyn_node already defined
 > 
 > since its envelop'd in an if/else clause, shouldn't it work?

Unfortuantely no, you can only ever have one "EXEC SQL DECLARE" for a
given cursor name due to ecpg/ESQL simple parsing. What you would do
in a situation like this is something like:

  if( ic_flag == 1 )
      /* only select those non-IC/Spyder nodes that has full update set */
    sprintf(stmt, "SELECT node_name FROM NODE WHERE dynamic_community = 'f' AND ic_flag = 'n' AND machine_type != 22 AND node_id != 0 AND NODE_NAME != %s", nodename);
  else
    sprintf(stmt, "SELECT node_name FROM NODE WHERE dynamic_community = 'f' AND node_id != 0 AND NODE_NAME != %s", nodename);

  EXEC SQL PREPARE s_statement FROM :stmt;
  EXEC SQL DECLARE full_dyn_node CURSOR FOR s_statement;

Regards, Lee.

Wed, 13 Nov 2002 09:29:58 +0000
Lee Kindness <lkindness@csl.co.uk>
ecpg "problem" ... 
On Tue, Nov 12, 2002 at 02:58:17PM -0400, Marc G. Fournier wrote:
> 
> 
>         if (ic_flag == 1) {
>         /*only select those non-IC/Spyder nodes that has full update set*/
>         EXEC SQL DECLARE full_dyn_node CURSOR FOR
>                  SELECT node_name FROM NODE
>                  WHERE dynamic_community = 'f' AND ic_flag='n' AND machine_type!=22
>                  AND node_id != 0 AND NODE_NAME != :nodename;
>         }
>         else{
>         EXEC SQL DECLARE full_dyn_node CURSOR FOR
>                  SELECT node_name FROM NODE
>                  WHERE dynamic_community = 'f'
>                  AND node_id != 0 AND NODE_NAME != :nodename; (line#493)
>         }
> ...
> since its envelop'd in an if/else clause, shouldn't it work?

By definition no. You could compare it to C preprocessor commands like
#define.

Michael
-- 
Michael Meskes
Michael@Fam-Meskes.De
Go SF 49ers! Go Rhein Fire!
Use Debian GNU/Linux! Use PostgreSQL!

Thu, 14 Nov 2002 12:07:25 +0100
Michael Meskes <meskes@postgresql.org>
Re: ecpg "problem" ...