简体   繁体   English

SOCI行集 <row> 怪异的错误

[英]SOCI rowset<row> weird error

I recently installed SOCI library for my project because it requires working with SQLite database. 我最近为我的项目安装了SOCI库,因为它需要使用SQLite数据库。 I tried to fetch rowset but I got weird error: 我试图获取行集,但出现了奇怪的错误:

"c:\mingw\include\soci\exchange-traits.h:35:5: error: incomplete type 'soci::details::exchange_traits<soci::row>' used in nested name specifier".

I have no idea what's wrong with my code... the line that does that error is: 我不知道我的代码有什么问题...发生此错误的行是:

soci::rowset<> results = (sql.prepare << "SELECT * from games where user_name='" << user.getName() << "'");

By the way, I use the most recent version of SOCI. 顺便说一下,我使用的是最新版本的SOCI。 the wider part of the code: 代码的更广泛的部分:

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)...

You have to specify the type of the soci::rowset , because it's a templated type. 您必须指定soci::rowset的类型,因为它是模板类型。 So for example if you select a integer column, you would use a soci::rowset<int> as type for results . 因此,例如,如果您select整数列,则可以将soci::rowset<int>用作results类型。 Your example is a special case, because you don't know the type yet, but for this soci has defined the soci::row type, so you could use soci::rowset<soci::row> results 您的示例是一个特例,因为您尚不知道类型,但是为此soci定义了soci::row类型,因此可以使用soci::rowset<soci::row> results

Also you should never build your query by concatenation of user input strings, so instead of sql.prepare << "SELECT * from games where user_name='" << user.getName() << "'" use sql.prepare << "SELECT * from games where user_name=:name", soci::use(name,user.getName()); 另外,您永远不要通过连接用户输入字符串来构建查询,因此,使用sql.prepare << "SELECT * from games where user_name='" << user.getName() << "'"代替sql.prepare << "SELECT * from games where user_name='" << user.getName() << "'" sql.prepare << "SELECT * from games where user_name=:name", soci::use(name,user.getName()); instead. 代替。

Otherwise you're vulnerable for so called SQL-Injection Attacks 否则,您很容易受到所谓的SQL注入攻击的攻击

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM