I am developing database in Sqlite. I created the table the schema are
Sms_Address
,
Sms_Body
,
Status_Msg
. The initial status of message is 0. I am updating the status to 1 by using
setStatus()
function in the database. But the status of all rows are updated. I want to update only one field named as
Status_Msg
checking by checkbox.
The
setStatus()
function is given below:
public String setStatus(){
SQLiteDatabase sqldb = this.getWritableDatabase();
ContentValues values = new ContentValues();
if (Status_Msg.equals(Status_Msg)) {
values.put(Status_Msg, 1);
sqldb.update(DB_Table1, values, "status = 0", null);
}
System.out.println("" + Status_Msg);
sqldb.close();
return Status_Msg;
}
I am displaying data in the database by using
showStatusChangedData()
function. The control moves properly in this function. This function does not show messages in listview Please check these two functions.
The
showStatusChangedData()
function is given below:
public List<Message> showStatusChangedData(){
SQLiteDatabase sqldb = getWritableDatabase();
List<Message> list = new ArrayList<>();
String select_query = "SELECT * FROM " + DB_Table1 + " where status = 1";
Cursor cursor = sqldb.rawQuery(select_query,null);
if (cursor.moveToFirst()) {
do {
Message msg = new Message();
msg.setmAddress(cursor.getString(0));
msg.setmBody(cursor.getString(1));
msg.setmStatus(cursor.getString(2));
list.add(msg);
} while (cursor.moveToNext());
}
return list;
}
What I have tried:
I tried the following query
sqldb.update(DB_Table1, values,Sms_Address +"="+ Status_Msg,null);
But this not works.