Reputation:
i want to update my sqlite database but i cannot find the way to do it,following is the code:
const char *sqlStatement = "UPDATE frame SET fileExist = '1' WHERE name='$variable'";
if(sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
NSLog(@"successupdate");
}
from the above code i want my table update where the name is equal to $variable name;how to achieve this?
Upvotes: 3
Views: 8655
Reputation: 4912
FMDB is a nice wrapper for SQLite statements. It takes care of most of the prepare/bind/step/reset drudgery. I highly recommend it for any project that needs a DB, but doesn't want to use Core Data.
Upvotes: 0
Reputation: 52565
You're nearly there.
const char *sqlStatement = "UPDATE frame SET fileExist = '1' WHERE name=?";
sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL);
sqlite3_bind_text(sqlStatement, 1, variable, -1, SQLITE_TRANSIENT);
int success = sqlite3_step(sqlStatement);
sqlite3_reset(sqlStatement);
Note that preparing the SQL statement only tells SQLite what the statement looks like. It's sqlite3_bind_text
that applies the variable to the SQL statement and the sqlite3_step
line that actually runs it.
Upvotes: 11