Jaybird 3 和数据库文件属性(页面大小,SQL 方言,ODS major/minor)

Jaybird 3 and database-file properties (page size, SQL Dialect, ODS major/minor)

在 jaybird 2 版本中,我可以通过 gds isc_info_page_size 获取数据库页面大小。但现在我无法找到 - 在 jaybird 3.0 中是否可以做到这一点? 我有 host:port、数据库文件 name/alias 和 login/password - 我不想使用 MON$ 表。

我看了文档,只发现 FBManager 可以 return int getPageSize() 但文档说:创建时要使用的页面大小数据库,或 -1 如果使用数据库默认值。

但是我有一个现有的数据库,现在想知道它的页面大小。不统计不解析header信息能行吗?

PS。如果你告诉我如何知道数据库 SQL 方言和 ODS 版本

也会很有帮助

class FBManager 用于创建(或删除)数据库,页面大小用于创建数据库。

FirebirdDatabaseMetaData接口中可以使用以下方法:

/**
 * Get the major version of the ODS (On-Disk Structure) of the database.
 * 
 * @return The major version number of the database itself
 * @exception SQLException if a database access error occurs
 */
int getOdsMajorVersion() throws SQLException;

/**
 * Get the minor version of the ODS (On-Disk Structure) of the database.
 * 
 * @return The minor version number of the database itself
 * @exception SQLException if a database access error occurs
 */
int getOdsMinorVersion() throws SQLException;

/**
 * Get the dialect of the database.
 *
 * @return The dialect of the database
 * @throws SQLException if a database access error occurs
 * @see #getConnectionDialect()
 */
int getDatabaseDialect() throws SQLException;

/**
 * Get the dialect of the connection.
 * <p>
 * The connection dialect may be different from the database dialect.
 * </p>
 *
 * @return The dialect of the connection
 * @throws SQLException if a database access error occurs
 * @see #getDatabaseDialect()
 */
int getConnectionDialect() throws SQLException;

要访问这些,您需要解包数据库元数据对象:

Connection connection = ...
FirebirdDatabaseMetaData fbmd = connection.getMetaData().unwrap(FirebirdDatabaseMetaData.class);

int odsMajorVersion = fbmd.getOdsMajorVersion();
// etc

据我所知,页面大小没有暴露在任何地方。请在 http://tracker.firebirdsql.org/browse/JDBC

上提交改进请求

如果你真的想 fiddle 内部,你总是可以使用新的内部 API,但它应该被认为是不稳定的并且可能随时改变(它可能会变成在 Java 9 的未来版本中无法访问或更难访问,具体取决于我们将如何实现模块支持)。

警告:我在没有编译或测试的情况下输入了这个:

Connection connection = ...
FbDatabase db = connection.unwrap(FirebirdConnection.class).getFbDatabase();
byte[] info = db.getDatabaseInfo(new byte[] { ISCConstants.isc_info_page_size }, 20);
if (info[0] == ISCConstants.isc_info_page_size) {
    int valueLength = VaxEncoding.iscVaxInteger2(info, 1);
    int pageSize = VaxEncoding.iscVaxInteger(info, 3, valueLength);
    // ...
}

或者使用它的同级

/**
 * Request database info.
 *
 * @param requestItems
 *         Array of info items to request
 * @param bufferLength
 *         Response buffer length to use
 * @param infoProcessor
 *         Implementation of {@link InfoProcessor} to transform
 *         the info response
 * @return Transformed info response of type T
 * @throws SQLException
 *         For errors retrieving or transforming the response.
 */
<T> T getDatabaseInfo(byte[] requestItems, int bufferLength, InfoProcessor<T> infoProcessor) throws SQLException;

查看 FBStatisticsManager

中的工作示例

免责声明:我维护 Jaybird。