如果查询为空,则代码永远不会执行。我尝试了多种变体。这是简单的代码。
mysqlpp::Query query = conn.query();
query << "SELECT * FROM users WHERE username= "
<< mysqlpp::quote_only << username
<< "AND password= "
<< mysqlpp::quote_only << password;
mysqlpp::StoreQueryResult res = query.store();
mysqlpp::StoreQueryResult::const_iterator it;
for (it = res.begin(); it != res.end(); ++it)
{
mysqlpp::Row row = *it;
if (!row.empty())
{
// user name and password match, log them in
std::cout << "You are logged" << std::endl;
// rest of code goes here
}
else if (row.empty()) // even just 'else' doesnt get executed
{
// no username or password that matches with user input
std::cout << "Wrong username or password" << std::endl;
// rest of code goes here
// this never get executed, and i have no idea why
}
}
如何检查行是否为空?我几乎尝试了他在参考手册中找到的任何东西,但仍然没有。