21.10.2013 Views

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

Firebird 2.1 Language Reference Update

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Context variables<br />

Description: OLD contains the existing version of a database record just before a deletion or update. Starting<br />

with <strong>Firebird</strong> 2.0 it is read-only.<br />

Type: Data row<br />

Note<br />

Available in: PSQL<br />

Added in: 1.5<br />

Changed in: 2.0<br />

In multi-action triggers – introduced in <strong>Firebird</strong> 1.5 – OLD is always available. But if the trigger is fired by<br />

an INSERT, there is obviously no pre-existing version of the record. In that situation, reading from OLD will<br />

always return NULL; writing to it will cause a runtime exception.<br />

ROW_COUNT<br />

Description: The ROW_COUNT context variable contains the number of rows affected by the most recent DML<br />

statement (INSERT, UPDATE, DELETE, SELECT or FETCH) in the current trigger, stored procedure or executable<br />

block.<br />

Type: INTEGER<br />

Example:<br />

update Figures set Number = 0 where id = :id;<br />

if (row_count = 0) then<br />

insert into Figures (id, Number) values (:id, 0);<br />

Behaviour with SELECT and FETCH:<br />

• After a singleton SELECT, ROW_COUNT is 1 if a data row was retrieved and 0 otherwise.<br />

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

• After a FETCH from a cursor, ROW_COUNT is 1 if a data row was retrieved and 0 otherwise. Fetching more<br />

records from the same cursor does not increment ROW_COUNT beyond 1.<br />

• In <strong>Firebird</strong> 1.5.x, ROW_COUNT is 0 after any type of SELECT statement.<br />

Note<br />

ROW_COUNT cannot be used to determine the number of rows affected by an EXECUTE STATEMENT or EXE-<br />

CUTE PROCEDURE command.<br />

115

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!