I use sqlite data base to store values in offline mode.In these values it contains strings with double quotation marks.(eg: hai \"Man\")
You can replace all double quote occurrences in SummaryDescription calling this:
NSString *newSummaryDescription = [SummaryDescription stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
So you code will look like this:
NSString *newSummaryDescription = [SummaryDescription stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
NSString *insertSQL = [NSString stringWithFormat: @"UPDATE tablename SET SummaryDescription=\"%@\" WHERE SummaryDate1=\"%@\" AND ClientId=\"%@\"", newSummaryDescription, [_dic objectForKey:@"SummaryDate1"], [[NSUserDefaults standardUserDefaults] objectForKey:@"ClientID"]];
To store double quotation marks or any other special character, use a parameter to pass the string into the SQL statement (as suggested by CL in this answer):
NSString *str = @"some characters \" and \'";
const char *sql = "INSERT INTO MyTable(Name) VALUES(?)";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) == SQLITE_OK) {
sqlite3_bind_text(stmt, 1, [str UTF8String], -1, SQLITE_TRANSIENT);
if (sqlite3_step(stmt) != SQLITE_DONE) {
NSLog(@"SQL execution failed: %s", sqlite3_errmsg(db));
}
} else {
NSLog(@"SQL prepare failed: %s", sqlite3_errmsg(db));
}
sqlite3_finalize(stmt);
Hope this will help you. Happy Coding :)
You need to Escape(/) the quotation mark.
Like :
hai "Man" :
>> To >> : hai \""Man\""