Does Firebird BLR contain the related field sizes?

2019-05-14 18:56发布

问题:

Firebird and InterBase keep a compiled form of stored procedures and triggers in BLR (tokenized) format.

But I do not really know the structure of BLR.

Is field size the part of the BLR?

Would I get some problems when a stored procedure contains two fields (source and destination), and later I'll change the size of these two fields?

For example they were varchar(50) long, but now I change them to varchar(100) with system table updates. What will happen? Would it only copy 50 characters, or all (100)?

Or does BLR contains only object links (tables and fields)?

I will try to demonstrate with "pseudo" code:

begin
  for select comp_id, comp_name from companies where ...
    into :ci, :cn 
    do begin
      -- somehow we're adding this to another table
      insert into new_clients (id, name) values (:ci, :cn);
    end
end;

This could be a trigger or stored procedure.

  1. Comp_name, and new_clients.name are initially varchar(50).
  2. I add this procedure or trigger. It is working fine for a day.
  3. Later I realize these fields are too short to fit my data.
  4. I use a GUI (for example IBExpert) to change these fields to varchar(150).
  5. It's ok, all of them are varchar(150) now.

Then what will happen?

  1. If BLR contains field sizes too, then it doesn't matter I changed the fields' sizes. The trigger copy on 50 characters, cos it has precompiled prior length.
  2. If BLR uses only relates/links/tokens to the tables and fields, we can change the fields without worrying of copy function.

The question is same: does BLR contains the related fields' sizes or not?

回答1:

First, you can see BLR of a procedure in ISQL:

SQL> create or alter procedure p1 (i1 varchar(10), i2 varchar(20)) returns (o1 varchar(30)) as begin end!
SQL> set blob all!
SQL> commit!
SQL> select rdb$procedure_blr from rdb$procedures where rdb$procedure_name = 'P1'!

blr_version5,
blr_begin,
   blr_message, 0, 4,0,
      blr_varying2, 0,0, 10,0,
      blr_short, 0,
      blr_varying2, 0,0, 20,0,
      blr_short, 0,
   blr_message, 1, 3,0,
      blr_varying2, 0,0, 30,0,
      blr_short, 0,
      blr_short, 0,
   blr_receive, 0,
    ...
blr_eoc

Second, don't, ever, change system tables.

Third, yes, you'll have a problem! It's why there is no ALTER PROCEDURE PARAMETER command.