Suppose I had a method like this...
long getNumItemsFromDb() {
SQLiteDatabase db = dbhelper.getReadableDatabase();
try {
String query = "SELECT " + COL_NAME +
" FROM " + TABLE_NAME +
" WHERE " + COL_NAME + " = ?";
String[] args = new String[] {"whatever"};
return DatabaseUtils.longForQuery(db, query, args);
} finally {
db.close();
}
}
...but it's possible that, for example, String COL_NAME = "select";
and String TABLE_NAME = "from";
- which is going to break the query. So, I'd obviously need to surround those values in my query
String with either backticks, single quotes or double quotes - but which of these is the best practice for Android / SQLite?
NB - I have simplified my query String above to make this question simpler and more to the point. So, in reality, I do need to create the SQL manually like this rather than using one of the helper methods in Android.
NB2 - I have seen similar questions here and here but the questions/answers do not address SQLite and Android.