Re: Dynamic SQL with cursors
Posted in 1998
Hi Eric !!! wht I understand is this is useful only if u r selecting same no and type of columns(but different WHERE CLAUSE) in SELECT of DECLARE cursor. Assuming this I tried following and it worked : 1> Inside Function I maped value of 'x' to cursor name which are open if(x = 10 ) strcpy(cur_name,cur_emp1); if(x = 20) strcpy(cur_name,cur_emp2); etc.. 2>inside a loop I fetched the cursor EXEC SQL FETCH :cur_name INTO :var1,:var2; I am using IDS 7.1 and ESQL/C 7.1. I have no idea whether it will work on version 2.x or not. Good Luck. Sunil.. On Fri, 18 Sep 1998 asberry@acm.org wrote: > I'm trying to do something that I'm sure I've seen done before, but I must be > losing my mind because what I'm reading in the documentation seems to indicate > it can't be done. > > Basically, I have an existing application with a function that has a > parameter x. I have several cursors that I am opening, and inside my > function I want to fetch from one of these cursors depending on the value of > x (basically I want to alternate between cursors depending on x). > > The brute force method is to set up my cursor references within a switch/case > construct (there are 5 cursors for each of the 16 possible values of x). It > just seems like there should be a cleaner method to do this than to cut and > paste all this code with slight modifications in all these switch/case > statements. > > It seems like I should be able to use dynamic SQL to do this, building the > name of the cursor to be used, etc with sprintfs, but my documentation says > that you can't use prepare/execute for declare, execute, fetch and open > statements (which just happen to be the ones I need!). I tried to do it > anyway just for giggles but I end up getting a syntax error. > > This may be different in newer versions of Informix, I have a REALLY old > version of (like 2.x, and no way around that). Or maybe I'm just forgetting > something ... it's been awhile since I've done much heavy duty esql/c. > > Any suggestions other than "upgrade" would be appreciated. :) > > Thanks, > > Eric > > Eric > > -----== Posted via Deja News, The Leader in Internet Discussion ==----- > http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum >