MySql C++ connector getString() doesn't work correctly, while getInt works perfectly

后端 未结 4 2016
轻奢々
轻奢々 2021-01-20 04:18

I tried to connect C++ to MySql and I just can\'t get this to work properly. I used latest MySql and C++/Connector for Windows from Oracle site. I also use VS2010.

相关标签:
4条回答
  • 2021-01-20 04:40

    I trial run the demo source codes from MySQL Connector/C++ Developer Guide / Getting Started with Connector/C++: Usage Examples / Complete Example 1 in the environment "mysql-connector-c++-8.0.13-win32" and Visual C++ 2015.

    I also encountered the same problem.

    In debug mode, it should use

    std::string version = result->getString( COLUMN_NAME ).c_str();
    

    But in release mode, this is OK:

    sql::SQLString sString  = result->getString( COLUMN_NAME );
    

    I believe it is because my project must been compiled with the same runtime with the MySQL C++ Connector library.

    0 讨论(0)
  • 2021-01-20 04:42

    The code below worked for me:

    sql::ResultSet *res;
    res->getString("Column name").c_str();
    

    Just using res->getString("Column name") was crashing my application.

    0 讨论(0)
  • 2021-01-20 04:44

    I had a similar problem the program would give a memory exception. Here is what I did to fix it:

    std::string version = result->getString( COLUMN_NAME ).c_str();
    

    This didn't work:

    sql::SQLString sString  = result->getString( COLUMN_NAME ); <<<memory exception
    std::string version = sString; 
    
    0 讨论(0)
  • 2021-01-20 04:50

    Are you sure task-column doesn't have the binary collation set? If so, the connector may return different metadata for the same column.

    Update:

    Also, check that the Connector has been compiled with the same runtime as your project. If using VS, I bet the other one was compiled with /MT and the other with /MD. This way, they use different heaps and it won't work.

    0 讨论(0)
提交回复
热议问题