There are three ways to solve this problem:
- Make formatting yourself. Do not do this. (well, unless that line is part of your code, not the user). In this case, this approach is great.)
- Use
sqlite3_mprintf("%Q") for SQLite to do this. ( %q quotes the replacement; %q performs the replacement and inserts NULL for the null pointer.) - Use the bindings in your statement, which you fill out with
sqlite3_bind_text . This is the best way to do this because it does not require recompiling the statement for each row and does not open you up for SQL Injection .
Using binding will look like this:
sqlite3_prepare(db, "INSERT INTO Table(Column) VALUES(?);", -1, &stmt, NULL); sqlite3_bind_text(stmt, 1, [str cStringUsingEncoding:NSUTF8StringEncoding], -1, SQLITE_TRANSIENT); // stepping, etc
(Remember to check for errors.)
Steven fisher
source share