There is an error which i repeatedly encounter while retrieving the following retrieval code:
public VTB getCommands(String variation) {
VTB vtb=new VTB();
SQLiteDatabase db = this.getReadableDatabase();
try
{
Cursor cursor;
cursor=db.query(TABLE_NAME, new String[]{ COMMANDS,VARIATIONS},VARIATIONS+"="+variation,null, null, null, null);
if(cursor!=null)
cursor.moveToFirst();
vtb = new VTB(cursor.getString(0),cursor.getString(1));
}
catch(SQLException e)
{
Log.e("DB ERROR", e.toString());
e.printStackTrace();
}
return vtb;
}
The error encountered is:
04-16 22:52:43.921: I/Database(382): sqlite returned: error code = 1, msg = near "First": syntax error
04-16 22:52:43.921: E/DB ERROR(382): android.database.sqlite.SQLiteException: near "First": syntax error: , while compiling: SELECT command, variations FROM VTB WHERE variations=Call First Name{F}, last name{L}
Try using parameterized queries, such as:
cursor=db.query(TABLE_NAME, new String[]{ COMMANDS,VARIATIONS},VARIATIONS+"= ?", new String[]{variation},null, null, null, null);