Search code examples
androidsqlitecontent-values

SQLite Android update a specific row


I'm having trouble trying to update a row in SQlite.

I want to update the row "name" with anyone with the name1 and rename it to bob. I also want to update row "age" with anyone who is 5.

ContentValues cv = new ContentValues();
cv.put("age", "bob"); 
cv.put("name", "2");
database.update("tblTest1", cv, "name", null);

cursor = database.rawQuery("select age,name from tblTest1", null);
displayAllInCursor(cursor);

When I run this the rest of the program works fine. In the logcat the following message is displayed:

I/Choreographer﹕ Skipped 39 frames! The application may be doing too much work on its main thread.

Also I'm unsure how to create a delete with ContentValues.

How can I do this correctly?


Solution

  • You just update where clause.

     String where = "name ='name1'OR age = 5" ;
        ContentValues cv = new ContentValues();
            cv.put("age", "bob"); 
            cv.put("name", "2");
            database.update("tblTest1", cv, where, null);
    
            cursor = database.rawQuery("select age,name from tblTest1", null);
            displayAllInCursor(cursor);