MySQL的结果集始终为空。

4

未解决问题的跟进:mysql结果集为空?

结果集总是为空,并且连接仍然存在。 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
有人吗?................. - NullBy7e
2
我遇到了完全相同的问题;它是由那些警告引起的。显然,问题在于MySQL C++源代码.lib是使用不同的编译器构建的,因此我们必须使用VC2013重新编译它。我宁愿不重新编译,所以我在这个问题上开始了一个赏金,希望有人告诉我另一种绕过警告的方法 ;)。 - AStopher
1
@zyboxinternational 我现在正在使用VS2008,看一下这个链接:http://www.dreamincode.net/forums/topic/351316-mysql-resultset-is-always-null/page__p__2037291__fromsearch__1 然而,如果能在VS2013上使用就更好了! - NullBy7e
你好:能否发布更多的代码,因为问题可能出现在代码的其他地方。例如,您是否尝试在任何地方导出mysql DLL功能(即定义mysqlcppconn_EXPORTS)?这通常用于创建DLL而不是在exe中使用。 - GMasucci
你的路径中有libmysql.dll吗?尝试把这个dll文件放在可执行文件所在的文件夹中。 - LHristov
显示剩余2条评论
1个回答

0

这可能与this有关

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

#define CPPCONN_LIB_BUILD 1

在你的代码中。不过我不确定。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接