I'm trying to insert into a table with this field TITLE varchar(200) NOT NULL
the next sentence:
INSERT OR IGNORE INTO EXAMPLETABLE VALUES ("1-Preludi \"Obrint Pas 2011\"", ...
The problem is that SQLite missunderstand the \" escape caracter , and i don't know how to put it to resolve the problem (Maybe a character code?) in my Android program.
To insert values into a database you should always use SQLiteStatement (HowTo) as they escape your values and prevent your app from being targeted with SQL-Injections.
Also, if you're inserting multiple values (say in a loop), executing a precompiled statement with different bound values is much faster than a normal insert-statement.
Just working with sqlite and direct sql insert commands from the command line, I find that double quoting escapes itself. With your example
INSERT OR IGNORE INTO EXAMPLETABLE VALUES ("1-Preludi ""Obrint Pas 2011""", ...
Try something similar:
ContentValues values = new ContentValues();
values.put("YOURCOLUMNNAME", "1-Preludi \"Obrint Pas 2011\"");
// ... other stuff you want to insert ...
SQLiteDatabase db = ... ; // Usually obtained using a SQLiteOpenHelper
long id = db.insertWithOnConflict("EXAMPLETABLE", BaseColumns._ID, values, SQLiteDatabase.CONFLICT_IGNORE);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With