Sign in to follow this  
chrpeter

SQLite Error Please Help!

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this