Informix Query Problem
Posted in 1993
Topics: SQL Development & Query Writing, Connectivity: ESQL/C, 4GL & Embedded SQL
calvin writes: > We are having a problem running a 4gl program on two of our production > machines. The program runs fine on 3 others. We are attempting to do a count > distinct to find the number of rows that are found by a query. The query which > actually returns the rows works fine, but the count distinct is giving the > "Attempt to fetch an unopen cursor." The syntax is the same as the query for > the rows, with the declare, prepare, open and fetch, in fact the open is the > statement immediatly proceding the fetch. We changed the fetch to a foreach > loop, and the program works fine. I have to ignore that the code is valid on the failing systems even though other systems with the 'same' code work. The code, at least for the failing systems, cannot be valid or it would work - the only other option is that the 'valid' code has a corrupted binary, and a recompile is all that would be needed. That you can change the structure of the code on the broken machines and make it work is another indication that something is different. Since you didn't include the appropriate lines of code I have to assume a lot. So, assuming you need to know even the basics, the best approach is for you to compare the algorithm you are using in your application against the demo programs that Informix includes that do exactly the same thing. When you mentioned that you get the error message, "Attempt to fetch an opened cursor" and then say that by substituting 'foreach' for 'fetch' solves the problem, tells me that possibly not enough preparation is included in the code. In order to use any cursor created by a 'prepare' or 'declare' (or combination thereof) you have to 'open' it before you can use it. Next, the use of 'fetch' implies that after the 'open' you first do a 'fetch first' before going in to your while loop that does a 'fetch next', and then continue in the loop until the returned status is 'notfound'. You left out way too much needed information to make any sane evaluation of the problem. If you're willing to send me a copy of the code segment (between the creation of the select statement and close of the cursor) I'm willing to check it out for you, unless what I've indicated here has helped sufficiently. ------------------------------------------------------------------ John R. Carter, Sr. Programmer/Analyst for Informix products 71553.535@compuserve.com ------------------------------------------------------------------