mercredi 8 juillet 2015

Android database update records

In a table of my database, I have 7 records. Now I want to update the records through a WHERE clause. First, count the records, according to a clause

int pos = 0;
String SQL = "SELECT COUNT(posizione) FROM operatori WHERE posizione>0;";
final Cursor cur = db2.rawQuery(SQL, null);
while (cur.moveToNext()) {
       pos = cur.getInt(0);
 }
      cur.close();

//then, with a for loop, update all the records based on a WHERE clause
for (int i = 1; i <= pos; i++) {
    ContentValues cv1 = new ContentValues();
    cv1.put(OperatoriTable.POSIZIONE, i);
    db2.update(OperatoriTable.TABLE_NAME, cv1, OperatoriTable.POSIZIONE + ">0", null);
    }
    db2.close();

but, for example, if posequals 5, should enter the numbers 1,2,3,4,5. Instead, it is always inserted 1. Where am I wrong?

Aucun commentaire:

Enregistrer un commentaire