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

SQLCODE

Available in: PSQL

Added in: 1.5

Changed in: 2.0

Deprecated in: 2.5.1

Description: In a WHEN ... DO error handling block, the SQLCODE context variable contains the current SQL error code. Prior to Firebird 2.0, SQLCODE was only set in WHEN SQLCODE and WHEN ANY handlers. Now it may also be non-zero in WHEN GDSCODE and WHEN EXCEPTION blocks, provided that the condition raising the error corresponds with an SQL error code. Outside error handlers, SQLCODE is always 0. Outside PSQL it doesn't exist at all.

Type: INTEGER

Example: 

when any
do
begin
  if (sqlcode <> 0) then
    Msg = 'An SQL error occurred!';
  else
    Msg = 'Something bad happened!';
  exception ex_custom Msg;
end

Important notice: SQLCODE is now deprecated in favour of the SQL-2003-compliant SQLSTATE status code. Support for SQLCODE and WHEN SQLCODE will be discontinued in some future version of Firebird.

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