-2

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?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
ZubZero
  • 9
  • 5
  • 2
    For the log message, please see http://stackoverflow.com/questions/14678593/the-application-may-be-doing-too-much-work-on-its-main-thread – OneCricketeer Jun 04 '16 at 03:42
  • wrap your database calls in an AsyncTask. the message is warning you that something is taking too much time in the UI thread - you should try to keep it idle. if there's any chance something is going to take a moment or two, use a separate thread. – trooper Jun 04 '16 at 03:43

2 Answers2

1

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);
USKMobility
  • 5,721
  • 2
  • 27
  • 34
-1

do it this way:

String[] args = new String[]{yourVariableName}; //this is for the condition
database.execSQL("UPDATE " + TABLENAME + " SET colum1Name='" + variable1 + "', column2Name='"+variable2+"' WHERE id=?", args);//replace id for your condition
Toast.makeText(getBaseContext(), "database updated!", Toast.LENGTH_LONG).show();
Carlos Carrizales
  • 2,340
  • 3
  • 18
  • 24