简体   繁体   中英

how to update sqlite3 database in iphone

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM