Friday, April 1, 2011

Updating a Sqlite record with Android

I was having a problem updating a record using the database built into android. I had a working SQL statement, but it wasn't working using the raw sql command! I'm not sure why it wasn't working, but after reading about ContentValues I decided I wanted to use that instead. I thought it was best practice this way, but I ran into some unknown errors that the debugger was not providing much information for.

This is how I have it working for my setup:


public int updateLength(String route_length, int route_id){
ContentValues cv = new ContentValues();
cv.put("length", route_length);
return db.update(TABLE_NAME_ROUTE, cv, "id=" + route_id, null );
}


I believe there is a better way to attach the "id=" statement in the third argument of the update but I couldn't get any of these ways to work for me.