jeudi 9 juillet 2015

SQLite: db.update with composite primary key?

I'm quite new to Android programming, and I'm currently trying to figure out how to build an SQLite database with two tables. In one of the tables I'm using a composite primary key on two columns. My question is how to write the update function. I want to say "update contact where id1 = x and id2 = y", how do I do that?

The example I'm following looks like this:

public boolean updateContact (Integer id, String name, String phone, String email, String street,String place)
    {
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues contentValues = new ContentValues();
        contentValues.put("name", name);
        contentValues.put("phone", phone);
        contentValues.put("email", email);
        contentValues.put("street", street);
        contentValues.put("place", place);
        db.update("contacts", contentValues, "id = ? ", new String[] { Integer.toString(id) } );
        return true;
    } 

Aucun commentaire:

Enregistrer un commentaire