Code example for Cursor

Methods: closegetColumnIndexOrThrowgetLonggetStringmoveToFirst

0
 
    try { 
      cursor = database.query(TABLE_NAME, null, NUMBER + " = ? AND " + ZID + " = ?",
                              new String[] {encodedNumber, encodedZid}, null, null, null);
 
      if (cursor != null && cursor.moveToFirst()) {
        long          id     = cursor.getLong(cursor.getColumnIndexOrThrow(ID));
        ContentValues values = new ContentValues();
 
        values.put(RS2, cursor.getString(cursor.getColumnIndexOrThrow(RS1)));
        values.put(RS1, encodedRs1);
        values.put(EXPIRES, expiration);
        if (!continuity) values.put(VERIFIED, 0);
 
        database.update(TABLE_NAME, values, ID + " = ?", new String[] {id+""});
      } else { 
        ContentValues values = new ContentValues();
        values.put(RS1, encodedRs1);
        values.put(RS2, (String)null);
        values.put(ZID, encodedZid);
        values.put(NUMBER, encodedNumber);
        values.put(VERIFIED, false);
        values.put(EXPIRES, expiration);
 
        database.insert(TABLE_NAME, null, values);
      } 
    } finally { 
      if (cursor != null)
        cursor.close();
    } 
  } 
 
 
  public RetainedSecrets getRetainedSecrets(String number, byte[] zid) {