gpt4 book ai didi

java - Jaybird 3 和数据库文件属性(页面大小、SQL 方言、ODS 主要/次要)

转载 作者:行者123 更新时间:2023-11-29 04:32:40 25 4
gpt4 key购买 nike

在 jaybird 2 版本中,我可以通过 gds isc_info_page_size 获取数据库页面大小。但现在我无法找到 - 在 jaybird 3.0 中是否可以做到这一点?我有主机:端口、数据库文件名/别名和登录名/密码 - 我不想使用 MON$ 表。

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

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

附言。如果您指出如何了解数据库 SQL 方言和 ODS 版本,也会很有帮助

最佳答案

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

FirebirdDatabaseMetaData 接口(interface)中提供了以下方法:

/**
* 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 上提出改进请求

如果你真的想摆弄内部结构,你总是可以使用新的内部 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。

关于java - Jaybird 3 和数据库文件属性(页面大小、SQL 方言、ODS 主要/次要),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43191002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com