简体   繁体   English

当值> = 16时ResultSet-> getString()崩溃

[英]ResultSet ->getString() crashes when value is >=16

ResultSet *search;
....
....
search= prepareStatement->executeQuery();


while (search->next())
{
cout << "Email Found: " << search->getString("EmailColumn") << endl; //crashes here
}

From the code above, calling getString() function actually gets the value from the database. 从上面的代码中,调用getString()函数实际上是从数据库中获取值。 But then it crashes the program. 但随后它使程序崩溃。 It displays the value then crashes the program. 显示该值,然后使程序崩溃

I discovered the problem but couldn't fix it. 发现了这个问题 ,但不能 修复它。 I can't tell if this is a bug or something else . 我不知道这是错误还是其他原因

The problem only happens when the length of the value in the EmailColumn column is more or equals to 16 . 问题仅当值在EmailColumn 长度 大于等于 16发生。 No error if the length of the value is less or equals to 15 . 如果值的长度 小于等于 15 ,则没有错误。

Any solution or workarounds for this? 任何解决方案或解决方法吗?

I solved it. 我解决了 The solution is to build your own C++ Connector and use the dll files it compiles. 解决方案是构建自己的C ++连接器并使用它编译的dll文件。 The dll distributed by Oracle was made with a different version of Visual Studio compiler that I am currently using. Oracle分发的dll是使用我当前使用的其他版本的Visual Studio编译器制作的。 The first answer here will show you how to build it yourself. 这里的第一个答案将向您展示如何自己构建它。 MySQL Connector C++ 64bit build from source in Visual Studio 2012 ? 从Visual Studio 2012中的源代码构建MySQL Connector C ++ 64位

I had almost the same problem (and realized too late that Oracle is not supporting the library for Windows anymore). 我遇到了几乎相同的问题(并且意识到Oracle不再支持Windows库已经为时已晚)。 The following workaround worked for me: 以下变通办法对我有效:

ResultSet *search;
....
....
search= prepareStatement->executeQuery();

while( search->next() )
{
  string const * theString = 
    new string( search->getString( "EmailColumn") );

  cout << *theString << endl;

  operator delete( theString );
  theString = nullptr;
}

My guess is that by this construction VisualStudio 2015 is compiling code that is not calling the destructor std::string::~string() (which caused the crash for my application) for a string that is created by the library via ResultsSet::getString(). 我的猜测是,通过这种构造,VisualStudio 2015正在编译未调用析构函数std :: string ::〜string()(这导致我的应用程序崩溃)的代码,该字符串是由库通过ResultsSet ::创建的。的getString()。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM