简体   繁体   中英

SOCI rowset<row> weird error

I recently installed SOCI library for my project because it requires working with SQLite database. 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. 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. So for example if you select a integer column, you would use a soci::rowset<int> as type for 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

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()); instead.

Otherwise you're vulnerable for so called SQL-Injection Attacks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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