Function Sequence Error
The "Function sequence error" may occur when you execute a SQL statement in the wrong context, such as when a SQL result set has not been completely read by the client.
A common cause of this error is executing a SELECT statement without processing the result set before executing another SQL statement. Alpha Anywhere attempts to release all resources held when you attempt to execute another SQL statement. There are cases, however, when an error in your code or a complex SQL statement will cause the following error:
Function sequence error
Two cases where this error can occur are described below.
1. You have assigned the ResultSet property of a connection to a local variable. You then execute another SQL statement (perhaps within a transaction initiated by SQL::Connection::BeginTransaction()), then execute another SQL statement on the connection and then attempt to call the SQL::Connection::Commit() or SQL::Connection::Rollback() function on the current connection.
For more information on best practices for storing the connection object's ResultSet property in a variable, see An Important Note About Assigning the ResultSet Property to Variables in the documentation for the SQL::Connection class.
2. You have called SQL::Connection::Execute() with a string beginning with an INSERT, UPDATE, or DELETE SQL statement and followed by one or more other SQL statements that return a result set.
Alpha DAO attempts to retrieve the value of the last inserted identity when processing an INSERT statement and the count of rows affected when processing UPDATE and DELETE statements.
In order to retrieve counts and identities while executing each SQL statement Alpha DAO looks for the keyword INSERT, UPDATE, or DELETE at the beginning of the string passed to SQL::Connection::Execute(). If the respective keyword is found, Alpha DAO will make the appropriate call for the database to retrieve this information after a successful call. You can retrieve the affected row count or last inserted identity values from the CallResult property of the SQL::Connection the Execute() function was invoked on after the call returns successfully to Xbasic.
If your SQL string includes additional statements that return a result set (such as a SELECT or a stored procedure call), a result set is opened before your SQL string completes executing. This may cause the SQL that Alpha DAO executes to fail.
If your SQL string contains multiple INSERT, UPDATE, or DELETE statements, only the count or identity of the last data update statement will be preserved. In this scenario, you may find the values in the CallResult property of the SQL::Connection object has incorrect or unexpected values.
For more information on retrieving the last inserted identity or rows affected see the SQL::CallResult class.