SQLCODE Variable

The SQLCODE variable is an integer whose value indicates the success or failure of the most recently executed SQL statement.

Table 2–5 shows the SQLCODE return code values and their meanings.

Table 2–5: SQLCODE Return Code Values  
Return Code
Meaning
0
The statement executed successfully and no exceptional conditions occurred.
+1001
No rows were found to satisfy the request (see Table 2–6).
< 0
An error occurred. For example, an update operation violated a specified constraint, such as NOT NULL or UNIQUE. See Table 2–7 for the individual error codes and meanings.
  1. Other positive values are reserved for future informational and error messages.

Table 2–6 shows the meaning of a +100 return code for each SQL statement where this return code can occur.

Table 2–6: Meanings of the +100 Return Code  
Statement
Meaning
FETCH
There is no next row.
SELECT
INSERT . . . SELECT
There are no rows to select.
Searched UPDATE1
No rows were found to update.
Searched DELETE1
No rows were found to delete.
  1. Positioned UPDATE and DELETE return an error if no row is present to satisfy the SQL request.

Table 2–7 lists and describes the specific error code values for SQLCODE.

Table 2–7: SQLCODE Error Code Values
Error Code
Meaning
-1
General compile or run-time error. Usually results from incorrect syntax.
-2
Cardinality violation. A SELECT...INTO... statement returned more than one row, or a subquery preceded by an arithmetic operator (such as =) returned more than one row.
-11
The schema for the database has changed since the r-code for this request was generated. You must recompile the request. If the SQL Compiler is available, it recompiles automatically; otherwise, this error returns.
-16
The UPDATE...WHERE CURRENT OF... statement was not entered in the correct form.
-18
A cursor request was attempted, but the cursor has not been opened.
-21
A CTRL-C rolled back the transaction.
-26
An ESQL-LIB routine was called from within the CTRL-C interrupt handler.
-28
Error extracting value from host language variable.
-29
Error updating a host language variable.
-30
The database system caused the current transaction to be rolled back.
-40
Error extracting a host language variable.
-41
Error updating a host language variable.
-42
An attempt was made to convert between incompatible types. (For example, an attempt to convert from an SQLDADATE input to a Progress INTEGER data type is never valid.)
-43
An attempt was made to store a NULL value in a host language variable without setting an associated indicator variable.
-44
A converted value does not fit in the destination variable or field.
-45
An attempt was made to convert a string value to another type, but the current value of the string is not valid for that type.
-46
HLI_NOTCAP. ESQL is not capable of performing the requested operation.
-99
A fatal error occurred from which Progress cannot recover; you can make no further calls to ESQL-LIB except to the sqlgetmsg() function.

Using SQLCODE in an Application

If you are using the SQL preprocessor, you declare a variable named SQLCODE as a long C within the scope of any function that contains any Progress/ESQL statements except the WHENEVER, BEGIN DECLARE SECTION, or END DECLARE SECTION statements:

long SQLCODE; 

You receive source code compilation errors if you do not declare the SQLCODE variable as a long C data type. You do not have to declare it within the SQL DECLARE SECTION of your application. However, it is recommended that you do so.

The SQL preprocessor uses the address of this declared variable as an argument to an ESQL-LIB function, sqlcdbind(). By placing this function call prior to many of the calls to the ESQL-LIB interface in the generated output, the SQL preprocessor notifies the interface where to deposit the status information.

If you are not using the SQL preprocessor, or if you are using it and are accessing some of the ESQL-LIB functions that have no counterpart in Embedded SQL (especially the dynamic ESQL-LIB functions), you may still use SQLCODE as the mechanism to retrieve status information about the ESQL-LIB function calls being made. In this case, you declare a long C integer in your application and pass the address of that variable to the sqlcdbind() function. You do not have to declare the variable with the name SQLCODE.


Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095