Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to easily determine version of .fdb-file (Firebird database)

When looking at a .fdb-database of a proprietary software (probably using Firebird Embedded), how can I determine which version of Firebird I need to setup?

The only way I can currently imagine is by having a look with a hex viewer at 'ODS-version' which is part of a page header, which is most likely also used as format for the file header, and then somehow by digging through respository history find out which Firebird release supports which ODS-Version. ODS-version, atleast nowadays, is encoded like stated below.

Related docs: https://firebirdsql.org/file/documentation/reference_manuals/reference_material/Firebird-Internals.pdf

Related code:

https://github.com/FirebirdSQL/firebird/blob/3dd6a2f5366e0ae3d0e6793ef3da02f0fd05823a/src/jrd/ods.h

and

inline USHORT DECODE_ODS_MAJOR(USHORT ods_version)
{
    return ((ods_version & 0x7FF0) >> 4);
}

inline USHORT DECODE_ODS_MINOR(USHORT ods_version)
{
    return (ods_version & 0x000F);
}

Is there really no easier way to determine required firebird version, e.g. with some cli-tool?

like image 699
Manuel Arwed Schmidt Avatar asked Mar 17 '18 14:03

Manuel Arwed Schmidt


1 Answers

If you have a Firebird installation at hand, you can use gstat to check the ODS for a database. For example:

gstat -h <path-to-your-database>

If the ODS version of the database is supported by the version of gstat, you'll get something like:

Database "D:\DATA\DB\FB4\FB4TESTDATABASE.FDB"
Gstat execution time Sat Mar 17 18:08:09 2018

Database header page information:
        Flags                   0
        Generation              308
        System Change Number    0
        Page size               16384
        ODS version             13.0
        Oldest transaction      393
        Oldest active           394
        Oldest snapshot         394
        Next transaction        395
        Sequence number         0
        Next attachment ID      150
        Implementation          HW=AMD/Intel/x64 little-endian OS=Windows CC=MSVC
        Shadow count            0
        Page buffers            0
        Next header page        0
        Database dialect        3
        Creation date           Jan 6, 2017 14:05:48
        Attributes              force write

    Variable header data:
        *END*

Here ODS version 13.0 means it is a Firebird 4 database.

If the gstat version does not support the ODS version of the database, you will get an error like (eg in this case using a Firebird 4 gstat on a Firebird 2.5/ODS 11.2 database):

Wrong ODS version, expected 13, encountered 11

This has its downsides though: it doesn't provide the ODS minor versions, and for example when using a Firebird 2.0 (ODS 11.0) or 2.1 (ODS 11.1) gstat to access a Firebird 2.5 (ODS 11.2) database, this will lead to the unhelpful error message:

Wrong ODS version, expected 11, encountered 11

The quickest route is to use a Firebird 2.5 gstat as this will allow you to pinpoint the exact ODS versions between 10 (Firebird 1) and 11.2 (Firebird 2.5), and at the same time the error message will allow you to pinpoint if you need a newer version (eg ODS 12 is Firebird 3, ODS 13 is Firebird 4).

However, you will also need to look at the Implementation output of gstat. Firebird database files have platform specific storage (although this has been reduced since Firebird 2.0). For example in Firebird 1.5 and earlier (ODS 10), a database from a 32 bit Firebird cannot be accessed by a 64 bit Firebird. A Firebird database from a little endian platform (most common) cannot be read on a big endian platform (and vice versa).

Within these limitations, a Firebird 2.5 installation can read databases with ODS 10 through 11.2. Firebird 3 can only read ODS 12, and Firebird 4 only ODS 13.

If there are platform mismatches (eg old 32/64 bit or little/big endian) or unsupported ODS versions, you will need to have a transportable backup (gbak) to convert and/or upgrade.

For an overview of ODS versions and accompanying Firebird (or InterBase) version, see All Firebird and InterBase On-Disk-Structure (ODS) versions.

like image 141
Mark Rotteveel Avatar answered Oct 13 '22 11:10

Mark Rotteveel