Android SQL - Check if whole row already exists in database

前端 未结 3 1542
时光取名叫无心
时光取名叫无心 2021-01-18 19:42

I\'m trying to create a simple favorites application, where you can keep your favorites pages (from the web for example).

Let\'s say I have the following data in my

3条回答
  •  清酒与你
    2021-01-18 20:24

    You can check using cursor:

    public boolean checkEvent(String title, String URL, String tag) 
    {
        SQLiteDatabase db = this.getReadableDatabase();
    
        Cursor cursor = db.query(TABLES, 
                new String[] { KEY_TITLE,KEY_URL,KEY_TAG }, 
                KEY_TITLE + " = ? and "+ KEY_URL + " = ? and " + KEY_TAG + " = ?" , 
                new String[] {title,url,tag}, 
                null, null, null, null);
    
        if(cursor.moveToFirst())
    
         return true; //row exists
        else 
         return false;
    
    }
    

    Edit: Code now copy & paste ready

提交回复
热议问题