12.18SQLCODE

SQLCODE of the Firebird error in a WHEN …​ DO block

Available inPSQL

Deprecated in2.5.1

TypeINTEGER

Syntax

  |SQLCODE

In a WHEN …​ DO error handling block, the SQLCODE context variable contains the numeric value of the current SQL error code. SQLCODE is non-zero in WHEN …​ DO blocks, if the current error has a SQL error code. Outside error handlers, SQLCODE is always 0. Outside PSQL, it doesn’t exist at all.

🛑
Warning

SQLCODE is now deprecated in favour of the SQL-2003-compliant Section 12.19, “SQLSTATE status code. Support for SQLCODE and WHEN SQLCODE will be discontinued in a future version of Firebird.

Example

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