0

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)...
Oded
  • 72
  • 1
  • 8

1 Answers1

4

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

Superlokkus
  • 4,731
  • 1
  • 25
  • 57
  • 1
    Thanks mate, it was long ago so I managed to solve this but thanks anyway and it's good to keep it here so people can learn from it. and big thank for the sqli advice :) – Oded Aug 12 '15 at 09:28