imin imin - 1 month ago 21
Android Question

android sqlite query with multiple where

Here's my current sqlite code:

Cursor c = sqlDatabase.rawQuery("select docid as _id, recipeID from " + TABLE_RECIPE_NAME +
" where " + KEY_ownerID + " = ? ", new String[] { ownerID});


It works fine, but when I tried adding multiple where to something like this:

Cursor c = sqlDatabase.rawQuery("select docid as _id, recipeID from " + TABLE_RECIPE_NAME +
" where " + KEY_ownerID + " = ?, " + KEY_partnerID + " = ?, " + KEY_advertiserID + " = ?, " + KEY_chefID + " = ?", new String[] { ownerID, partnerID, advertiserID, chefID });


It returns an error. So how do I deal with multiple ?

Answer

change query to:

Cursor c = sqlDatabase.rawQuery("select docid as _id, recipeID from " + TABLE_RECIPE_NAME + 
                " where " + KEY_ownerID + " = ? AND  " + KEY_partnerID + " = ? AND  " + KEY_advertiserID + " = ? AND " + KEY_chefID + " = ?", new String[] { ownerID, partnerID, advertiserID, chefID });
Comments