|
Scott, I made the changes to the program, and am now getting an error on the SQLFetchScroll. The error is SQ99999 Error Occurred in SQL Call Level Interface You have issued a procedure call that encountered an error. The error code is 10. Error codes are as follows: Error type 10 is function sequence error. Any suggestions? Thanks, Scott Klement <rpg400-l@xxxxxxxxxxxxxxxx> wrote: Hi Jeff, You said you're getting a -2 return code from SQLPrepare(). -2 is the same as SQL_INVALID_HANDLE (the latter being a named constant with a value of -2). Your program creates the environment and connection handles and connects successfully. The next thing it does is create another environment handle? Why would you do that? I think you probably meant to create a statement handle here, but that's not what you did! You then call SQLPrepare() and pass hstmt, but I don't see where you ever created the hstmt handle? Here's the code I'm referring to:
//********************************************************** // prepare the statement (do this once) //********************************************************** rc = SQLAllocHandle (SQL_HANDLE_ENV : SQL_NULL_HANDLE : henv); Exsr Check_Rc;
I would assume that what you really wanted to do the following, correct? rc = SQLAllocHandle (SQL_HANDLE_STMT : henv : hstmt); Exsr Check_Rc; Then you do the following:
szSqlStr = SQL_Select_Stmt; // Load SQL Statement to execute cbSqlStr = SQL_NTS; // Length // Associate SQL Statement with Handle // All SQL commands will now refer to this statement rc = SQLPrepare(hstmt : // Statement Handle szSqlStr : // Statement to execute cbSqlStr); // Length Exsr Check_Rc;
Here you're getting an SQL_INVALID_HANDLE error, which is likely to be because you never allocate hstmt (unless you change your code to match my suggestion) Another thing that struck me as odd was the following:
%Occur(Customer_Data)= 1; Rows_to_Fetch = %Elem(Customer_Data); rc = SQLFetchScroll (hstmt : // Handle SQL_FETCH_NEXT : // Type of fetch Rows_to_Fetch ); // Number of rows to fetch
Unless I'm really confused, the 3rd parameter to SQLFetchScroll is an offset, and NOT the number of rows to fetch! This offset would be used when the 2nd parameter is SQL_FETCH_RELATIVE to tell it where to move the cursor relative to the current position, which SQLFetchScroll does before it fetches a record. I don't think SQLFetchScroll is capable of fetching multiple records, is it? I thought you had to use SQLExtendedFetch() for that... However, I've never been able to get SQLExtendedFetch() to work, I always get SQLSTATE=HY010 when I try to use SQLExtendedFetch(). Since I can never get it to work properly, I didn't respond to your first question :) If SQLFetchScroll() does allow multiple records to be returned, I'd expect that you'd have to set the rowset size with SQLSetStmtAttr(). Have you tried that?
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.