How to update sqlite3 database in iphone

I want to update sqlite database, but I cannot find a way to do this, here 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 $ variable name, how to do it?

+3
source share
2 answers

You are almost 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. He sqlite3_bind_textwho applies the variable to the SQL statement and the string sqlite3_stepthat actually runs it.

+11
source

FMDB - SQLite. ///reset. , , Core Data.

0

Source: https://habr.com/ru/post/1709007/


All Articles