I'm trying to write a simple sqlite query in c++ using visual studio 2010. My problem is that i can't use a c++ variable inside that query. I was not able to find the right syntax.

sqlite3_prepare_v2(handler, "SELECT * FROM grammateas WHERE username==X;", -1, &statement, 0);

where X i would like to use a variable.
In php and mysql is very simple, but here things are more complicated!
Ī¤hanks in advance.

Recommended Answers

All 2 Replies

You have to set the string before calling salite3_prepare().

std::string select;
std::string username = "AncientDragon";
select = "SELECT * FROM grammateas WHERE username = '" + username.c_str() + "'";
sqlite3_prepare_v2(handler,select.c_str(), -1, &statement, 0);

Really thank you! Works great!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.