How To Handle Word With Apostrophe?
I'm filling an arraylist with some cities, but one of them ('Reggio nell'Emilia') have an apostrophe in its name and when i select it in the app it crashes. Here is the code: SQLit
Solution 1:
Using parameters eliminates such formatting problems:
result = db_read.rawQuery("select ... where region = ? ...",
newString[] { region.get(i) });
Solution 2:
You should make use of SqliteQueryBuilder
to make a safe query:
SQLiteQueryBuilderqueryBuilder=newSQLiteQueryBuilder();
// Set the table
queryBuilder.setTables('Table_Name');
SQLiteDatabasedb= database.getWritableDatabase();
Cursorcursor= queryBuilder.query(db, projection, selection,
selectionArgs, null, null, sortOrder);
Good luck.
Edited:
Also there is a util method in 'DatabaseUtils` class in andorid the help you to scape unwanted characters:
value = DatabaseUtils.sqlEscapeString(value);
Solution 3:
I finally solved the problem using the hint (that one described in my question) in another part of the code (it was used as extra in another activity).
Post a Comment for "How To Handle Word With Apostrophe?"