Search code examples
firebirdfirebird2.5

Copy stored procedure to another Firebird database using BLR code


I need to copy a stored procedure from one Firebird database (v2.5.9) to other Firebird database (v5.0.1), but I don't have the source code. With isql I can extract the BLR of the stored procedure, and I was wondering if there is a way to create the stored procedure in the second database using only the BLR code.


Solution

  • In theory yes, in practice, no. For the following reasons:

    1. AFAIK, BLR can change between versions, sometimes in incompatible ways. So you can't just copy the BLR from one version to the other and expect it to work. (I might be wrong about this though.)
    2. There might be references by IDs and other things that are specific to your database, which might be hard to replace.
    3. There is nothing in Firebird itself that support this, and getting the BLR into the other Firebird database would require direct system table manipulation, which is no longer allowed since Firebird 3.0. So even if the previous points don't apply, you're stuck here.

    Assuming the original author of the stored procedure deleted the source code from the RDB$PROCEDURE_SOURCE column, and they refuse to hand over the code, the best thing you can do is view the BLR by casting to a BLOB SUB_TYPE TEXT (which will generate a "human readable" representation of the BLR), and use that to try and reverse engineer the stored procedure.

    Alternatively, you could try and upgrade a copy of that Firebird 2.5 database using gbak (backup and restore), and instead copy the data of the other database into that database, so you have access to the stored procedure.