Testing for warning conditions

Even when SQLCODE indicates that a statement has executed successfully, a warning condition may still have occurred. The 8-character array SQLCA.SQLWARN indicates such warning conditions. Each SQLWARN array element (or “flag”) stores either the space character (blank) or the character “W”. In each flag, “W” indicates that a warning condition has occurred; the kind of warning condition differs for each flag.

Table 8-2 describes what the space character or “W” means in each flag:

Table 8-2: SQLWARN flags

Flag

Description

SQLWARN1

If blank, no warning condition of any kind occurred, and all other SQLWARN flags are blank. If SQLWARN1 is set to “W,” one or more warning conditions occurred, and at least one other flag is set to “W.”

SQLWARN2

If set to “W,” the character string variable that you designated in a fetch statement was too short to store the statement’s result data, so the result data was truncated. You designated no indicator variable to receive the original length of the data that was truncated.

SQLWARN3

If set to “W,” the input sent to Adaptive Server contained a null value in an illegal context, such as in an expression or as an input value to a table that prohibits null values.

SQLWARN4

The number of columns in a select statement’s result set exceeds the number of host variables in the statement’s into clause.

SQLWARN5

Reserved.

SQLWARN6

Adaptive Server generated a conversion error while attempting to execute this statement.

SQLWARN7

Reserved.

SQLWARN8

Reserved.

Test for a warning after you determine that a SQL statement executed successfully. Use the whenever statement, as described in the next section, to instruct the precompiler to write the test code for you.