我最近为我的项目安装了SOCI库,因为它需要使用SQLite数据库。我试图获取行集,但发现了一个奇怪的错误:
"c:\mingw\include\soci\exchange-traits.h:35:5: error: incomplete type 'soci::details::exchange_traits<soci::row>' used in nested name specifier".我不知道我的密码有什么问题..。执行此错误的行是:
soci::rowset<> results = (sql.prepare << "SELECT * from games where user_name='" << user.getName() << "'");顺便说一下,我使用了最新版本的SOCI。守则的更广泛部分:
soci::session& sql = conn.getSession();
soci::rowset<> results = (sql.prepare << "SELECT * from games where user_name='" << user.getName() << "'");
for(soci::rowset<>::const_iterator it = results.begin(); it != results.end(); ++it)...发布于 2015-08-11 08:32:15
您必须指定soci::rowset的类型,因为它是一个模板类型。因此,例如,如果您select一个整数列,您将使用一个soci::rowset<int>作为results的类型。您的示例是一个特例,因为您还不知道类型,但是对于这个套接字已经定义了soci::row类型,所以可以使用soci::rowset<soci::row> results
此外,您也不应该通过连接用户输入字符串来构建查询,所以使用sql.prepare << "SELECT * from games where user_name='" << user.getName() << "'"代替sql.prepare << "SELECT * from games where user_name=:name", soci::use(name,user.getName());。
否则,您就容易受到所谓的SQL注入攻击的攻击。
https://stackoverflow.com/questions/28416057
复制相似问题