I have the following code which I was using to update a single row in my database:
public int updateSentFieldForIncomingMessage(IncomingMessage incomingMessage)
{
SQLiteDatabase db;
int numberOfRowsAffected;
try
{
db = super.getWritableDatabase();
}
catch (SQLiteException e)
{
File dbFile = context.getDatabasePath(DATABASE_NAME);
db = SQLiteDatabase.openDatabase(dbFile.getAbsolutePath(), null, SQLiteDatabase.NO_LOCALIZED_COLLATORS);
}
try
{
ContentValues values = new ContentValues();
values.put(KEY_MESSAGE_SENT, true);
numberOfRowsAffected = db.update(TABLE_INCOMING_MESSAGES, values, KEY_ID + " = ?", new String[]{String.valueOf(incomingMessage.getId())});
}
finally
{
db.close();
}
return numberOfRowsAffected;
}
This works fine but now I'd like to refactor the method so that instead of a single IncomingMessage parameter, it accepts a list of IncomingMessage. But when I get to this statement:
db.update(TABLE_INCOMING_MESSAGES, values, KEY_ID + " = ?", new String[]{String.valueOf(incomingMessage.getId())});
I'm not sure how to modify it so that I can specify multiple rows (via KEY_ID) in my WHERE clause. What I'd like to do is say something like KEY_ID IN ( <multiple row IDs here> ). Is that possible?
Aucun commentaire:
Enregistrer un commentaire