Question on SQLCODE -254
Posted in 2017
I was recently trying to find out why a cursor was not returning the correct results. The root cause was that the FETCH statement had a different number of host variables than the SELECT that had been PREPAREd and DECLAREd as the cursor. The surprising thing was that the SQLCODE was always 0. I would have expected a non-zero SQLCODE. Specifically, I would have expected -254 ('finder -254' output below): -254 Too many or too few host variables given. The number of host variables that you named in the INTO clause of this statement does not match the number of columns that you referenced in the statement. Locate the text of the statement (in a PREPARE or DECLARE statement) and verify the number of placeholders. Then review the list in the INTO clause to see which item or items are incorrect. ----- end of finder output --------- Based on the finder description, it certainly looks like we should have received a -254 SQLCODE when executing the FETCH. Since the application was written in one of the x4gl products, we contacted the vendor to ask why it did not return -254. Their reply was that their product worked the same as C4GL, and that this was expected behavior. I was virtually certain that could not be correct, but I don't have access to C4GL. Instead, I constructed a test case in ESQL/C, doing the same steps as the x4gl application. I was surprised to find that it, too, returned SQLCODE 0 regardless of whether the FETCH included too few , too many or the correct number of host variables. I also created an ESQL/C test case with a simple SELECT ... INTO ... statement, with an incorrect number of host variables in the INTO clause. Again, SQLCODE = 0. The same was true if I did a PREPAREd a SELECT statement and then did an EXECUTE prepared_statement_name INTO .... A test case in SPL does flag this as a problem, although it returns a different error: -720 The number of returned values and of SPL variables do not match. The list of SPL variables that follows the INTO keyword has a different cardinality from the number of values in each row of the active set. This error can occur during the FOREACH statement of SPL, or during the FETCH statement of dynamic SQL. ... ----- end of finder output --------- So, my question - does Informix ever return a SQLCODE of -254? If so, under what circumstances? This with Informix 11.50.FC6. Thanks.