Hey what i want to do is update a table if the field exsits or insert the new value as given by the user.
For this what i do is select everything present in the table and check if the name entered by the user exists den update it or else insert it.
However the problem is when there is no data in the table the query fails and no data is inserted in the table.
NSString *query = @"select * from PPM";
sqlite_stmt *statement;
if(sqlite_prepare_v2(database,[query UTF8string],-1,&statement,NULL) == SQLITE_OK)
{
while (sqlite3_step(statement) == SQLITE_ROW)
//select data from table
//if value entered is same as entered by user update the table
//else insert in the table
}
How about
INSERT OR REPLACE?You can use it with the
UNIQUEconstraints in your database structure to replace a value if it already exists, and insert it if it not there already.