[英]C++ MySQL-connector on Arch-Linux/arm
我已经使用C ++ / C,MySQL C ++连接器和ncurses / CDK编写了一个程序。 它可以很好地编译,并且可以在x86 / 64架构上很好地运行。 但是,在Raspberry Pi B +(ArchLinux)上运行时,它会崩溃。
我意识到这是一个很难回答的问题,但也许经验丰富的人可以提供帮助。
这是(希望)相关的代码:
//Open Connection to the Database
nrpeout::MYSQL_CON localhost("127.0.0.1", 3306, "root", "toor");
//localhost.write_attributes_to_console();
con = localhost.open_database_connection();
//Create a new object of type nrpeoutputquery
nrpeout::Nrpeoutputquery current_query("SELECT * FROM nrpeout", con);
//Execute query
res = current_query.execute_query();
//Close Database Connection
localhost.close_database_connection(con);
} catch (sql::SQLException &e) {
//Handle SQL-Exceptions
std::cout << "# ERR: SQLException in " << __FILE__;
std::cout << "(" << __FUNCTION__ << ") on line "
<< __LINE__ << std::endl;
std::cout << "# ERR: " << e.what();
std::cout << " (MySQL error code: " << e.getErrorCode();
std::cout << ", SQLState: " << e.getSQLState() << " )" << std::endl;
} catch(...) {
//Handle Standard Exceptions
std::cout << "Unknown Exception raised. Please contact your Administrator" << std::endl;
}
nrpeout::NrpeResultSet* currentResults = new nrpeout::NrpeResultSet(res);
使用Valgrind和GDB,我尝试将错误缩小到创建对象“ currentResults”的行。
这是保存查询结果的成员函数:
nrpeout::NrpeResultSet::NrpeResultSet(sql::ResultSet* res)
{
for (unsigned int i = 0; i < res->rowsCount(); ++i)
{
res->next();
std::string command = res->getString("command");
//Shorten the String
size_t posCommand = command.find("_");
std::string shortened_command = command.substr(posCommand+1);
int ret = res->getInt("ret");
std::string text = res->getString("text");
//Shorten the Text
size_t posText = text.find("|");
std::string shortened_text = text.substr(0, posText-1);
std::string last_updated = res->getString("last_updated");
this->results.push_back(Row(shortened_command, ret, shortened_text, last_updated));
}
好吧,您没有捕获到可能要处理的异常。 使用封闭的数据库连接,语句或结果集时,抛出InvalidInstanceException。
我的建议是使用gdb运行代码并捕获异常:
gdb ./some-program
$ catch throw
$ r
抛出每个异常后,此操作将中断。 (但还包括处理的异常,因此可能会有很多中断,具体取决于您到达重要部分的时间。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.