mysql结果集始终为null

时间:2014-07-26 23:42:07

标签: c++ mysql visual-studio-2013

来自未解决的问题的跟进:mysql resultset is empty?

结果集始终为null且连接处于活动状态。 VS2013调试器说mysqlcppconn.dll没有调试符号。

在mysql控制台上测试了查询并且工作正常,它返回1

  CDatabase::CDatabase(CSettings* settings)
    {
        settings = settings;
        try {
            Connection* con = get_driver_instance()->connect("", "", "");
            con->setSchema("hyperbot");
            cout << "Connected." << endl << endl;
            cout << "Verifying hyper key with database...." << endl;

        if (!verify(con, settings->get_channel(), settings->get_hyper_key()))
        {
            cout << "Verification failed." << endl;
            CFunctions::ExitWithTimeout(5000);
        }
        delete con;
    }
    catch (sql::SQLException &e) {
        cout << "# ERR: SQLException in " << __FILE__;
        cout << "(" << __FUNCTION__ << ") on line »" << __LINE__ << endl;
        cout << "# ERR: " << e.what();
        cout << " (MySQL error code: " << e.getErrorCode();
        cout << ", SQLState: " << e.getSQLState() << " )" << endl;
        CFunctions::ExitWithTimeout(5000);
    }
}

bool CDatabase::verify(Connection* con, string channel, string hyper_key)
{
    if (!con) return false;

    sql::Statement *stmt;
    sql::ResultSet *res;
    stmt = con->createStatement();
    stmt->executeQuery("SELECT COUNT(*) FROM dark_souls2_widgets");
    res = stmt->getResultSet();
    if (res == NULL)
    {
        return false;
    }
    while (res->next()) {
        cout << res->getInt(1);
    }
    delete stmt;
    delete res;
    /*sql::ResultSet *res;
    sql::PreparedStatement  *prep_stmt;

    prep_stmt = con->prepareStatement("SELECT COUNT(*) FROM dark_souls2_widgets WHERE channel=? AND hyper_key=?");
    prep_stmt->setString(1, channel);
    prep_stmt->setString(2, hyper_key);
    prep_stmt->execute();
    res = prep_stmt->getResultSet();
    delete res;
    delete prep_stmt;
    */
    return false;
}

CDatabase::~CDatabase()
{
}

我在编译时也会收到这些奇怪的警告:

1>c:\program files (x86)\mysql\mysql connector c++ 1.1.3\include\cppconn\sqlstring.h(38): warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'sql::SQLString'
1>c:\program files (x86)\mysql\mysql connector c++ 1.1.3\include\mysql_driver.h(52): warning C4251: 'sql::mysql::MySQL_Driver::proxy' : class 'boost::scoped_ptr<sql::mysql::NativeAPI::NativeDriverWrapper>' needs to have dll-interface to be used by clients of class 'sql::mysql::MySQL_Driver'
1>c:\program files (x86)\mysql\mysql connector c++ 1.1.3\include\mysql_connection.h(165): warning C4251: 'sql::mysql::MySQL_Connection::proxy' : class 'boost::shared_ptr<sql::mysql::NativeAPI::NativeConnectionWrapper>' needs to have dll-interface to be used by clients of class 'sql::mysql::MySQL_Connection'
1>c:\program files (x86)\mysql\mysql connector c++ 1.1.3\include\mysql_connection.h(169): warning C4251: 'sql::mysql::MySQL_Connection::service' : class 'boost::scoped_ptr<sql::mysql::MySQL_Statement>' needs to have dll-interface to be used by clients of class 'sql::mysql::MySQL_Connection'
1>c:\program files (x86)\mysql\mysql connector c++ 1.1.3\include\cppconn\exception.h(61): warning C4251: 'sql::SQLException::sql_state' : class 'std::basic_string<char,std::char_traits<char>,std::allocator<char>>' needs to have dll-interface to be used by clients of class 'sql::SQLException'

1 个答案:

答案 0 :(得分:0)

可能与this

有关

这基本上意味着你可能需要把

#define CPPCONN_LIB_BUILD 1
你的代码中的

。但不确定。

相关问题