Error handling after a SQL statement
When to check for errors
You should always test the success or failure code (the SQLCode property of the Transaction
object) after issuing one of the following statements in a script:
-
Transaction management statement (such as CONNECT, COMMIT,
and DISCONNECT) -
Embedded or dynamic SQL
Do not do this type of error checking
following a retrieval or update made in a DataWindow.
For information about handling errors in DataWindows,
see the DataWindow Programmers Guide.
SQLCode return values
Table 12-4 shows
the SQLCode return values.
Value |
Meaning |
---|---|
0 |
Success |
100 |
Fetched row not found |
-1 |
Error (the statement failed) Use SQLErrText or SQLDBCode to obtain the |
Using SQLErrText and SQLDBCode
The string SQLErrText in
the Transaction object contains the database vendor–supplied
error message. The long named SQLDBCode in
the Transaction object contains the database vendor-supplied status
code. You can reference these variables in your script.
Example
To display a message box containing the DBMS error number
and message if the connection fails, code the following:
1 |
CONNECT USING SQLCA; |
1 |
IF SQLCA.SQLCode = -1 THEN |
1 |
   MessageBox("SQL error " + String(SQLCA.SQLDBCode),& |
1 |
   SQLCA.SQLErrText ) |
1 |
END IF |