jeudi 28 janvier 2016

Android Sqlite Update increase value issue

The problem is that the following code works just fine for the first time I update a column value, but it refuses to increase it the next times.

public void incrementValue(Context context, String number) {

     SwipeDatabaseHelper mOpenHelper = new SwipeDatabaseHelper(
          context.getApplicationContext());

     String sql = "UPDATE " + DatabaseContract.PATH_CONTACTS + " SET "
          + DatabaseContract.DatabaseEntry.COLUMN_CONTACT_UNREAD + " = " +
          DatabaseContract.DatabaseEntry.COLUMN_CONTACT_UNREAD + " + 1 WHERE "
          + DatabaseContract.DatabaseEntry.COLUMN_CONTACT_NUM + " = ?";

     mOpenHelper.getWritableDatabase().execSQL(sql, new String[]{number});
}

It is very interesting that when I update it with a hard coded value (for example 0) it goes perfectly. And when I call the function again it only increments it by one and the value never goes above 1 even if you call it a thousand times

Aucun commentaire:

Enregistrer un commentaire