3

mysqlconnexionを使用してデータベースからstd::stringを取得しようとしています

簡単なコードは次のとおりです。

sql::Statement *stmt = con->createStatement();
sql::ResultSet  *res = stmt->executeQuery("SELECT * FROM test.new_table");
while (res->next()) {  
    std::string somestring = res->getString("idnew_table");
} //crashes here

delete res;
delete stmt;

したがって、executeQueryは問題なく、ループに入ります。中断すると、期待される結果はいくつかの文字列になります。somestring宣言の後、ループの最後まで進み、次の反復の前にクラッシュします。

コールスタックは次のとおりです。

>   msvcp100d.dll!std::_Lockit::_Lockit(int kind)  Line 64 + 0x14 bytes C++
    msvcp100d.dll!std::_Container_base12::_Orphan_all()  Line 200   C++
    CM.dll!std::_String_val<char,std::allocator<char> >::~_String_val<char,std::allocator<char> >()  Line 478 + 0xb bytes   C++
    CM.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >()  Line 755 + 0xf bytes   C++
    CM.dll!DAL::GetInfo()  Line 45 + 0xc bytes  C++

出力:

First-chance exception at 0x1038ad4a (msvcp100d.dll) in CMLauncher.exe: 0xC0000005: Access violation reading location 0xccccccd0.
Unhandled exception at 0x76f615de in CMLauncher.exe: 0xC0000005: Access violation reading location 0xccccccd0.
First-chance exception at 0x76f5016e in CMLauncher.exe: 0x00000000: The operation completed successfully.
Unhandled exception at 0x76f615de in CMLauncher.exe: 0x00000000: The operation completed successfully.

したがって、C++ランタイムライブラリのどこかに初期化されていないメモリがあるようです...std :: stringデストラクタでクラッシュしているように見えます。これは、文字列のスコープが完了するとクラッシュするため、意味があります...

私の推測では、libmysqlは古いバージョンのC ++ランタイム(たとえばmsvcp90d.dll)を使用しており、新しいバージョンと衝突しています...それも意味がありますか?

私はWindows7を使用しており、mySQL Server 5.5、VS2010Proを使用しています。すべて32ビットで。どうも!必要なmroe情報を投稿させていただきます。

編集:他の誰かがDumbCodersコメントを読む前に: MySQLコネクタ の例ドキュメントでは、ステートメントとresultSetの両方を削除する必要があると指定されています。

4

1 に答える 1

5

この問題は、ここでの問題と同じように思われます

于 2012-06-15T17:40:09.580 に答える