Jump to content
  • Advertisement
Sign in to follow this  
chrpeter

SQLite Error Please Help!

This topic is 3350 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been trying to save this string to the SQLite database for a while now and no luck online! I am using Visual Studio 2008 and using a SQLite C++ class. Here is my code: int main() { std::string s; SQLITE3 sql("apptz.sql"); string hey = "heyy"; //This works when I manually input text sql.exe("INSERT INTO appts (title) VALUES ('First Appt.')"); //This does not work when I use the variable name instead of manually sql.exe("INSERT INTO appts (title) VALUES (hey)"); return 0; } Chris Peterson If you can help it will be greatly appreciated. Thank you! [Edited by - chrpeter on July 21, 2009 3:40:32 AM]

Share this post


Link to post
Share on other sites
Advertisement
To further this...How would I store a string into the server. For example:

int main()
{
std::string s;
SQLITE3 sql("apptz.sql");
string hey = "heyy";

//This works when I manually input text
sql.exe("INSERT INTO appts (title) VALUES ('First Appt.')");

//This does not work when I use the variable name instead of manually
sql.exe("INSERT INTO appts (title) VALUES (hey)");

return 0;
}

Share this post


Link to post
Share on other sites
You'll need to use the parameter binding functions in order to bind parameters to prepared statements.

The prepared statement interface can seem daunting at first, but under typical usage of sqlite1, you can often get away with building the SQL statement dynamically:
std::string stmt = "INSERT INTO appts (title) VALUES ('";
stmt += hey;
stmt += "')";
sql.exe(stmt);



1 Note, this is only true for sqlite where variables and parameters are not typically coming via a remote interface. For network-facing applications, I would recommend you always use the "bind" interfaces.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!