Re: Error -254 In ESQL/C With Dynamic SQL?
Posted in 1996
The Informix DESCRIBE statement tells you all about the *output* variables. The OPEN statement needs the *input* variables. The lists are usually different and incompatible, leading to the errors you are getting. There is no support in Informix for describing the input variables -- you have to know what values to supply, possibly even setting up your own descriptor structure. In case of doubt, you can probably use character strings and character representations of the input variables. In the particular case of your code, you simply do not need to open the cursor with the USING clause -- you need it in the FETCH statement instead (which is carefully omitted from your code). But if you had one, you'd have to fix up the storage area for the data -- that takes more code than you show. Also, you normally describe a statement before opening the cursor. You are using your descriptor before you've set it up, but you're using it where you shouldn't anyway, and so on... Please indicate which book you are using (manual title, version, chapter and page, please). Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> }From: "Alexander J. Oss" <alex.oss@films.com> }Date: Wed, 26 Jun 96 17:58:37 EDT }X-Informix-List-Id: <news.25467> } }I'm trying to use an SQL Descriptor to perform dynamic SQL as described in the }ESQL/C manual, and when I try to open a cursor using this method, I am getting }an error -254, "Too many or too few host variables given." Since I use a }"using sql descriptor" clause, the DESCRIBE of the prepared statement should }have automatically provided an appropriate descriptor for the cursor. } }I took the example from the book and did something for the stores7 database }(below), which I mailed to Informix five days ago. I got a call back today, }and the last I heard, they got a mix of core dumps and not being able to }connect to the database with this code on a Sun box. However, I suspect the }person helping me is not an ESQL/C maven, since he did not know what to do to }fix my ANSI prototype function declaration. I'm running Online DSA 7.10.UC2 }on an NCR 3431. } }Has anybody come across anything like this? Thanks for your help! } }The following program prints out "4: -254", meaning that an error -254 has }occurred at the fourth tested statement, the OPEN. } }#include <stdio.h> } }void test(int i) }{ } if (SQLCODE) } { } fprintf(stderr, "%d: %d\\n", i, SQLCODE); } exit(1); } } }} } }int main() }{ } exec sql begin declare section; } char statementText[] = } "select customer_num from customer"; } exec sql end declare section; } } exec sql database stores7; } test(0); } } exec sql prepare statementId from :statementText; } test(1); } } exec sql declare cursorId cursor for statementId; } test(2); } } exec sql allocate descriptor 'descriptorId'; } test(3); } } exec sql open cursorId using sql descriptor 'descriptorId'; } test(4); } } exec sql describe statementId using sql descriptor 'descriptorId'; } test(5); } } exec sql close cursorId; } test(6); } } exec sql free cursorId; } test(7); } } exec sql deallocate descriptor 'descriptorId'; } test(8); } } exec sql free statementId; } test(9); } } return(0); }}