SQLSTATE
<< SQLCODE | FB 2.5 Language Reference | UPDATING >>
SQLSTATE
Available in: PSQL
Added in: 2.5.1
Description
In a WHEN ... DO error handler, the SQLSTATE context variable contains the 5-character, SQL-2003-compliant status code resulting from the statement that raised the error. Outside error handlers, SQLSTATE is always '00000'. Outside PSQL it is not available at all.
Type: CHAR(5)
Example
when any
do
begin
Msg = case sqlstate
when '22003' then 'Numeric value out of range.'
when '22012' then 'Division by zero.'
when '23000' then 'Integrity constraint violation.'
else 'Something bad happened! SQLSTATE = ' || sqlstate
end;
exception ex_custom Msg;
end
Notes:
SQLSTATEis destined to replaceSQLCODE. The latter is now deprecated in Firebird and will disappear in some future version.- Firebird does not (yet) support the syntax
WHEN SQLSTATE ... DO. You have to useWHEN ANYand test theSQLSTATEvariable within the handler. - Each
SQLSTATEcode is the concatenation of a 2-character class and a 3-character subclass. Classes00(successful completion),01(warning) and02(no data) represent completion conditions. Every status code outside these classes is an exception. Because classes00,01and02don't raise an error, they won't ever show up in theSQLSTATEvariable. - For a complete listing of
SQLSTATEcodes, consult the Appendix to the Firebird 2.5 Release Notes.
back to top of page
<< SQLCODE | FB 2.5 Language Reference | UPDATING >>







