gpt4 book ai didi

c++ - mysql 结果集始终为空

转载 作者:可可西里 更新时间:2023-11-01 07:44:40 24 4
gpt4 key购买 nike

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

结果集始终为空,连接处于事件状态。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'

最佳答案

可能与this有关

这基本上意味着你可能必须把

#define CPPCONN_LIB_BUILD 1

在您的代码中。不过不确定。

关于c++ - mysql 结果集始终为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24976510/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com