private long insertSearchesInTransaction(SQLiteDatabase db,ContentValues values){
  String search=values.getAsString(Searches.SEARCH);
  if (TextUtils.isEmpty(search)) {
    throw new IllegalArgumentException("Must include the SEARCH field");
  }
  Cursor cursor=null;
  try {
    cursor=db.query(TABLE_SEARCHES,new String[]{Searches._ID},Searches.SEARCH + "=?",new String[]{search},null,null,null);
    if (cursor.moveToNext()) {
      long id=cursor.getLong(0);
      db.update(TABLE_SEARCHES,values,Searches._ID + "=?",new String[]{Long.toString(id)});
      return id;
    }
 else {
      return db.insertOrThrow(TABLE_SEARCHES,Searches.SEARCH,values);
    }
  }
  finally {
    if (cursor != null)     cursor.close();
  }
}

private long insertSearchesInTransaction ( SQLiteDatabase db , ContentValues values ) { String search = values . getAsString ( Searches . SEARCH ) ; if ( TextUtils . isEmpty ( search ) ) { throw new IllegalArgumentException ( "Must include the SEARCH field" ) ; } Cursor cursor = null ; try { cursor = db . query ( TABLE_SEARCHES , new String [ ] { Searches . _ID } , Searches . SEARCH + "=?" , new String [ ] { search } , null , null , null ) ; if ( cursor . moveToNext ( ) ) { long id = cursor . getLong ( 0 ) ; db . update ( TABLE_SEARCHES , values , Searches . _ID + "=?" , new String [ ] { Long . toString ( id ) } ) ; return id ; } else { return db . insertOrThrow ( TABLE_SEARCHES , Searches . SEARCH , values ) ; } } finally { if ( cursor != null ) cursor . close ( ) ; } }
searches are unique , so perform an upsert manually since sqlite doesn ' t support them .
