jeudi 28 avril 2016

How delete specific cell in SQLite Table android

I wonder if it is possible to delete just a specific cell inside a SQLite database. For example, I have some rows and columns like this:

 _id |name |lastname |phone  | avatar
 - - - - - - - - - - - - - - - - - - 
 1   |John | Doe     |555111 | data
 2   |Mary | Doe     |555112 | data

I can delete a complete row with

db.delete(NAME_TABLE, KEY_ID+ " = ?",
                new String[] { String.valueOf(_id) });

But what if I want to delete just the avatar from the second entry? The only way I found was to put an empty byte[] array into that cell, but isn´t there a better way like this:

private void deleteAvatar(int id){

  ContentValues val = new ContentValues();
  val.put(AVATAR_COL,new byte[0]);
  db.update(NAME_TABLE, val, KEY_ID+"="+id, null);
}

using:

val.put(AVATAR_COL,null);

is not allowed, also I can´t find any method in the SQLite documentation about deleting a specific cell. I searched a lot on google and here in SO, but can´t find a thread about, maybe because of not clear headwords. So this might be a simple question and somebody might think, users with some experience should know it. But never needed it before and also I haven´t found anything on Android API.

Aucun commentaire:

Enregistrer un commentaire