Firebird Documentation IndexFirebird 2.5 Language Ref. UpdateContext variables → SQLSTATE
Firebird Home Firebird Home Prev: SQLCODEFirebird Documentation IndexUp: Context variablesNext: UPDATING

SQLSTATE

Tip

Find a more recent version at Firebird 5.0 Language Reference: 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: 

Prev: SQLCODEFirebird Documentation IndexUp: Context variablesNext: UPDATING
Firebird Documentation IndexFirebird 2.5 Language Ref. UpdateContext variables → SQLSTATE