如何轻松确定.fdb文件的版本(Firebird数据库)

时间:2018-03-17 14:32:09

标签: firebird firebird-embedded

在查看专有软件的.fdb数据库(可能使用Firebird Embedded)时,如何确定需要设置哪个版本的Firebird?

我目前唯一想象的方法是在'ODS-version'上查看十六进制查看器,它是页眉的一部分,很可能也用作文件头的格式,然后通过某种方式挖掘资源库历史,找出哪个Firebird版本支持哪个ODS版本。 ODS版本,至少现在,编码如下所述。

相关文档: https://firebirdsql.org/file/documentation/reference_manuals/reference_material/Firebird-Internals.pdf

相关代码:

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

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);
}

确实没有更简单的方法来确定所需的火鸟版本,例如用一些cli工具?

1 个答案:

答案 0 :(得分:2)

如果您手头有Firebird安装,则可以使用gstat检查数据库的ODS。例如:

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

如果gstat版本支持数据库的ODS版本,您将获得如下内容:

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*

此处ODS version 13.0表示它是Firebird 4数据库。

如果gstat版本不支持数据库的ODS版本,您将收到类似的错误(例如,在Firebird 2.5 / ODS 11.2数据库中使用Firebird 4 gstat):

Wrong ODS version, expected 13, encountered 11

这有其缺点:它没有提供ODS次要版本,例如当使用Firebird 2.0(ODS 11.0)或2.1(ODS 11.1)gstat访问Firebird 2.5(ODS 11.2)数据库时,这将导致无用的错误消息:

Wrong ODS version, expected 11, encountered 11

最快的路线是使用Firebird 2.5 gstat,因为这将允许您精确定位10(Firebird 1)和11.2(Firebird 2.5)之间的确切ODS版本,同时错误消息将允许您精确定位如果你需要更新版本(例如ODS 12是Firebird 3,ODS 13是Firebird 4)。

但是,您还需要查看gstat的Implementation输出。 Firebird数据库文件具有特定于平台的存储(尽管自Firebird 2.0以来已经减少了)。例如,在Firebird 1.5及更早版本(ODS 10)中,64位Firebird无法访问32位Firebird的数据库。来自小端平台(最常见)的Firebird数据库无法在大端平台上读取(反之亦然)。

在这些限制内,Firebird 2.5安装可以使用ODS 10到11.2读取数据库。 Firebird 3只能读取ODS 12,而Firebird 4只能读取ODS 13。

如果存在平台不匹配(例如旧的32/64位或小/大端)或不支持的ODS版本,则需要使用可传输备份(gbak)进行转换和/或升级。

有关ODS版本和随附的Firebird(或InterBase)版本的概述,请参阅All Firebird and InterBase On-Disk-Structure (ODS) versions