ecpg "problem" ... - Mailing list pgsql-hackers

From Lee Kindness
Subject ecpg "problem" ...
Date
Msg-id 15826.7062.975.548240@kelvin.csl.co.uk
Whole thread Raw
In response to ecpg "problem" ...  ("Marc G. Fournier" <scrappy@hub.org>)
List pgsql-hackers
Marc,

Marc G. Fournier writes:>         if (ic_flag == 1) {>         /*only select those non-IC/Spyder nodes that has full
updateset*/>         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>
SELECTnode_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'tit 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_nameFROM 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.


pgsql-hackers by date:

Previous
From: Tommi Maekitalo
Date:
Subject: Re: performance regression, 7.2.3 -> 7.3b5 w/ VIEW
Next
From: Mats Lofkvist
Date:
Subject: JDBC access is broken in 7.3 beta