FirebirdSQL logo

OLD

Record with the initial values of a row before update or delete

Available in

PSQL — triggers only,
DSQL — RETURNING clause of UPDATE, UPDATE OR INSERT and MERGE

Type

Record type

Syntax
OLD.column_name
Table 1. OLD Parameters
Parameter Description

column_name

Column name to access

OLD contains the existing version of a database record just before a deletion or update.The OLD record is read-only.

Note

In multi-action triggers OLD is always available.However, if the trigger is fired by an INSERT, there is obviously no pre-existing version of the record.In that situation, reading from OLD will always return NULL.

RESETTING

Indicates if the trigger fired during a session reset

Available in

PSQL — triggers only

Type

BOOLEAN

Syntax
RESETTING

Its value is TRUE if session reset is in progress and FALSE otherwise.Intended for use in ON DISCONNECT and ON CONNECT database triggers to detect an ALTER SESSION RESET.

ROW_COUNT

Number of affected rows of the last executed statement

Available in

PSQL

Type

INTEGER

Syntax
ROW_COUNT

The ROW_COUNT context variable contains the number of rows affected by the most recent DML statement (INSERT, UPDATE, DELETE, SELECT or FETCH) in the current PSQL module.

Behaviour with SELECT and FETCH
  • After a singleton SELECT, ROW_COUNT is 1 if a data row was retrieved and 0 otherwise.

  • In a FOR SELECT loop, ROW_COUNT is incremented with every iteration (starting at 0 before the first).

  • After a FETCH from a cursor, ROW_COUNT is 1 if a data row was retrieved and 0 otherwise.Fetching more records from the same cursor does not increment ROW_COUNT beyond 1.

Note

ROW_COUNT cannot be used to determine the number of rows affected by an EXECUTE STATEMENT or EXECUTE PROCEDURE command.

Example
update Figures set Number = 0 where id = :id;
if (row_count = 0) then
  insert into Figures (id, Number) values (:id, 0);

SQLCODE

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

Available in

PSQL

Deprecated in

2.5.1

Type

INTEGER

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 [fblangref50-contextvars-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