I want to be able to take a ContentValues object and use that in a sqlite statement.
ContentValues cv;
cv.put( "id", 1 );
cv.put( "name", "Bob" );
cv.put( "isCEO", true );
Normally, I would hardcode the request as such:
db.execSQL( "Insert or replace into Employee (id, name, isCEO) values (1, 'Bob', true)" );
What’s the best way to convert cv into the string “(id, name, isCEO) values (1, ‘Bob’, true)”? Also, is there a way to get back a success/fail status for the sqlite operation in this case?
Use the ‘replace’ method of SQLiteDatabase. e.g.
For this to work, the ‘id’ column has to be a PRIMARY key column in your table.
The response of the ‘replace’ method is a long value: