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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

DDL statements<br />

/* Determines if A is a multiple of B: */<br />

set term #;<br />

create procedure ismultiple (a bigposnum, b bigposnum)<br />

returns (res bool3)<br />

as<br />

declare ratio type of bigposnum; -- ratio is a bigint<br />

declare remainder type of bigposnum; -- so is remainder<br />

begin<br />

if (a is null or b is null) then res = null;<br />

else if (b = 0) then<br />

begin<br />

if (a = 0) then res = 1; else res = 0;<br />

end<br />

else<br />

begin<br />

ratio = a / b; -- integer division!<br />

remainder = a - b*ratio;<br />

if (remainder = 0) then res = 1; else res = 0;<br />

end<br />

end#<br />

set term ;#<br />

Warning<br />

If you change a domain's definition, existing PSQL code using that domain may become invalid. If this happens,<br />

the system table field RDB$VALID_BLR will be set to 0 for any procedure or trigger whose code is no longer<br />

valid. If you have changed a domain, the following query will find the code modules that depend on it and<br />

report the state of RDB$VALID_BLR:<br />

select * from (<br />

select 'Procedure', rdb$procedure_name, rdb$valid_blr from rdb$procedures<br />

union<br />

select 'Trigger', rdb$trigger_name, rdb$valid_blr from rdb$triggers<br />

) (type, name, valid)<br />

where exists<br />

(select * from rdb$dependencies<br />

where rdb$dependent_name = name and rdb$depended_on_name = 'MYDOMAIN')<br />

/* Replace MYDOMAIN with the actual domain name. Use all-caps if the domain<br />

was created case-insensitively. Otherwise, use the exact capitalisation. */<br />

Unfortunately, not all PSQL invalidations will be reflected in the RDB$VALID_BLR field. It is therefore advisable<br />

to look at all the procedures and triggers reported by the above query, even those having a 1 in the<br />

“VALID” column.<br />

Please notice that for PSQL modules inherited from earlier <strong>Firebird</strong> versions (including a number of system<br />

triggers, even if the database was created under <strong>Firebird</strong> <strong>2.1</strong> or higher), RDB$VALID_BLR is NULL. This does<br />

not indicate that their BLR is invalid.<br />

The isql commands SHOW PROCEDURES and SHOW TRIGGERS flag modules whose RDB$VALID_BLR field<br />

is zero with an asterisk. SHOW PROCEDURE PROCNAME and SHOW TRIGGER TRIGNAME, which display individual<br />

PSQL modules, do not signal invalid BLR.<br />

COLLATE in variable and parameter declarations<br />

Changed in: <strong>2.1</strong><br />

30

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

Saved successfully!

Ooh no, something went wrong!