【发布时间】:2018-08-29 08:31:58
【问题描述】:
我正在尝试使用 gcc 7.1 创建一个带有 OCCI(版本 11、12、18,都导致下面解释的相同问题)的 C++ 应用程序。
下面的应用程序在 RHEL7 下使用 gcc 4.8.5 编译并运行良好,但在使用 gcc 7.1 编译时抛出错误 ORA-24960: the attribute OCI_ATTR_USERNAME is greater than the maximum allowable length of 255。
This question 似乎解决了这个问题,但在我的情况下,降级到较低的编译器版本不是选项,因为我需要将 OCCI 调用集成到依赖 gcc 7.1 的更大应用程序中。
这是一个 MCVE,用于简单地检查与 DB 的连接:
#include <string>
#include <occi.h>
using namespace oracle::occi;
using namespace std;
int main()
{
const string url = "//server:1234/ID";
const string username = "user";
const string password = "password";
Environment* env = Environment::createEnvironment();
try {
Connection* conn = env->createConnection(username, password, url);
cout << "Connection to " << url << " successfully established." << endl;
env->terminateConnection(conn);
cout << "Connection closed." << endl;
}
catch (const SQLException& ex) {
cerr << "Error: " << ex.what() << endl;
}
Environment::terminateEnvironment (env);
}
有没有人遇到过这个问题并知道是否有解决方法或我可以链接的静态 OCCI 库?
【问题讨论】:
-
我尽量避免使用 OCCI,g++ ABI 会不时更改,并且没有任何力量会迫使 Oracle 使用更新的编译器重新编译 OCCI。任何开源 OCI 包装器都比 OCCI 更好。例如,最近已经发生过,由于 ABI 不兼容,从 OCCI 引发的异常无法在使用较新的 g++ 编译的代码中捕获。抛出异常时,应用程序始终会出现段错误。
-
"Certified Compilers for OCCI (Doc ID 437957.1)" support doc 有关于兼容性的信息 - 基本上只有(默认?)支持的 Linux 发行版附带的编译器。正如 ibre 所说,如果需要,您可能最好使用 C 接口和其他包装器。
-
您使用的是哪个 g++ 7.1 - 软件包来自哪里?
标签: c++ oracle g++ occi oracle18c