Special Characters Json Ios Sqlite
I have one question. I'm getting information from JSON and he returns me invalid character. JSON give me this: '27/'' when I need this: 27'. I understand this is a encode for spe
Solution 1:
The issue is that you're building your SQL withstringWithFormat. That is a practice that is susceptible to this sort of problem. Instead, use ? placeholders in your SQL and then use sqlite3_bind_text to bind values to the ? placeholders. See the sqlite3_bind_text() help for more information.
For example, you might:
constchar *insert_stmt = "INSERT INTO FORMATOS (ID, NOMBRE) VALUES (?, ?)";
if (sqlite3_prepare_v2(dieneDB, insert_stmt, -1, &statement, NULL) != SQLITE_OK) { // prepare SQLNSLog(@"prepare error: %s", sqlite3_errmsg(dieneDB));
} else {
if (sqlite3_bind_text(statement, 1, idStr, -1, NULL) != SQLITE_OK) { // bind 1NSLog(@"bind idStr error: %s", sqlite3_errmsg(dieneDB));
} elseif (sqlite3_bind_text(statement, 2, nameStr, -1, NULL) != SQLITE_OK) { // bind 2NSLog(@"bind nameStr error: %s", sqlite3_errmsg(dieneDB));
} elseif (sqlite3_step(statement) != SQLITE_DONE) { // perform SQLNSLog(@"step error: %s", sqlite3_errmsg(dieneDB));
} else {
NSLog(@"Guardado Formatos correctamente");
}
sqlite3_finalize(statement);
}
I just typed this in, so please forgive any typos, but hopefully it illustrates the idea.
Note, I also (a) check all of these return codes; (b) log the error if any; and (c) finalize the statement when done.
Post a Comment for "Special Characters Json Ios Sqlite"